Shreyas094
commited on
Commit
•
eb21d5d
1
Parent(s):
f8b4cd1
Update app.py
Browse files
app.py
CHANGED
@@ -472,10 +472,10 @@ def get_response_from_excel(query, model, context, num_calls=3, temperature=0.2)
|
|
472 |
logging.info("Finished generating response for Excel data")
|
473 |
|
474 |
def get_response_from_llama(query, model, selected_docs, file_type, num_calls=1, temperature=0.2):
|
475 |
-
logging.info(f"
|
476 |
|
477 |
-
# Initialize the Hugging Face client
|
478 |
client = InferenceClient(model, token=huggingface_token)
|
|
|
479 |
|
480 |
if file_type == "excel":
|
481 |
# Excel functionality
|
@@ -518,27 +518,35 @@ def get_response_from_llama(query, model, selected_docs, file_type, num_calls=1,
|
|
518 |
|
519 |
else:
|
520 |
raise ValueError("Invalid file type. Use 'excel' or 'pdf'.")
|
521 |
-
|
|
|
|
|
522 |
full_response = ""
|
523 |
-
for
|
|
|
524 |
try:
|
525 |
-
# Generate content with streaming enabled
|
526 |
for message in client.chat.completions.create(
|
527 |
messages=messages,
|
528 |
max_tokens=2000,
|
529 |
temperature=temperature,
|
530 |
stream=True,
|
531 |
):
|
|
|
532 |
if message.choices and message.choices[0].delta and message.choices[0].delta.content:
|
533 |
chunk = message.choices[0].delta.content
|
534 |
full_response += chunk
|
535 |
-
|
|
|
536 |
except Exception as e:
|
|
|
537 |
yield f"An error occurred with the Llama model: {str(e)}. Please try again."
|
538 |
|
539 |
if not full_response:
|
|
|
540 |
yield "No response generated from the Llama model."
|
541 |
-
|
|
|
|
|
542 |
# Modify the existing respond function to handle both PDF and web search
|
543 |
def respond(message, history, model, temperature, num_calls, use_web_search, selected_docs):
|
544 |
logging.info(f"User Query: {message}")
|
|
|
472 |
logging.info("Finished generating response for Excel data")
|
473 |
|
474 |
def get_response_from_llama(query, model, selected_docs, file_type, num_calls=1, temperature=0.2):
|
475 |
+
logging.info(f"Starting get_response_from_llama with query: {query}, model: {model}, file_type: {file_type}")
|
476 |
|
|
|
477 |
client = InferenceClient(model, token=huggingface_token)
|
478 |
+
logging.info("InferenceClient initialized")
|
479 |
|
480 |
if file_type == "excel":
|
481 |
# Excel functionality
|
|
|
518 |
|
519 |
else:
|
520 |
raise ValueError("Invalid file type. Use 'excel' or 'pdf'.")
|
521 |
+
|
522 |
+
logging.info(f"Prepared messages: {messages}")
|
523 |
+
|
524 |
full_response = ""
|
525 |
+
for i in range(num_calls):
|
526 |
+
logging.info(f"Starting API call {i+1}/{num_calls}")
|
527 |
try:
|
|
|
528 |
for message in client.chat.completions.create(
|
529 |
messages=messages,
|
530 |
max_tokens=2000,
|
531 |
temperature=temperature,
|
532 |
stream=True,
|
533 |
):
|
534 |
+
logging.debug(f"Received message chunk: {message}")
|
535 |
if message.choices and message.choices[0].delta and message.choices[0].delta.content:
|
536 |
chunk = message.choices[0].delta.content
|
537 |
full_response += chunk
|
538 |
+
logging.debug(f"Accumulated response length: {len(full_response)}")
|
539 |
+
yield full_response
|
540 |
except Exception as e:
|
541 |
+
logging.error(f"Error during API call {i+1}: {str(e)}")
|
542 |
yield f"An error occurred with the Llama model: {str(e)}. Please try again."
|
543 |
|
544 |
if not full_response:
|
545 |
+
logging.warning("No response generated from the Llama model")
|
546 |
yield "No response generated from the Llama model."
|
547 |
+
else:
|
548 |
+
logging.info(f"Final response length: {len(full_response)}")
|
549 |
+
|
550 |
# Modify the existing respond function to handle both PDF and web search
|
551 |
def respond(message, history, model, temperature, num_calls, use_web_search, selected_docs):
|
552 |
logging.info(f"User Query: {message}")
|