Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -96,7 +96,6 @@ ModelID = Literal[
|
|
96 |
"qwen/qwen-72b-chat",
|
97 |
"google/gemma-2-27b-it"
|
98 |
]
|
99 |
-
|
100 |
class FollowupQueryModel(BaseModel):
|
101 |
query: str = Field(..., description="User's query for the followup agent")
|
102 |
model_id: ModelID = Field(
|
@@ -105,6 +104,7 @@ class FollowupQueryModel(BaseModel):
|
|
105 |
)
|
106 |
conversation_id: str = Field(default_factory=lambda: str(uuid4()), description="Unique identifier for the conversation")
|
107 |
user_id: str = Field(..., description="Unique identifier for the user")
|
|
|
108 |
|
109 |
class Config:
|
110 |
schema_extra = {
|
@@ -113,18 +113,20 @@ class FollowupQueryModel(BaseModel):
|
|
113 |
"model_id": "openai/gpt-4o-mini",
|
114 |
"conversation_id": "123e4567-e89b-12d3-a456-426614174000",
|
115 |
"user_id": "user123",
|
116 |
-
"
|
117 |
}
|
118 |
}
|
119 |
|
120 |
|
121 |
-
|
122 |
-
async def digiyatra_query_table(query: str, db: Annotated[Any, Depends(get_db_connection)], limit: Optional[int] = 5):
|
123 |
"""Query the digiyatra table."""
|
|
|
|
|
|
|
124 |
response = await query_table(
|
125 |
-
table_id=
|
126 |
-
query=query,
|
127 |
-
user_id=
|
128 |
limit=limit
|
129 |
)
|
130 |
return response.results['data'][0]['text']
|
@@ -143,7 +145,7 @@ async def followup_agent(query: FollowupQueryModel, background_tasks: Background
|
|
143 |
{"role": "system", "content": FOLLOWUP_DIGIYATRA_PROMPT}
|
144 |
]
|
145 |
|
146 |
-
digiyatra_response = await digiyatra_query_table(query
|
147 |
user_query_with_context = f"{query.query} \n\n FAQ Context for ANSWERING: {digiyatra_response}"
|
148 |
conversations[query.conversation_id].append({"role": "user", "content": user_query_with_context})
|
149 |
last_activity[query.conversation_id] = time.time()
|
@@ -182,6 +184,7 @@ async def followup_agent(query: FollowupQueryModel, background_tasks: Background
|
|
182 |
logger.error(f"Error in followup_agent: {str(e)}")
|
183 |
raise HTTPException(status_code=500, detail="An error occurred while processing the followup agent request.")
|
184 |
|
|
|
185 |
from fastapi.middleware.cors import CORSMiddleware
|
186 |
|
187 |
app.add_middleware(
|
|
|
96 |
"qwen/qwen-72b-chat",
|
97 |
"google/gemma-2-27b-it"
|
98 |
]
|
|
|
99 |
class FollowupQueryModel(BaseModel):
|
100 |
query: str = Field(..., description="User's query for the followup agent")
|
101 |
model_id: ModelID = Field(
|
|
|
104 |
)
|
105 |
conversation_id: str = Field(default_factory=lambda: str(uuid4()), description="Unique identifier for the conversation")
|
106 |
user_id: str = Field(..., description="Unique identifier for the user")
|
107 |
+
table_id: Optional[str] = Field(None, description="Optional knowledge base table identifier for the query")
|
108 |
|
109 |
class Config:
|
110 |
schema_extra = {
|
|
|
113 |
"model_id": "openai/gpt-4o-mini",
|
114 |
"conversation_id": "123e4567-e89b-12d3-a456-426614174000",
|
115 |
"user_id": "user123",
|
116 |
+
"table_id":"digiyatra"
|
117 |
}
|
118 |
}
|
119 |
|
120 |
|
121 |
+
async def digiyatra_query_table(query: FollowupQueryModel, db: Annotated[Any, Depends(get_db_connection)], limit: Optional[int] = 5):
|
|
|
122 |
"""Query the digiyatra table."""
|
123 |
+
if query.table_id is None:
|
124 |
+
query.table_id = "digiyatra"
|
125 |
+
|
126 |
response = await query_table(
|
127 |
+
table_id=query.table_id,
|
128 |
+
query=query.query,
|
129 |
+
user_id=query.user_id,
|
130 |
limit=limit
|
131 |
)
|
132 |
return response.results['data'][0]['text']
|
|
|
145 |
{"role": "system", "content": FOLLOWUP_DIGIYATRA_PROMPT}
|
146 |
]
|
147 |
|
148 |
+
digiyatra_response = await digiyatra_query_table(query, db=get_db_connection(), limit=5)
|
149 |
user_query_with_context = f"{query.query} \n\n FAQ Context for ANSWERING: {digiyatra_response}"
|
150 |
conversations[query.conversation_id].append({"role": "user", "content": user_query_with_context})
|
151 |
last_activity[query.conversation_id] = time.time()
|
|
|
184 |
logger.error(f"Error in followup_agent: {str(e)}")
|
185 |
raise HTTPException(status_code=500, detail="An error occurred while processing the followup agent request.")
|
186 |
|
187 |
+
|
188 |
from fastapi.middleware.cors import CORSMiddleware
|
189 |
|
190 |
app.add_middleware(
|