Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -228,7 +228,8 @@ def chatbot(policy_name_dd,contract_text,progress=gr.Progress()):
|
|
228 |
out_file.write(trimmed_input)
|
229 |
"""
|
230 |
gpt_model = "gpt-4-1106-preview"
|
231 |
-
response = openai.
|
|
|
232 |
model=gpt_model,
|
233 |
temperature=0,
|
234 |
messages=[
|
@@ -243,17 +244,18 @@ def chatbot(policy_name_dd,contract_text,progress=gr.Progress()):
|
|
243 |
]
|
244 |
)
|
245 |
|
246 |
-
gpt_response = response.choices[0].message
|
|
|
247 |
|
248 |
tokens_used = response.usage
|
249 |
if gpt_model == "gpt-4":
|
250 |
-
question_cost = (tokens_used.total_tokens / 1000) * .03
|
251 |
-
prompt_tokens = tokens_used.prompt_tokens
|
252 |
-
completion_tokens = tokens_used.completion_tokens
|
253 |
|
254 |
else:
|
255 |
-
prompt_tokens = tokens_used.prompt_tokens
|
256 |
-
completion_tokens = tokens_used.completion_tokens
|
257 |
question_cost = ((prompt_tokens / 1000) * .01) + ((completion_tokens / 1000) * .03)
|
258 |
|
259 |
"""
|
|
|
228 |
out_file.write(trimmed_input)
|
229 |
"""
|
230 |
gpt_model = "gpt-4-1106-preview"
|
231 |
+
response = openai.ChatCompletion.create(
|
232 |
+
#response = openai.chat.completions.create(
|
233 |
model=gpt_model,
|
234 |
temperature=0,
|
235 |
messages=[
|
|
|
244 |
]
|
245 |
)
|
246 |
|
247 |
+
gpt_response = response.choices[0].message["content"]
|
248 |
+
#gpt_response = response.choices[0].message.content
|
249 |
|
250 |
tokens_used = response.usage
|
251 |
if gpt_model == "gpt-4":
|
252 |
+
question_cost = (tokens_used.get('total_tokens',0) / 1000) * .03
|
253 |
+
prompt_tokens = tokens_used.get('prompt_tokens',0)
|
254 |
+
completion_tokens = tokens_used.get('completion_tokens',0)
|
255 |
|
256 |
else:
|
257 |
+
prompt_tokens = tokens_used.get('prompt_tokens',0)
|
258 |
+
completion_tokens = tokens_used.get('completion_tokens',0)
|
259 |
question_cost = ((prompt_tokens / 1000) * .01) + ((completion_tokens / 1000) * .03)
|
260 |
|
261 |
"""
|