Spaces:
Build error
Build error
Ganesh Chintalapati commited on
Commit ·
a3ce268
1
Parent(s): 5925c4b
modular code apsssjjj
Browse files
core.py
CHANGED
|
@@ -4,7 +4,7 @@ from typing import AsyncGenerator, List, Dict, Tuple
|
|
| 4 |
from config import logger
|
| 5 |
from api import ask_openai, ask_anthropic, ask_gemini
|
| 6 |
|
| 7 |
-
async def query_model(query: str, providers: List[str], history: List[Dict[str, str]]) -> AsyncGenerator[Tuple[str, List[Dict[str, str]], List[Dict[str, str]], List[Dict[str, str]]], None]:
|
| 8 |
logger.info(f"Processing query with providers: {providers}")
|
| 9 |
openai_response = ""
|
| 10 |
anthropic_response = ""
|
|
@@ -92,7 +92,7 @@ async def query_model(query: str, providers: List[str], history: List[Dict[str,
|
|
| 92 |
gemini_response = response
|
| 93 |
gemini_messages = messages
|
| 94 |
logger.info(f"Yielding update for {provider}: {response[:50]}...")
|
| 95 |
-
yield
|
| 96 |
new_generator_states[new_generator_states.index((provider, gen, task))] = (provider, gen, None)
|
| 97 |
except StopAsyncIteration:
|
| 98 |
logger.info(f"Generator for {provider} completed")
|
|
@@ -103,19 +103,18 @@ async def query_model(query: str, providers: List[str], history: List[Dict[str,
|
|
| 103 |
|
| 104 |
active_generators = new_generator_states
|
| 105 |
|
| 106 |
-
|
| 107 |
if openai_response.strip() and not openai_response.startswith("Error:"):
|
| 108 |
-
|
| 109 |
if anthropic_response.strip() and not anthropic_response.startswith("Error:"):
|
| 110 |
-
|
| 111 |
if gemini_response.strip() and not gemini_response.startswith("Error:"):
|
| 112 |
-
|
| 113 |
|
| 114 |
-
|
| 115 |
-
updated_history = history + [{"user": query, "bot": combined_response}]
|
| 116 |
logger.info(f"Updated history: {updated_history}")
|
| 117 |
|
| 118 |
-
yield combined_response, openai_messages, anthropic_messages, gemini_messages
|
| 119 |
|
| 120 |
async def submit_query(query: str, providers: List[str], history: List[Dict[str, str]]) -> AsyncGenerator[Tuple[str, List[Dict[str, str]], List[Dict[str, str]], List[Dict[str, str]], List[Dict[str, str]]], None]:
|
| 121 |
|
|
|
|
| 4 |
from config import logger
|
| 5 |
from api import ask_openai, ask_anthropic, ask_gemini
|
| 6 |
|
| 7 |
+
async def query_model(query: str, providers: List[str], history: List[Dict[str, str]]) -> AsyncGenerator[Tuple[str, str, List[Dict[str, str]], List[Dict[str, str]], List[Dict[str, str]]], None]:
|
| 8 |
logger.info(f"Processing query with providers: {providers}")
|
| 9 |
openai_response = ""
|
| 10 |
anthropic_response = ""
|
|
|
|
| 92 |
gemini_response = response
|
| 93 |
gemini_messages = messages
|
| 94 |
logger.info(f"Yielding update for {provider}: {response[:50]}...")
|
| 95 |
+
yield response, openai_messages, anthropic_messages, gemini_messages
|
| 96 |
new_generator_states[new_generator_states.index((provider, gen, task))] = (provider, gen, None)
|
| 97 |
except StopAsyncIteration:
|
| 98 |
logger.info(f"Generator for {provider} completed")
|
|
|
|
| 103 |
|
| 104 |
active_generators = new_generator_states
|
| 105 |
|
| 106 |
+
combined_response = ""
|
| 107 |
if openai_response.strip() and not openai_response.startswith("Error:"):
|
| 108 |
+
combined_response += f"[OpenAI]: {openai_response}\n\n"
|
| 109 |
if anthropic_response.strip() and not anthropic_response.startswith("Error:"):
|
| 110 |
+
combined_response += f"[Anthropic]: {anthropic_response}\n\n"
|
| 111 |
if gemini_response.strip() and not gemini_response.startswith("Error:"):
|
| 112 |
+
combined_response += f"[Gemini]: {gemini_response}"
|
| 113 |
|
| 114 |
+
updated_history = history + [{"user": query, "bot": combined_response.strip()}]
|
|
|
|
| 115 |
logger.info(f"Updated history: {updated_history}")
|
| 116 |
|
| 117 |
+
yield combined_response.strip(), openai_messages, anthropic_messages, gemini_messages
|
| 118 |
|
| 119 |
async def submit_query(query: str, providers: List[str], history: List[Dict[str, str]]) -> AsyncGenerator[Tuple[str, List[Dict[str, str]], List[Dict[str, str]], List[Dict[str, str]], List[Dict[str, str]]], None]:
|
| 120 |
|