Spaces:
Runtime error
Runtime error
update file
Browse files- gpt_analyze.py +5 -5
gpt_analyze.py
CHANGED
|
@@ -44,10 +44,10 @@ def analyze_by_3p5(text, api_key=None):
|
|
| 44 |
)
|
| 45 |
refine_prompt = PromptTemplate(input_variables=["existing_answer", "text"], template=refine_template)
|
| 46 |
# 使用 OpenAI API 密钥创建 OpenAI 对象
|
| 47 |
-
if api_key
|
| 48 |
-
openai_api_key = os.getenv('OPENAI_API_KEY')
|
| 49 |
-
else:
|
| 50 |
openai_api_key = api_key
|
|
|
|
|
|
|
| 51 |
llm = OpenAI(temperature=0, model_name="gpt-3.5-turbo", openai_api_key=openai_api_key)
|
| 52 |
|
| 53 |
# 加载总结和完善模型链,并向其提供刚才定义的两个模板字符串作为问题和细化问题的提示。
|
|
@@ -60,10 +60,10 @@ def analyze_by_3p5(text, api_key=None):
|
|
| 60 |
|
| 61 |
except AuthenticationError as e:
|
| 62 |
print("OpenAI API authentication error:", e.json_body)
|
| 63 |
-
return
|
| 64 |
except Exception as e:
|
| 65 |
logging.error("Summary error:", exc_info=True)
|
| 66 |
-
return
|
| 67 |
|
| 68 |
|
| 69 |
if __name__ == '__main__':
|
|
|
|
| 44 |
)
|
| 45 |
refine_prompt = PromptTemplate(input_variables=["existing_answer", "text"], template=refine_template)
|
| 46 |
# 使用 OpenAI API 密钥创建 OpenAI 对象
|
| 47 |
+
if api_key:
|
|
|
|
|
|
|
| 48 |
openai_api_key = api_key
|
| 49 |
+
else:
|
| 50 |
+
openai_api_key = os.getenv('OPENAI_API_KEY')
|
| 51 |
llm = OpenAI(temperature=0, model_name="gpt-3.5-turbo", openai_api_key=openai_api_key)
|
| 52 |
|
| 53 |
# 加载总结和完善模型链,并向其提供刚才定义的两个模板字符串作为问题和细化问题的提示。
|
|
|
|
| 60 |
|
| 61 |
except AuthenticationError as e:
|
| 62 |
print("OpenAI API authentication error:", e.json_body)
|
| 63 |
+
return "请检查apikey"
|
| 64 |
except Exception as e:
|
| 65 |
logging.error("Summary error:", exc_info=True)
|
| 66 |
+
return "生成总结出错"
|
| 67 |
|
| 68 |
|
| 69 |
if __name__ == '__main__':
|