Skip to content

Commit e2a9294

Browse files
committed
update
1 parent 8ba2ff4 commit e2a9294

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

examples/docqa/doc-chat-simple.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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)

0 commit comments

Comments
 (0)