Added some of Drew's suggestions

This commit is contained in:
Zachary Lee 2024-12-07 14:44:37 -05:00
commit 94ac97a07a
No known key found for this signature in database

View file

@ -63,21 +63,21 @@ pip install mcp anthropic python-dotenv
You'll need an Anthropic API key, which you can get from the [Anthropic Console](https://console.anthropic.com/settings/keys). You'll need an Anthropic API key, which you can get from the [Anthropic Console](https://console.anthropic.com/settings/keys).
After you've gotten your key, create a `.env.local` file to store it securely. After you've gotten your key, create a `.env` file to store it securely.
```bash ```bash
# Creates the .env.local file # Creates the .env file
touch .env.local touch .env
``` ```
```bash .env.local ```bash .env
ANTHROPIC_API_KEY=<your key here> ANTHROPIC_API_KEY=<your key here>
``` ```
```bash .gitignore ```bash .gitignore
# Make sure to add your .env key to your .gitignore to exclude it from source control! # Make sure to add your .env key to your .gitignore to exclude it from source control!
.env.local .env
``` ```
@ -201,10 +201,11 @@ class ClaudeCLIChatbot:
final_text.append(f"[Calling tool {tool_name} with args {tool_args}]") final_text.append(f"[Calling tool {tool_name} with args {tool_args}]")
# Continue conversation with tool results # Continue conversation with tool results
messages.append({ if hasattr(content, 'text') and content.text:
"role": "assistant", messages.append({
"content": content.text if hasattr(content, 'text') else '' "role": "assistant",
}) "content": content.text
})
messages.append({ messages.append({
"role": "user", "role": "user",
"content": result.content "content": result.content
@ -363,10 +364,11 @@ class ClaudeCLIChatbot:
final_text.append(f"[Calling tool {tool_name} with args {tool_args}]") final_text.append(f"[Calling tool {tool_name} with args {tool_args}]")
# Continue conversation with tool results # Continue conversation with tool results
messages.append({ if hasattr(content, 'text') and content.text:
"role": "assistant", messages.append({
"content": content.text if hasattr(content, 'text') else '' "role": "assistant",
}) "content": content.text
})
messages.append({ messages.append({
"role": "user", "role": "user",
"content": result.content "content": result.content
@ -570,7 +572,7 @@ The server code consists of three main parts:
``` ```
mcp-quickstart/ mcp-quickstart/
├── /venv ├── /venv
├── .env.local ├── .env
├── client.py ├── client.py
└── server.py └── server.py
``` ```
@ -582,8 +584,8 @@ python client.py server.py
3. You can now ask questions like: 3. You can now ask questions like:
``` ```
What time is it in Tokyo?
What time is it in New York? What time is it in New York?
What time was it an hour ago in Sydney?
Convert 3:30 PM PST to EST Convert 3:30 PM PST to EST
When it's 9 AM in London, what time is it in Sydney? When it's 9 AM in London, what time is it in Sydney?
``` ```