Update app.py
Browse files99 unmodified lines10010110210310410526 unmodified lines13213313413513613713813914014114214314414514614799 unmodified linesreturn FAISS.from_documents(documents, embed)def get_response_with_search(query, model, num_calls=3, temperature=0.2):search_results = duckduckgo_search(query)web_search_database = create_web_search_vectors(search_results)26 unmodified linesmain_content = ""for i in range(num_calls):for message in client.chat_completion(messages=[{"role": "user", "content": prompt}],max_tokens=max_new_tokens,temperature=temperature,stream=False,):if message.choices and message.choices[0].delta and message.choices[0].delta.content:chunk = message.choices[0].delta.contentmain_content += chunkyield main_content, "" # Yield partial main content without sourcesdef vote(data: gr.LikeData):if data.liked:99 unmodified lines10010110210310410510610726 unmodified lines13413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017199 unmodified linesreturn FAISS.from_documents(documents, embed)import jsondef get_response_with_search(query, model, num_calls=3, temperature=0.2):search_results = duckduckgo_search(query)web_search_database = create_web_search_vectors(search_results)26 unmodified linesmain_content = ""for i in range(num_calls):try:response = client.chat_completion(messages=[{"role": "user", "content": prompt}],max_new_tokens=max_new_tokens,temperature=temperature,stream=False,)# Log the raw response for debugginglogging.info(f"Raw API response: {response}")# Check if the response is a string (which might be an error message)if isinstance(response, str):logging.error(f"API returned an unexpected string response: {response}")yield f"An error occurred: {response}", ""return# If it's not a string, assume it's the expected object structureif hasattr(response, 'choices') and response.choices:for choice in response.choices:if hasattr(choice, 'message') and hasattr(choice.message, 'content'):chunk = choice.message.contentmain_content += chunkyield main_content, "" # Yield partial main content without sourceselse:logging.error(f"Unexpected response structure: {response}")yield "An unexpected error occurred. Please try again.", ""except Exception as e:logging.error(f"Error in API call: {str(e)}")yield f"An error occurred: {str(e)}", ""returndef vote(data: gr.LikeData):if data.liked:
app.py+34-10