Add example to use any LLM

This commit is contained in:
Aymeric 2024-12-15 12:47:45 +01:00
parent 57b35337c2
commit b6fc583d96
1 changed files with 30 additions and 0 deletions

30
examples/use_any_llm.py Normal file
View File

@ -0,0 +1,30 @@
from agents import OpenAIEngine, AnthropicEngine, HfApiEngine, CodeAgent
from dotenv import load_dotenv
load_dotenv()
openai_engine = OpenAIEngine(model_name="gpt-4o")
agent = CodeAgent([], llm_engine=openai_engine)
print("\n\n##############")
print("Running OpenAI agent:")
agent.run("What is the 10th Fibonacci Number?")
anthropic_engine = AnthropicEngine()
agent = CodeAgent([], llm_engine=anthropic_engine)
print("\n\n##############")
print("Running Anthropic agent:")
agent.run("What is the 10th Fibonacci Number?")
# Here, our token stored as HF_TOKEN environment variable has accesses 'Make calls to the serverless Inference API' and 'Read access to contents of all public gated repos you can access'
llama_engine = HfApiEngine(model="meta-llama/Llama-3.3-70B-Instruct")
agent = CodeAgent([], llm_engine=llama_engine)
print("\n\n##############")
print("Running Llama3.3-70B agent:")
agent.run("What is the 10th Fibonacci Number?")