Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import uuid
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from fastapi.responses import StreamingResponse
|
|
@@ -196,19 +200,30 @@ def get_collection_files(collection_id: str, user_id: str) -> str:
|
|
| 196 |
logger.error(f"Error getting collection files: {str(e)}")
|
| 197 |
return f"Error getting files: {str(e)}"
|
| 198 |
|
| 199 |
-
def format_for_model(state):
|
| 200 |
-
|
| 201 |
-
config
|
| 202 |
-
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
# Get files in the collection
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
|
|
|
| 209 |
return prompt.invoke({
|
| 210 |
"collection_files": collection_files,
|
| 211 |
-
"messages": state
|
| 212 |
})
|
| 213 |
|
| 214 |
async def clean_tool_input(tool_input: str):
|
|
|
|
| 1 |
+
#DOCS
|
| 2 |
+
# https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.chat_agent_executor.create_react_agent
|
| 3 |
+
|
| 4 |
+
|
| 5 |
import uuid
|
| 6 |
from fastapi import FastAPI
|
| 7 |
from fastapi.responses import StreamingResponse
|
|
|
|
| 200 |
logger.error(f"Error getting collection files: {str(e)}")
|
| 201 |
return f"Error getting files: {str(e)}"
|
| 202 |
|
| 203 |
+
def format_for_model(state: dict, config: Optional[RunnableConfig] = None) -> list[BaseMessage]:
|
| 204 |
+
"""
|
| 205 |
+
Format the input state and config for the model.
|
| 206 |
+
|
| 207 |
+
Args:
|
| 208 |
+
state: The current state dictionary containing messages
|
| 209 |
+
config: Optional RunnableConfig containing thread configuration
|
| 210 |
+
|
| 211 |
+
Returns:
|
| 212 |
+
Formatted messages for the model
|
| 213 |
+
"""
|
| 214 |
+
# Get collection_id and user_id from config instead of state
|
| 215 |
+
thread_config = config.get("configurable", {}) if config else {}
|
| 216 |
+
collection_id = thread_config.get("collection_id")
|
| 217 |
+
user_id = thread_config.get("user_id")
|
| 218 |
|
| 219 |
# Get files in the collection
|
| 220 |
+
collection_files = get_collection_files(collection_id, user_id) if collection_id and user_id else "No files available"
|
| 221 |
+
logger.info(f"Fetching collection for userid {user_id} and collection_id {collection_id} || Results: {collection_files}")
|
| 222 |
+
|
| 223 |
+
# Format using the prompt template
|
| 224 |
return prompt.invoke({
|
| 225 |
"collection_files": collection_files,
|
| 226 |
+
"messages": state.get("messages", []) # Safely get messages with default empty list
|
| 227 |
})
|
| 228 |
|
| 229 |
async def clean_tool_input(tool_input: str):
|