Shreyas094 commited on
Commit
c7e4b70
·
verified ·
1 Parent(s): 922ee31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -33,7 +33,6 @@ print(f"CLOUDFLARE_AUTH_TOKEN: {API_TOKEN[:5]}..." if API_TOKEN else "Not set")
33
  MODELS = [
34
  "mistralai/Mistral-7B-Instruct-v0.3",
35
  "mistralai/Mixtral-8x7B-Instruct-v0.1",
36
- "meta-llama/Meta-Llama-3.1-8B-Instruct",
37
  "@cf/meta/llama-3.1-8b-instruct"
38
  ]
39
 
@@ -349,20 +348,26 @@ def get_response_from_pdf(query, model, num_calls=3, temperature=0.2):
349
  {context_str}
350
  Write a detailed and complete response that answers the following user question: '{query}'"""
351
 
352
- client = InferenceClient(model, token=huggingface_token)
353
-
354
- response = ""
355
- for i in range(num_calls):
356
- for message in client.chat_completion(
357
- messages=[{"role": "user", "content": prompt}],
358
- max_tokens=1000,
359
- temperature=temperature,
360
- stream=True,
361
- ):
362
- if message.choices and message.choices[0].delta and message.choices[0].delta.content:
363
- chunk = message.choices[0].delta.content
364
- response += chunk
365
- yield response # Yield partial response
 
 
 
 
 
 
366
 
367
  def vote(data: gr.LikeData):
368
  if data.liked:
 
33
  MODELS = [
34
  "mistralai/Mistral-7B-Instruct-v0.3",
35
  "mistralai/Mixtral-8x7B-Instruct-v0.1",
 
36
  "@cf/meta/llama-3.1-8b-instruct"
37
  ]
38
 
 
348
  {context_str}
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:
356
+ # Use Hugging Face API
357
+ client = InferenceClient(model, token=huggingface_token)
358
+
359
+ response = ""
360
+ for i in range(num_calls):
361
+ for message in client.chat_completion(
362
+ messages=[{"role": "user", "content": prompt}],
363
+ max_tokens=1000,
364
+ temperature=temperature,
365
+ stream=True,
366
+ ):
367
+ if message.choices and message.choices[0].delta and message.choices[0].delta.content:
368
+ chunk = message.choices[0].delta.content
369
+ response += chunk
370
+ yield response # Yield partial response
371
 
372
  def vote(data: gr.LikeData):
373
  if data.liked: