File size: 3,220 Bytes
f802661
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# LLM Configuration Guide

This directory contains centralized LLM configuration for the CrewAI Data Analyst application.

## Quick Start

### 1. Choose Your LLM Provider

Set the `LLM_PROVIDER` environment variable (in Replit Secrets or `.env` file):

```bash
LLM_PROVIDER=groq  # Options: groq, openai, ollama, anthropic
```

### 2. Add Your API Key

Add the corresponding API key to Replit Secrets:

| Provider | API Key Variable | Get Key From |
|----------|-----------------|--------------|
| Groq (Default) | `GROQ_API_KEY` | https://console.groq.com/keys |
| OpenAI | `OPENAI_API_KEY` | https://platform.openai.com/api-keys |
| Anthropic | `ANTHROPIC_API_KEY` | https://console.anthropic.com/ |
| Ollama | `OLLAMA_BASE_URL` | http://localhost:11434 (local) |

### 3. Restart the Application

After changing providers, restart the workflow to apply changes.

## Supported Providers

### ๐Ÿš€ Groq (Recommended)
- **Model**: llama-3.3-70b-versatile
- **Speed**: Very fast
- **Cost**: Low
- **Best for**: Production use, fast responses

```bash
LLM_PROVIDER=groq
GROQ_API_KEY=gsk_...
```

### ๐Ÿค– OpenAI
- **Model**: gpt-4o-mini
- **Speed**: Fast
- **Cost**: Medium
- **Best for**: High-quality responses

```bash
LLM_PROVIDER=openai
OPENAI_API_KEY=sk-...
```

### ๐Ÿ  Ollama (Local)
- **Model**: llama3
- **Speed**: Depends on hardware
- **Cost**: Free (runs locally)
- **Best for**: Privacy, offline use

```bash
LLM_PROVIDER=ollama
OLLAMA_BASE_URL=http://localhost:11434
```

### ๐Ÿง  Anthropic Claude
- **Model**: claude-3-5-sonnet-20241022
- **Speed**: Fast
- **Cost**: Medium
- **Best for**: Complex reasoning tasks

```bash
LLM_PROVIDER=anthropic
ANTHROPIC_API_KEY=sk-ant-...
```

## How It Works

The `llm_config.py` file provides a centralized configuration system that:

1. **Reads environment variables** to determine which LLM provider to use
2. **Validates credentials** before initializing agents
3. **Returns standardized config** that works with all CrewAI agents
4. **Allows easy switching** between providers without code changes

### Code Example

All agents automatically use the centralized config:

```python
from crewai import Agent, LLM
from config.llm_config import get_llm_params

my_agent = Agent(
    name="My Agent",
    role="My Role",
    llm=LLM(**get_llm_params()),  # Automatically uses configured provider
    verbose=True
)
```

## Customizing Models

To use a different model for a specific provider, edit `config/llm_config.py`:

```python
GROQ_CONFIG = {
    "model": "groq/llama-3.1-8b-instant",  # Change this
    "api_key": os.getenv("GROQ_API_KEY"),
}
```

## Troubleshooting

### Error: "Invalid LLM provider"
- Check that `LLM_PROVIDER` is set to one of: groq, openai, ollama, anthropic

### Error: "API_KEY environment variable is not set"
- Make sure you've added the API key to Replit Secrets
- Restart the workflow after adding secrets

### Error: "Connection refused" (Ollama)
- Make sure Ollama is running locally
- Check that `OLLAMA_BASE_URL` points to the correct address

## Security Notes

- **Never commit API keys** to version control
- Always use Replit Secrets or environment variables
- The `.env.example` file is safe to commit (contains no real keys)