Skip to content

Commit c424f58

Browse files
committed
updated based on PR review
1 parent c8812d7 commit c424f58

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

langroid-llm-agents/README.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
1-
### Langroid + Groq
1+
## How to use Langroid Multi-Agent Framework with Groq
2+
23
[Langroid](https://github.com/langroid/langroid) is an
34
open-source Python framework that simplifies building LLM applications,
45
using a Multi-Agent paradigm.
56

67
You can now use Langroid with Groq, by setting the model name to
78
`groq/<model>`, e.g., `groq/llama3-70b-8192`.
89

9-
To get started, create a virtual environment using Python 3.11:
10+
To get started, create a virtual environment using Python 3.11 and Langroid:
1011

1112

1213
```bash
1314
python3 -m venv .venv
1415
. ./.venv/bin/activate
1516
pip install --upgrade langroid
1617
````
17-
Place your `GROQ_API_KEY` in a `.env` file in the root directory of this project,
18-
it should have a line that looks like:
18+
19+
Place your `GROQ_API_KEY` in a `.env` file in the root directory of this project.
20+
If you don't have one, you can create an account on GroqCloud and
21+
generate one for free at https://console.groq.com.
22+
Your `.env` file should have a line that looks like the following:
23+
1924
```
2025
GROQ_API_KEY=gsk_...
2126
```
2227
Or you can set explicitly set this key in your environment before
2328
running the scripts.
2429
25-
Below is a bare-bones code example.
30+
### Simple code examples using Langroid with a Groq-hosted LLM
31+
32+
Here is how you can specify a Groq-hosted LLM with Langroid, and directly
33+
"chat" with the LLM
34+
2635
2736
```python
2837
import langroid as lr
@@ -36,19 +45,32 @@ llm_config = lm.OpenAIGPTConfig(
3645
llm = lm.OpenAIGPT(llm_config)
3746
3847
llm.chat("3+4=?").message
48+
```
3949
50+
The `llm` does _not_ maintain conversation state, so you must invoke `chat()` with
51+
a sequence of user-assistant messages. Langroid has a convenient `ChatAgent` abstraction
52+
that maintains this state for you:
53+
```python
4054
agent_config = lr.ChatAgentConfig(
4155
llm=llm_config,
4256
system_message="""Be nice but concise""",
4357
)
4458
4559
agent = lr.ChatAgent(agent_config)
60+
response = agent.llm_response("Capital of France?")
61+
# follow-up question works since agent maintains conversation history
62+
response = agent.llm_response("What about Congo?")
63+
```
64+
65+
Finally, you can wrap an agent in a `Task` to run it in an interactive chat loop.
66+
Here's all you need to make a basic chat-bot using Langroid:
67+
```python
4668
task = lr.Task(agent, interactive=True)
4769
task.run()
4870
```
4971

5072
An example script showing a 2-agent assistant is included in this folder.
51-
The langroid repo has numerous example scripts as well, and you can run them
52-
against a groq-hosted LLM by changing `chat_model` to `groq/llama3-70b-8192` (as an
73+
The Langroid repo has numerous example scripts as well, and you can run them
74+
against a Groq-hosted LLM by changing `chat_model` to `groq/llama3-70b-8192` (as an
5375
example). Many of the scripts also take a command-line argument `-m` to specify the
5476
model, e.g. `-m groq/llama3-70b-8192`.

langroid-llm-agents/search-assistant.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
Run like this:
1212
1313
python3 search-assistant.py
14+
15+
To run with a different Groq-hosted LLM, you can pass in the LLM via the MODEL env var:
16+
17+
MODEL=groq/<another_model> python3 search-assistant.py
1418
"""
1519

1620
from dotenv import load_dotenv
@@ -21,6 +25,7 @@
2125
import langroid.language_models as lm
2226
from langroid.agent.tools.duckduckgo_search_tool import DuckduckgoSearchTool
2327

28+
# can pass in this env var at the command line
2429
MODEL = "groq/llama3-70b-8192"
2530

2631
def main() -> None:

0 commit comments

Comments
 (0)