AceVen57 commited on
Commit
02c9322
·
verified ·
1 Parent(s): 7120111

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -41
app.py CHANGED
@@ -191,51 +191,49 @@ def predict(user_input,company):
191
  ]
192
 
193
  # Get response from the LLM
194
- try:
195
- url = "https://api.fireworks.ai/inference/v1/chat/completions"
196
- payload = {
197
- "model": "accounts/fireworks/models/llama-v3p3-70b-instruct",
198
- "temperature": 0.6,
199
- "top_p": 1,
200
- "top_k": 40,
201
- "presence_penalty": 0,
202
- "frequency_penalty": 0,
203
- "messages": [
204
- {
205
- "role": "user",
206
- "content": f"{prompt}"
207
- }
208
  ]
209
- }
210
- headers = {
211
- "Accept": "application/json",
212
- "Content-Type": "application/json",
213
- "Authorization": f"Bearer {api_key}"
214
- }
215
-
216
- response = requests.post(url, headers=headers, json=payload)
217
 
218
- prediction = response.json()["choices"][0]["message"]["content"]
219
 
220
- except Exception as e:
221
- prediction = {
222
- "error_type": type(e).__name__,
223
- "error_message": str(e),
224
- "traceback": traceback.format_exc()
225
- }
226
 
227
- # Log safely
228
- with scheduler.lock:
229
- with log_file.open("a") as f:
230
- f.write(json.dumps(
231
- {
232
- 'user_input': user_input,
233
- 'retrieved_context': context_for_query,
234
- 'model_response': prediction
235
- },
236
- indent=2
237
- ))
238
- f.write("\n")
 
 
 
 
 
239
 
240
  return prediction
241
 
 
191
  ]
192
 
193
  # Get response from the LLM
194
+
195
+ url = "https://api.fireworks.ai/inference/v1/chat/completions"
196
+ payload = {
197
+ "model": "accounts/fireworks/models/llama-v3p3-70b-instruct",
198
+ "temperature": 0.6,
199
+ "top_p": 1,
200
+ "top_k": 40,
201
+ "presence_penalty": 0,
202
+ "frequency_penalty": 0,
203
+ "messages": [
204
+ {
205
+ "role": "user",
206
+ "content": f"{prompt}"
207
+ }
208
  ]
209
+ }
210
+ headers = {
211
+ "Accept": "application/json",
212
+ "Content-Type": "application/json",
213
+ "Authorization": f"Bearer {api_key}"
214
+ }
 
 
215
 
216
+ response = requests.post(url, headers=headers, json=payload)
217
 
218
+ prediction = response.json()["choices"][0]["message"]["content"]
 
 
 
 
 
219
 
220
+
221
+ if response.ok:
222
+ print(response.json()["choices"][0]["message"]["content"])
223
+ else:
224
+ print(f"❌ Error {response.status_code}: {response.text}")
225
+ # # Log safely
226
+ # with scheduler.lock:
227
+ # with log_file.open("a") as f:
228
+ # f.write(json.dumps(
229
+ # {
230
+ # 'user_input': user_input,
231
+ # 'retrieved_context': context_for_query,
232
+ # 'model_response': prediction
233
+ # },
234
+ # indent=2
235
+ # ))
236
+ # f.write("\n")
237
 
238
  return prediction
239