Skip to content

Commit d01cf6d

Browse files
author
Andy
committed
feat: Update the usage method of the api_key and place the api_key in the environment variables.
1 parent e1823e9 commit d01cf6d

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

examples/travel_planner/README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,36 @@
44
55
## Getting started
66

7-
1. Install the dependencies
7+
1. update [config.json](config.json) with your own OpenAI API key etc.
8+
> You need to modify the values corresponding to model_name and base_url.
9+
10+
```json
11+
12+
{
13+
"model_name":"qwen3-32b",
14+
"api_key": "API_KEY",
15+
"base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1"
16+
}
17+
```
18+
2. Create an environment file with your API key:
19+
> You need to set the value corresponding to API_KEY.
20+
21+
```bash
22+
echo "API_KEY=your_api_key_here" > .env
23+
```
24+
25+
3. Install the dependencies
826
```bash
927
cd ~/a2a-python/
1028
pip install .
1129
```
1230

13-
2. Start the server
31+
4. Start the server
1432
```bash
1533
uv run .
1634
```
1735

18-
3. Run the test client
36+
5. Run the test client
1937
```bash
2038
uv run loop_client.py
2139
```

examples/travel_planner/agent.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from langchain_openai import ChatOpenAI
22
from langchain_core.messages import HumanMessage, SystemMessage
3-
import json,asyncio
3+
import json
4+
import sys
5+
import os
6+
47
from collections.abc import AsyncGenerator
58

69
class TravelPlannerAgent:
@@ -11,10 +14,14 @@ def __init__(self):
1114
try:
1215
with open("config.json") as f:
1316
config = json.load(f)
17+
if not os.getenv(config["api_key"]):
18+
print(f'{config["api_key"]} environment variable not set.')
19+
sys.exit(1)
20+
api_key = os.getenv(config["api_key"])
1421
self.model = ChatOpenAI(
1522
model=config["model_name"],
1623
base_url=config["base_url"],
17-
api_key=config["api_key"],
24+
api_key=api_key,
1825
temperature=0.7 # Control the generation randomness (0-2, higher values indicate greater randomness)
1926
)
2027
except FileNotFoundError:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"model_name":"qwen3-32b",
3-
"api_key": "sk-74e8a7c32e2741ff892844597dcc31c1",
3+
"api_key": "API_KEY",
44
"base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1"
55
}

0 commit comments

Comments
 (0)