使用Groq调用Llama API时遭遇API Key未配置错误的求助
使用Groq调用Llama API时遭遇API Key未配置错误的求助
我最近在尝试通过Groq Cloud调用Llama API,但一直卡在API Key未配置的错误上,试了好几种方法都没解决,实在没办法来求助了!
我已经试过在命令行里设置环境变量:
- Windows 命令行下用
set GROQ_API_KEY=api_key - PowerShell 下用
$env:GROQ_API_KEY = "api_key"
但不管怎么操作,运行代码时还是会遇到相同的API Key未配置错误。下面是我完整的代码,麻烦各位帮我排查下问题出在哪?
from groq import Groq from dotenv import load_dotenv import os # Load environment variables from .env file load_dotenv() # Retrieve the API key from the environment variable api_key = os.getenv("MY_KEY") # Initialize the Groq client with the API key client = Groq(api_key=api_key) # Prompt the user for input user_input = input("Enter your message: ") # Define the message list with the user's input messages = [ {"role": "user", "content": user_input} ] # Create a chat completion request completion = client.chat.completions.create( model="llama-3.3-70b-versatile", messages=messages, temperature=1, max_completion_tokens=1310, top_p=1, stream=True, stop=None, ) # Stream and print the response for chunk in completion: print(chunk.choices[0].delta.content or "", end="")
备注:内容来源于stack exchange,提问作者electroboiii
相关产品推荐
相关产品推荐

