You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Confirm this is an issue with the Python library and not an underlying OpenAI API
This is an issue with the Python library
Describe the bug
I run the code from docs but receive the error I find the cause of the bug is text load from .env have some special character.
from dotenv import load_dotenv
load_dotenv()
import os
openai.api_key = os.getenv("OPENAI_API_KEY")
and solved with
client = OpenAI(
api_key="sk...."
)
Seem have something weird when load .env file
My .env file is and I still use it for other code. But dont know this version receive error
I use new .venv of python 3.10.12 only install python-dotenv
To Reproduce
!pip install python-dotenv
!pip install openai
RUN the code snip set
I still can print print(u"\u201d")
Code snippets
importopenaifromopenaiimportOpenAIfromdotenvimportload_dotenvload_dotenv()
importosopenai.api_key=os.getenv("OPENAI_API_KEY")
client=OpenAI()
response=client.chat.completions.create(
model="gpt-3.5-turbo",
response_format={ "type": "json_object" },
messages=[
{"role": "system", "content": "You are 3translator to translate the input text to destination language the input is the text nees to translate. First: Detect the language of the input text Second: Translate the input text from the detected language in first step to the Vietnamese language Third: Return output only the translated text not add up the description"},
{"role": "user", "content": "this is a cat"},
]
)
OS
ubuntu 22.04.3
Python version
3.10.12
Library version
openai 1.2.3
The text was updated successfully, but these errors were encountered:
I'm not sure if you managed to fix your issue, but it seems to have been caused by the Right Double Quote being somewhere in your env file or in your code, which is quite a buggar to track down. I'm glad you figured it out!
I did notice on trying to run your code that it didn't work however, due to first the model type being used, then the lack of the word "JSON" in the query string. Here's the fixed version of it after the fact if you're still having issues:
importopenaifromopenaiimportOpenAIfromdotenvimportload_dotenvload_dotenv()
importosopenai.api_key=os.getenv("OPENAI_API_KEY")
client=OpenAI()
response=client.chat.completions.create(
model="gpt-3.5-turbo-1106",
response_format={ "type": "json_object" },
messages=[
{"role": "system", "content": "You are 3translator to translate the input text to destination language the input is the text nees to translate. First: Detect the language of the input text Second: Translate the input text from the detected language in first step to the Vietnamese language Third: Return output only the translated text not add up the description, and return it in JSON format."},
{"role": "user", "content": "this is a cat"},
]
)
print(response.choices[0].message.content)
Which produces:
$ python3 test.py
{
"translatedText": "đây là một con mèo"
}
If that's solved your problem, feel free to close this issue. Good luck with your project!
Uh oh!
There was an error while loading. Please reload this page.
Confirm this is an issue with the Python library and not an underlying OpenAI API
Describe the bug
I run the code from docs but receive the error
I find the cause of the bug is text load from .env have some special character.
and solved with
Seem have something weird when load .env file
My .env file is and I still use it for other code. But dont know this version receive error
I use new .venv of python 3.10.12 only install python-dotenv
To Reproduce
!pip install python-dotenv
!pip install openai
RUN the code snip set
I still can print
print(u"\u201d")
Code snippets
OS
ubuntu 22.04.3
Python version
3.10.12
Library version
openai 1.2.3
The text was updated successfully, but these errors were encountered: