feat:添加gpt检测基础功能
This commit is contained in:
parent
92c3a5546b
commit
7f3591959b
25
detection/GPTdetection.py
Normal file
25
detection/GPTdetection.py
Normal file
@ -0,0 +1,25 @@
|
||||
import os
|
||||
|
||||
import openai
|
||||
|
||||
|
||||
def detect_gpt(text):
|
||||
client = openai.OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
|
||||
response = client.chat.completions.create(
|
||||
messages=[
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are a Python code reviewer.Read the code below and identify any potential security vulnerabilities. Classify them by risk level (high, medium, low, none). Only report the line number and the risk level.",
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": text,
|
||||
}
|
||||
],
|
||||
model="gpt-3.5-turbo",
|
||||
)
|
||||
return response.choices[0].message.content
|
||||
#TODO: 解析GPT输出成标准格式
|
||||
#TODO: 强化提示词,更改模型输出文本格式
|
||||
|
||||
print(detect_gpt("import os\nos.system('rm -rf /')"))
|
@ -1,2 +1,3 @@
|
||||
reportlab
|
||||
packaging
|
||||
packaging
|
||||
openai
|
Loading…
x
Reference in New Issue
Block a user