import os
from langchain_openai import OpenAI
from langchain_openai import ChatOpenAI
from langchain.prompts import PromptTemplate
chat_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
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_dotenv
load_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?
llm = ChatOpenAI(
api_key=api_key
model = "meta/llama3-70b-instruct",
base_url = "https://integrate.api.nvidia.com/v1",
streaming=True)