题意:
when i am using langchain chat openai model and invoking method it's working but when using in crewai same llm models it gives invalid api key
当你提到在使用 langchain
的 chatopenai
模型并调用方法时一切正常,但在 crewai
中使用相同的 LLM(大型语言模型)模型时却收到“无效的 API 密钥”错误
问题背景:
import os
from langchain_openai import OpenAI
from langchain_openai import ChatOpenAI
from langchain.prompts import PromptTemplatechat_model = ChatOpenAI( openai_api_base = "https://integrate.api.nvidia.com/v1",model_name="meta/llama3-70b-instruct",openai_api_key = "api key",streaming=True) question = "What is the meaning of life?"answer = chat_model.invoke(question)
print(question)
print(answer)
when i am using above code it's working fine but when i am trying to user llm nvidea model with crew it gives me error
使用上述代码时一切正常,但当你尝试在 crew
(我猜测你指的是某种与AI或机器学习相关的平台或库,尽管这不是一个广泛认知的标准名称)中使用NVIDIA的LLM(大型语言模型)时遇到错误
from crewai import Crew,Process
from agents import AiBlogCreationAgent
from tasks import AiBlogCreationTasks
from langchain_openai import ChatOpenAI
import os
from blog_io import save_blog
from dotenv import load_dotenvload_dotenv()
print(os.environ['OPENAI_API_KEY'])
print(os.environ['SERPER_API_KEY'])
agents=AiBlogCreationAgent()
tasks=AiBlogCreationTasks()llm = ChatOpenAI(model = "meta/llama3-70b-instruct",base_url = "https://integrate.api.nvidia.com/v1",streaming=True)editor=agents.editor_agent()
blog_fetcher=agents.blog_fetch_agent()
blog_analyzer=agents.blog_analyzer_agent()
blog_complier=agents.blog_compiler_agent()fetched_blog_task=tasks.fetch_blog_task(blog_fetcher)
analyzed_blog_task=tasks.analyze_blog_task(blog_analyzer,[fetched_blog_task])
compiled_blog_task=tasks.compile_blog_task(blog_complier,[analyzed_blog_task],save_blog)crew=Crew(agents=[editor,blog_fetcher,blog_analyzer,blog_complier],tasks=[fetched_blog_task,analyzed_blog_task,compiled_blog_task],process=Process.hierarchical,manager_llm=llm,memory=True,
)results=crew.kickoff()print(results)
error:I encountered an error while trying to use the tool. This was the error:
我尝试使用工具时遇到了一个错误。这是错误信息:
Error code: 401 - {'error': {'message': 'Incorrect API key provided: nvapi-Jz**********************************************************mNs7. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}.
What's the solution for it 解决方案是什么呢
问题解决:
You are using an URL for nvidia, not OpenAI, use the expanded ChatOpenAI and replace with your Nvidia Key?
你正在使用针对NVIDIA的URL,而不是OpenAI的。请使用扩展的ChatOpenAI并将你的NVIDIA密钥替换进去
llm = ChatOpenAI(
api_key=api_key
model = "meta/llama3-70b-instruct",
base_url = "https://integrate.api.nvidia.com/v1",
streaming=True)