Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -250,35 +250,28 @@ def respond(message, history, model, temperature, num_calls, use_web_search):
|
|
250 |
|
251 |
logging.basicConfig(level=logging.DEBUG)
|
252 |
|
253 |
-
def get_response_from_cloudflare(
|
254 |
headers = {
|
255 |
"Authorization": f"Bearer {API_TOKEN}",
|
256 |
"Content-Type": "application/json"
|
257 |
}
|
258 |
model = "@cf/meta/llama-3.1-8b-instruct"
|
259 |
|
260 |
-
logging.debug(f"API_BASE_URL: {API_BASE_URL}")
|
261 |
-
logging.debug(f"API_TOKEN: {API_TOKEN[:5]}...")
|
262 |
-
|
263 |
-
prompt = f"Write a detailed and complete response that answers the following user question: '{query}'"
|
264 |
-
|
265 |
inputs = [
|
266 |
-
{"role": "system", "content": "You are a friendly assistant that helps answer questions."},
|
267 |
{"role": "user", "content": prompt}
|
268 |
]
|
269 |
|
270 |
payload = {
|
271 |
"messages": inputs,
|
272 |
-
"stream": True
|
|
|
273 |
}
|
274 |
|
275 |
full_response = ""
|
276 |
for i in range(num_calls):
|
277 |
try:
|
278 |
with requests.post(f"{API_BASE_URL}{model}", headers=headers, json=payload, stream=True) as response:
|
279 |
-
logging.debug(f"Cloudflare API Response Status: {response.status_code}")
|
280 |
-
logging.debug(f"Cloudflare API Response Headers: {response.headers}")
|
281 |
-
|
282 |
if response.status_code == 200:
|
283 |
for line in response.iter_lines():
|
284 |
if line:
|
@@ -349,7 +342,7 @@ def get_response_from_pdf(query, model, num_calls=3, temperature=0.2):
|
|
349 |
Write a detailed and complete response that answers the following user question: '{query}'"""
|
350 |
|
351 |
if model == "@cf/meta/llama-3.1-8b-instruct":
|
352 |
-
# Use Cloudflare API
|
353 |
for response in get_response_from_cloudflare(prompt, num_calls, temperature):
|
354 |
yield response
|
355 |
else:
|
|
|
250 |
|
251 |
logging.basicConfig(level=logging.DEBUG)
|
252 |
|
253 |
+
def get_response_from_cloudflare(prompt, num_calls=3, temperature=0.2):
|
254 |
headers = {
|
255 |
"Authorization": f"Bearer {API_TOKEN}",
|
256 |
"Content-Type": "application/json"
|
257 |
}
|
258 |
model = "@cf/meta/llama-3.1-8b-instruct"
|
259 |
|
|
|
|
|
|
|
|
|
|
|
260 |
inputs = [
|
261 |
+
{"role": "system", "content": "You are a friendly assistant that helps answer questions based on provided context."},
|
262 |
{"role": "user", "content": prompt}
|
263 |
]
|
264 |
|
265 |
payload = {
|
266 |
"messages": inputs,
|
267 |
+
"stream": True,
|
268 |
+
"temperature": temperature
|
269 |
}
|
270 |
|
271 |
full_response = ""
|
272 |
for i in range(num_calls):
|
273 |
try:
|
274 |
with requests.post(f"{API_BASE_URL}{model}", headers=headers, json=payload, stream=True) as response:
|
|
|
|
|
|
|
275 |
if response.status_code == 200:
|
276 |
for line in response.iter_lines():
|
277 |
if line:
|
|
|
342 |
Write a detailed and complete response that answers the following user question: '{query}'"""
|
343 |
|
344 |
if model == "@cf/meta/llama-3.1-8b-instruct":
|
345 |
+
# Use Cloudflare API with the retrieved context
|
346 |
for response in get_response_from_cloudflare(prompt, num_calls, temperature):
|
347 |
yield response
|
348 |
else:
|