Scrap Web supports various LangChain chat models. Here’s how to configure and use the most popular ones. The full list is available in the .
Model Recommendations
We have yet to test performance across all models. Currently, we recommend using GPT-4o. It achieves 89% accuracy on .
All models require their respective API keys. Make sure to set them in your environment variables before running the agent.
Supported Models
All LangChain chat models are supported. We will document the most popular ones here.
OpenAI
OpenAI’s GPT-4o models are recommended for best performance.
Copy
from langchain_openai import ChatOpenAI
from swift_web import Agent
# Initialize the model
llm = ChatOpenAI(
model="gpt-4o",
temperature=0.0,
)
# Create agent with the model
agent = Agent(
task="Your task here",
llm=llm
)
Required environment variables:
.envCopy
OPENAI_API_KEY=
Claude models provide excellent performance and can handle complex tasks well.
Copy
from langchain_anthropic import ChatAnthropic
from swift_web import Agent
# Initialize the model
llm = ChatAnthropic(
model_name="claude-3-sonnet-20240229",
temperature=0.0,
timeout=100, # Increase for complex tasks
)
# Create agent with the model
agent = Agent(
task="Your task here",
llm=llm
)
And add the variable:
.envCopy
ANTHROPIC_API_KEY=
If you’re using Azure OpenAI services, you can configure the model like this:
Copy
from langchain_openai import AzureChatOpenAI
from swift_web import Agent
from pydantic import SecretStr
import os
# Initialize the model
llm = AzureChatOpenAI(
model="gpt-4o",
api_version='2024-10-21',
azure_endpoint=os.getenv('AZURE_OPENAI_ENDPOINT', ''),
api_key=SecretStr(os.getenv('AZURE_OPENAI_KEY', '')),
)
# Create agent with the model
agent = Agent(
task="Your task here",
llm=llm
)