File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ Bare-bones example of using DocChatAgent to query a document.
3+
4+ Run like this:
5+
6+ python3 examples/docqa/doc-chat-simple.py
7+
8+ """
9+
10+ import langroid .language_models as lm
11+ from langroid .agent .special .doc_chat_agent import (
12+ DocChatAgent ,
13+ DocChatAgentConfig ,
14+ )
15+ from fire import Fire
16+
17+
18+ def main (model : str = "" ):
19+ # set up the agent
20+ agent = DocChatAgent (
21+ DocChatAgentConfig (
22+ llm = lm .OpenAIGPTConfig (chat_model = model or lm .OpenAIChatModel .GPT4o ),
23+ # several configs possible here, omitted for brevity
24+ )
25+ )
26+
27+ # ingest document(s), could be a local file/folder or URL
28+ # Try Borges' "Library of Babel" short story
29+ url = "https://xpressenglish.com/our-stories/library-of-babel/"
30+
31+ agent .ingest_doc_paths ([url ])
32+
33+ result = agent .llm_response ("what is the shape of the rooms in the library?" )
34+
35+ assert "hexagon" in result .content .lower ()
36+
37+ print (result .content )
38+
39+
40+ if __name__ == "__main__" :
41+ Fire (main )
You can’t perform that action at this time.
0 commit comments