What I’m trying to do:
Use the ChatGPT API to request an answer to a question
What I’ve tried and what’s not working:
I tried including the openai package that’s loaded in Anvil, however I think it’s an outdated library (0.18.01) which does not support chat. I think the newer library 0.23.01 does… so I’m just using requests to hit the gpt-3.5-turbo model directly.
For some reason the error I’m getting indicates that something in my code is wrong… as I see in the error that the api endpoint url is truncated. I have a more complete api url with all the parameters but since I’m getting this invalid url error, I’m iteratively trying to identify the problem so with the code below I’m simply trying to authenticate to the API
Code Sample:
url = "https://api.openai.com/v1/chat/completions -H \"Authorization: Bearer " + key + "\""
response = requests.request("GET", url)
remedy = json.loads(response.text)
that is returning this error message (I’ve x’d out my api key):
{‘error’: {‘message’: ‘Invalid URL (GET /v1/chat/completions -H “Authorization: Bearer sk-xxxxxxxxxxxxxxxx”)’, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: None}}