You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
prompt= (f'Use third person mood to summarize the following article delimited by triple backticks in 2 concise English sentences. Ensure the summary does not exceed 100 characters.\n'
84
-
f'```{content.strip(".")}.```')
85
-
resp=openai.Completion.create(
86
-
prompt=prompt,
87
-
**kwargs
88
-
)
89
-
answer=resp['choices'][0]['text'].strip()
90
-
else:
91
-
resp=openai.ChatCompletion.create(
92
-
messages=[
93
-
{
94
-
"role": "system",
95
-
"content": sys_prompt
96
-
},
97
-
{'role': 'user', 'content': content},
98
-
],
99
-
**kwargs)
100
-
message=resp["choices"][0]["message"]
101
-
ifmessage.get('function_call'):
102
-
json_str=message['function_call']['arguments']
103
-
ifresp["choices"][0]['finish_reason'] =='length':
104
-
json_str+='"}'# best effort to save truncated answers
105
-
try:
106
-
answer=json.loads(json_str)
107
-
exceptJSONDecodeErrorase:
108
-
logger.warning(f'Failed to decode answer from openai, will fallback to plain text, error: {e}')
109
-
return''# Let fallback code kicks in
110
-
else:
111
-
answer=message['content'].strip()
82
+
resp=openai.ChatCompletion.create(
83
+
messages=[
84
+
{
85
+
"role": "system",
86
+
"content": sys_prompt
87
+
},
88
+
{'role': 'user', 'content': content},
89
+
],
90
+
**kwargs)
112
91
logger.info(f'content: {content}')
113
92
logger.info(f'took {time.time() -start_time}s to generate: '
0 commit comments