Hi: Looking for help on following error:
Exception Traceback (most recent call last)
Cell In[5], line 1
----> 1 response_32 = llama32(messages, 90)
2 print(response_32)
File ~\Llama-3\L2\utils.py:35, in llama32(messages, model_size)
32 res = json.loads(requests.request(“POST”, url, headers=headers, data=json.dumps(payload)).content)
34 if ‘error’ in res:
—> 35 raise Exception(res[‘error’])
37 return res[‘choices’][0][‘message’][‘content’]
Exception: {‘message’: ‘Invalid API key provided. You can find your API key at https://api.together.xyz/settings/api-keys.’, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: ‘invalid_api_key’}
hi @alisq786
this part of the error is providing you website information where you can get your api keys as well as what to type once you click the link to get your api keys. So did you try?
Regards
DP
Thanks DP for your quick response appreciate it. With your guidance, I have generated my personal api.together_key. However not quite sure where I have to put it in utils.py file.
I assume, we have to put it in the following part:
def load_env():
_ = load_dotenv(find_dotenv())
The right API to pass in a prompt (of type string) is the completions API Create completion
The right API to pass in a messages (of type of list of message) is The chat completions API Create chat completion
Right?
and /or perhaps need to do something in following functions:
def llama32(messages, model_size=11):
def llama31(prompt_or_messages, model_size=8, temperature=0, raw=False, debug=False):
Plus do I need to generate sperate api_keys for following function:
def get_wolfram_alpha_api_key():
def get_tavily_api_key():
Looking for some specific help.
Thanks for being thire
do really need help with above quickly. thanks
first of all sorry @alisq786 for the delayed response.
Please go to File==>Open, then open the utils.py file. Here in the def llama32 section in the header section you will find together api key mentioned which you change with your api keys.
But highly recommend you to study the requirement.txt file first in detail as it provides all the details one needs to have in their local sytems for successful run of the codes as the dependencies version discrepancies can also cause error.
As far as I check the utils.py file, you do not require a separate api key, but let’s see. Change only the section where it mention the API.together_key
Regards
Dp
actually replaced ‘TOGETHER_API_KEY’ with my key under header section, however now getting following error:
Exception Traceback (most recent call last)
Cell In[5], line 1
----> 1 response_32 = llama32(messages, 90)
2 print(response_32)
File ~\DL_SC\Llama-3\L2\utils.py:36, in llama32(messages, model_size)
33 res = json.loads(requests.request(“POST”, url, headers=headers, data=json.dumps(payload)).content)
35 if ‘error’ in res:
—> 36 raise Exception(res[‘error’])
38 return res[‘choices’][0][‘message’][‘content’]
Exception: {‘message’: ‘Invalid API key provided. You can find your API key at https://api.together.xyz/settings/api-keys.’, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: ‘invalid_api_key’}
it’s the same error.
can I see how you changed the api keys @alisq786
As you suggested, following is the code peace that I changed with my key:
headers = {
“Accept”: “application/json”,
“Content-Type”: “application/json”,
#“Authorization”: f"Bearer {os.getenv(‘TOGETHER_API_KEY’)}"
“Authorization”: f"Bearer {os.getenv(‘e454bfd140d387*****************f1ddb3d7d56d5b40e9d3ff22af30be2’)}"
}
Note I put * in the key for security reasons.
Thanks for being there.
@alisq786
I don’t think that’s the right way,
Check here it is not totally same as the one you are looking but you will understand how you need to use your api keys in the utils.py file.
Thanks DP for quick response, greatly appreciate it 
Now I am getting following error: Please help
Thanks
@alisq786
which error? your image is not loaded properly
Thought DP sharing the following code snippet from utils.py file may help you conclude better. May their is issue in def load_env(): function as well. please check.
Sorry to bother you again n again
Regards
A
The code below should be added to a util.py file
import requests
import json
from dotenv import load_dotenv, find_dotenv
import os
from wolframalpha import Client
def load_env():
_ = load_dotenv(find_dotenv())
The right API to pass in a prompt (of type string) is the completions API Create completion
The right API to pass in a messages (of type of list of message) is The chat completions API Create chat completion
def llama32(messages, model_size=11):
model = f"meta-llama/Llama-3.2-{model_size}B-Vision-Instruct-Turbo"
url = f"{os.getenv(‘DLAI_TOGETHER_API_BASE’, ‘https://api.together.xyz’)}/v1/chat/completions"
payload = {
“model”: model,
“max_tokens”: 4096,
“temperature”: 0.0,
“stop”: [“<|eot_id|>”,“<|eom_id|>”],
“messages”: messages
}
headers = {
“Accept”: “application/json”,
“Content-Type”: “application/json”,
#“Authorization”: f"Bearer {os.getenv(‘TOGETHER_API_KEY’)}"
“Authorization”: f"Bearer {os.getenv(TOGETHER_API_KEY = ‘e454bfd140d3877b46061c46c7a2032dbf1ddb3d7d56d5b40e9d3ff22af30be2’)}"
}
res = json.loads(requests.request(“POST”, url, headers=headers, data=json.dumps(payload)).content)
if ‘error’ in res:
raise Exception(res[‘error’])
return res[‘choices’][0][‘message’][‘content’]
Hi DP:
Any luck with my issue.
Thanks for being their.
Looking forward.
A
you got the same error as you are not using your together api key correctly.
I provided you link which provided you information on how to use your own api keys by def llama in the
here the changes needed to be done in the utils py file
Dear DP:
Sorry to keep bothering you again and again, however I’m still not seeing what am need to do in utils.py file as I have put my key here: “Authorization”: f"Bearer {os.getenv(TOGETHER_API_KEY = ‘6791bceae9a84078a110edc7*******84fbff7718bf52d1f36eca289b2e2a’)}"
I don’t understand what I need to do in the following part as you suggested:
url = f"{os.getenv(‘DLAI_TOGETHER_API_BASE’, ‘https://api.together.xyz’)}/v1/chat/completions
I am really feeling foolish. If it is not extra too much to ask for I could send my utils file to you to examine and suggest changes or alternatively perhaps you could share a utils.py file where you could put dummy keys and I’ll replace it with mine and explicitly highlight where I need to put my Together_api_key.
I assume I am doning some silly mistake or perhaps am overseeing something obvious.
In the end, I thank you for your patience and looking forward to finally overcome this issue with your kind help.
Kind regards,
A
| Deepti_Prasad Mentor/Moderator/Tester
November 15 |
you got the same error as you are not using your together api key correctly.
I provided you link which provided you information on how to use your own api keys by def llama in the
alisq786:
Vision-Instruct-Turbo"
url = f"{os.getenv(‘DLAI_TOGETHER_API_BASE’, ‘https://api.together.xyz’)}/v1/chat/completions
here the changes needed to be done in the utils py file