Update app.py
Browse files
app.py
CHANGED
|
@@ -191,51 +191,49 @@ def predict(user_input,company):
|
|
| 191 |
]
|
| 192 |
|
| 193 |
# Get response from the LLM
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
]
|
| 209 |
-
}
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
}
|
| 215 |
-
|
| 216 |
-
response = requests.post(url, headers=headers, json=payload)
|
| 217 |
|
| 218 |
-
|
| 219 |
|
| 220 |
-
|
| 221 |
-
prediction = {
|
| 222 |
-
"error_type": type(e).__name__,
|
| 223 |
-
"error_message": str(e),
|
| 224 |
-
"traceback": traceback.format_exc()
|
| 225 |
-
}
|
| 226 |
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|