-
Notifications
You must be signed in to change notification settings - Fork 30
/
chat-agent.py
58 lines (45 loc) · 1.33 KB
/
chat-agent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
This example shows how you can use Langroid to define a basic Agent
encapsulating a chat LLM, and use it to set up an interactive chat session.
Run as follows:
python3 examples/quick-start/chat-agent.py
More details in the
[Getting Started guide](https://langroid.github.io/langroid/quick-start/chat-agent/)
"""
import typer
from rich import print
import langroid as lr
app = typer.Typer()
lr.utils.logging.setup_colored_logging()
def chat() -> None:
print(
"""
[blue]Welcome to the basic chatbot!
Enter x or q to quit
"""
)
config = lr.ChatAgentConfig(
llm=lr.language_models.OpenAIGPTConfig(
chat_model=lr.language_models.OpenAIChatModel.GPT4,
),
vecdb=None,
)
agent = lr.ChatAgent(config)
task = lr.Task(agent, name="Bot")
task.run()
@app.command()
def main(
debug: bool = typer.Option(False, "--debug", "-d", help="debug mode"),
no_stream: bool = typer.Option(False, "--nostream", "-ns", help="no streaming"),
nocache: bool = typer.Option(False, "--nocache", "-nc", help="don't use cache"),
) -> None:
lr.utils.configuration.set_global(
lr.utils.configuration.Settings(
debug=debug,
cache=not nocache,
stream=not no_stream,
)
)
chat()
if __name__ == "__main__":
app()