Skip to content

Commit

Permalink
fix: reset docs on each interaction (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbarda authored Oct 17, 2024
1 parent c0c9764 commit 804b3cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/retrieval_graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class Plan(TypedDict):
{"role": "system", "content": configuration.research_plan_system_prompt}
] + state.messages
response = cast(Plan, await model.ainvoke(messages))
return {"steps": response["steps"]}
return {"steps": response["steps"], "documents": "delete"}


async def conduct_research(state: AgentState) -> dict[str, Any]:
Expand Down
6 changes: 5 additions & 1 deletion backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

import uuid
from typing import Any, Optional, Union
from typing import Any, Literal, Optional, Union

from langchain.chat_models import init_chat_model
from langchain_core.documents import Document
Expand Down Expand Up @@ -89,6 +89,7 @@ def reduce_docs(
list[dict[str, Any]],
list[str],
str,
Literal["delete"],
],
) -> list[Document]:
"""Reduce and process documents based on the input type.
Expand All @@ -101,6 +102,9 @@ def reduce_docs(
new (Union[Sequence[Document], Sequence[dict[str, Any]], Sequence[str], str, Literal["delete"]]):
The new input to process. Can be a sequence of Documents, dictionaries, strings, or a single string.
"""
if new == "delete":
return []

existing_list = list(existing) if existing else []
if isinstance(new, str):
return existing_list + [
Expand Down

0 comments on commit 804b3cd

Please sign in to comment.