feat:添加gpt检测基础功能

This commit is contained in:
Tritium0041 2024-04-25 21:52:44 +08:00
parent 92c3a5546b
commit 7f3591959b
2 changed files with 27 additions and 1 deletions

25
detection/GPTdetection.py Normal file
View 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 /')"))

View File

@ -1,2 +1,3 @@
reportlab
packaging
packaging
openai