如果您看到请求 OpenAI API 密钥但您尚未显式配置 OpenAI,那是因为 Agno 在多个地方默认使用 OpenAI 模型,包括:
- 在
Agent
中未指定时的默认模型
- 默认嵌入器是
OpenAIEmbedder
和 VectorDBs,除非另有指定
快速修复:配置不同的模型
最好显式指定代理的模型,否则它将默认为 OpenAIChat
。
例如,要使用 Google 的 Gemini 而不是 OpenAI:
from agno.agent import Agent, RunResponse
from agno.models.google import Gemini
agent = Agent(
model=Gemini(id="gemini-1.5-flash"),
markdown=True,
)
# 在终端中打印响应
agent.print_response("写一个两句的恐怖故事。")
有关配置不同模型提供商的更多详细信息,请查阅我们的模型文档
快速修复:配置不同的嵌入器
嵌入也是如此。如果您想使用不同的嵌入器而不是 OpenAIEmbedder
,请显式配置它。
例如,要将 Google 的 Gemini 用作嵌入器,请使用 GeminiEmbedder
:
from agno.agent import AgentKnowledge
from agno.vectordb.pgvector import PgVector
from agno.embedder.google import GeminiEmbedder
# 在数据库中嵌入句子
embeddings = GeminiEmbedder().get_embedding("敏捷的棕色狐狸跳过懒狗。")
# 打印嵌入及其维度
print(f"Embeddings: {embeddings[:5]}")
print(f"Dimensions: {len(embeddings)}")
# 在知识库中使用嵌入器
knowledge_base = AgentKnowledge(
vector_db=PgVector(
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
table_name="gemini_embeddings",
embedder=GeminiEmbedder(),
),
num_documents=2,
)
有关配置不同模型提供商的更多详细信息,请查阅我们的嵌入器文档
Responses are generated using AI and may contain mistakes.