fix: 添加容错代码
Some checks failed
Python application test / build (pull_request) Failing after 12m17s

This commit is contained in:
2024-04-29 11:52:46 +08:00
parent 7a420b9bf8
commit d771976b35
2 changed files with 18 additions and 2 deletions

View File

@@ -5,7 +5,10 @@ import openai
def detectGPT(content: str):
client = openai.OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
api_key = os.getenv("OPENAI_API_KEY")
if api_key is None:
raise ValueError("env OPENAI_API_KEY no set")
client = openai.OpenAI(api_key=api_key)
text = content
# client = openai.OpenAI(api_key="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") #测试用key
response = client.chat.completions.create(