Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
neoguojing committed Dec 11, 2024
1 parent 013e255 commit e619b21
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# agi
langchain based agi

## RAG
- history_chain = RunnableLambda(self._enter_history, self._aenter_history).with_config(run_name="load_history")
- history_chain = RunnablePassthrough.assign(**{"chat_history": history_chain}).with_config(run_name="insert_history")
- retrieval_docs = (lambda x: x["input"]) | retriever
- retriever = (lambda x: x["input"]) | retriever or prompt | llm | StrOutputParser() | retriever, run_name="chat_retriever_chain"
- context=retrieval_docs.with_config(run_name="retrieve_documents")
- "context": format_docs run_name="format_inputs"
- answer = "context" | prompt | llm | _output_parser run_name="stuff_documents_chain"
10 changes: 9 additions & 1 deletion agi/tasks/llm_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@ def create_history_aware_retriever(
).with_config(run_name="chat_retriever_chain")

return retrieve_documents


# chain:RunnableWithMessageHistory
# chain:insert_history
# chain:RunnableParallel<chat_history>
# chain:load_history
# chain:check_sync_or_async
# chain:retrieval_chain
# chain:RunnableAssign<answer>
# chain:RunnableParallel<answer>
def create_chat_with_rag(km: KnowledgeManager,llm,**kwargs):
retrievers = create_retriever(km,**kwargs)

Expand Down
5 changes: 4 additions & 1 deletion tests/tasks/task_factory_rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def setUp(self):
def test_rag(self):
config={"configurable": {"user_id": "test", "conversation_id": "1"}}
ret = self.rag.invoke({"text":"上海未来一周天气如何?","language":"chinese"},config=config)
print(ret)
self.assertIsNotNone(ret)
self.assertIsInstance(ret['chat_history'],list)
self.assertIsInstance(ret['context'],list)
self.assertIsNotNone(ret['answer'])

if __name__ == '__main__':
unittest.main()

0 comments on commit e619b21

Please sign in to comment.