Comprehensive guide on integrating CrewAI with various Large Language Models (LLMs) using LiteLLM, including supported providers and configuration options.
gpt-4o-mini
model. This is determined by the OPENAI_MODEL_NAME
environment variable, which defaults to “gpt-4o-mini” if not set.
You can easily configure your agents to use a different model or provider as described in this guide.from crewai import Agent
# Using OpenAI's GPT-4
openai_agent = Agent(
role='OpenAI Expert',
goal='Provide insights using GPT-4',
backstory="An AI assistant powered by OpenAI's latest model.",
llm='gpt-4'
)
# Using Anthropic's Claude
claude_agent = Agent(
role='Anthropic Expert',
goal='Analyze data using Claude',
backstory="An AI assistant leveraging Anthropic's language model.",
llm='claude-2'
)
Parameter | Type | Description |
---|---|---|
model | str | The name of the model to use (e.g., “gpt-4”, “claude-2”) |
temperature | float | Controls randomness in output (0.0 to 1.0) |
max_tokens | int | Maximum number of tokens to generate |
top_p | float | Controls diversity of output (0.0 to 1.0) |
frequency_penalty | float | Penalizes new tokens based on their frequency in the text so far |
presence_penalty | float | Penalizes new tokens based on their presence in the text so far |
stop | str , List[str] | Sequence(s) to stop generation |
base_url | str | The base URL for the API endpoint |
api_key | str | Your API key for authentication |
import os
os.environ["OPENAI_API_KEY"] = "your-api-key"
os.environ["OPENAI_API_BASE"] = "https://api.your-provider.com/v1"
os.environ["OPENAI_MODEL_NAME"] = "your-model-name"
Download and install Ollama
Pull the desired model
ollama pull llama3.2
to download the model.Configure your agent
agent = Agent(
role='Local AI Expert',
goal='Process information using a local model',
backstory="An AI assistant running on local hardware.",
llm=LLM(model="ollama/llama3.2", base_url="http://localhost:11434")
)
base_url
parameter:
llm = LLM(
model="custom-model-name",
base_url="https://api.your-provider.com/v1",
api_key="your-api-key"
)
agent = Agent(llm=llm, ...)
Was this page helpful?