pvanand commited on
Commit
564f142
·
verified ·
1 Parent(s): 8c314b2

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +24 -9
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
- # Get collection_id and user_id from the state's configurable
201
- config = state.get("configurable", {})
202
- collection_id = config.get("collection_id")
203
- user_id = config.get("user_id")
 
 
 
 
 
 
 
 
 
 
204
 
205
  # Get files in the collection
206
-
207
- collection_files = get_collection_files(collection_id, user_id) if collection_id and user_id else "No files available" #get_current_files()#
208
- logger.info(f"fetching collection for userid{user_id} and collection_id {collection_id}|| Results {collection_files}")
 
209
  return prompt.invoke({
210
  "collection_files": collection_files,
211
- "messages": state["messages"]
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):