Spaces:
Sleeping
Sleeping
for debugging
Browse files- ai_service.py +5 -5
ai_service.py
CHANGED
|
@@ -52,7 +52,7 @@ async def get_ai_response(user_query: str, telegram_id: int = None):
|
|
| 52 |
if not pc or not index or not hf_client:
|
| 53 |
return "عذراً، خدمة الذكاء الاصطناعي غير متوفرة حالياً."
|
| 54 |
|
| 55 |
-
|
| 56 |
conversation_history = []
|
| 57 |
if telegram_id and db_manager:
|
| 58 |
db_manager.save_message(telegram_id, user_query, "user")
|
|
@@ -66,7 +66,7 @@ async def get_ai_response(user_query: str, telegram_id: int = None):
|
|
| 66 |
|
| 67 |
messages = [{"role": "system", "content": PROMPT}] + conversation_history
|
| 68 |
|
| 69 |
-
|
| 70 |
response = hf_client.chat.completions.create(
|
| 71 |
model=MODEL_NAME,
|
| 72 |
messages=messages,
|
|
@@ -80,7 +80,7 @@ async def get_ai_response(user_query: str, telegram_id: int = None):
|
|
| 80 |
|
| 81 |
|
| 82 |
if tool_calls:
|
| 83 |
-
|
| 84 |
for tool_call in tool_calls:
|
| 85 |
function_args = json.loads(tool_call.function.arguments)
|
| 86 |
search_query = function_args.get("query")
|
|
@@ -105,10 +105,10 @@ async def get_ai_response(user_query: str, telegram_id: int = None):
|
|
| 105 |
)
|
| 106 |
ai_final_content = final_response.choices[0].message.content
|
| 107 |
else:
|
| 108 |
-
|
| 109 |
ai_final_content = response_message.content
|
| 110 |
|
| 111 |
-
|
| 112 |
cleaned_response = clean_ai_response(ai_final_content)
|
| 113 |
|
| 114 |
if telegram_id and db_manager:
|
|
|
|
| 52 |
if not pc or not index or not hf_client:
|
| 53 |
return "عذراً، خدمة الذكاء الاصطناعي غير متوفرة حالياً."
|
| 54 |
|
| 55 |
+
print(f"User query: {user_query}")
|
| 56 |
conversation_history = []
|
| 57 |
if telegram_id and db_manager:
|
| 58 |
db_manager.save_message(telegram_id, user_query, "user")
|
|
|
|
| 66 |
|
| 67 |
messages = [{"role": "system", "content": PROMPT}] + conversation_history
|
| 68 |
|
| 69 |
+
print(f"getting response from Messages: {messages}")
|
| 70 |
response = hf_client.chat.completions.create(
|
| 71 |
model=MODEL_NAME,
|
| 72 |
messages=messages,
|
|
|
|
| 80 |
|
| 81 |
|
| 82 |
if tool_calls:
|
| 83 |
+
print(f"tool_calls: {tool_calls}")
|
| 84 |
for tool_call in tool_calls:
|
| 85 |
function_args = json.loads(tool_call.function.arguments)
|
| 86 |
search_query = function_args.get("query")
|
|
|
|
| 105 |
)
|
| 106 |
ai_final_content = final_response.choices[0].message.content
|
| 107 |
else:
|
| 108 |
+
print(f"response_message: {response_message}")
|
| 109 |
ai_final_content = response_message.content
|
| 110 |
|
| 111 |
+
print(f"ai_final_content: {ai_final_content}")
|
| 112 |
cleaned_response = clean_ai_response(ai_final_content)
|
| 113 |
|
| 114 |
if telegram_id and db_manager:
|