Spaces:
Runtime error
Runtime error
Update app.py
Browse files57 unmodified lines5859606162636465666768697071727374757677787957 unmodified lines# Use Hugging Face APIclient = InferenceClient(model, token=huggingface_token)main_content = ""try:for i in range(num_calls):response = await client.chat_completion(messages=[{"role": "user", "content": prompt}],max_tokens=6000,temperature=temperature,)if response.choices and response.choices[0].message:chunk = response.choices[0].message.contentmain_content += chunkyield main_content, ""except Exception as e:logging.error(f"Error in get_response_with_search: {str(e)}")yield f"An error occurred while processing your request: {str(e)}", ""async def respond(message, history, model, temperature, num_calls, use_embeddings):logging.info(f"User Query: {message}")logging.info(f"Model Used: {model}")57 unmodified lines5859606162636465666768697071727374757677787980818283848586878889909157 unmodified lines# Use Hugging Face APIclient = InferenceClient(model, token=huggingface_token)full_response = ""try:for _ in range(num_calls):for response in client.chat_completion(messages=[{"role": "user", "content": prompt}],max_tokens=6000,temperature=temperature,stream=True,top_p=0.9,):if isinstance(response, dict) and "choices" in response:for choice in response["choices"]:if "delta" in choice and "content" in choice["delta"]:chunk = choice["delta"]["content"]full_response += chunkyield full_response, ""else:logging.error("Unexpected response format or missing attributes in the response object.")breakexcept Exception as e:logging.error(f"Error in get_response_with_search: {str(e)}")yield f"An error occurred while processing your request: {str(e)}", ""if not full_response:logging.warning("No response generated from the model")yield "No response generated from the model.", ""async def respond(message, history, model, temperature, num_calls, use_embeddings):logging.info(f"User Query: {message}")logging.info(f"Model Used: {model}")
app.py+20-8