Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We have released a new major version of our SDK, and we recommend upgrading promptly. #1387

Closed
joeatheist5150 opened this issue May 1, 2024 · 0 comments

Comments

@joeatheist5150
Copy link

We have released a new major version of our SDK, and we recommend upgrading promptly.

Regarding this new sdk...

I'll admit it I'm a newb. I've been using ChatGPT to create a rather extensive app that has been working great. I took a break from the project and suddenly i could not get answers from the api. I installed wsl and ubuntu did the whole grit thing and still i am unable to resolve the errors in my code. GPT4 Turbo is of no help with the issue and despite my best efforts I've killed a couple of days work on the project effectively going in circles attempting to fix the issue. If there is anybody willing to take a look at my code and advise me on how I can get things going again, I would be most grateful...

Here is my code as is now

client = OpenAI()

Load environment variables from the .env file

load_dotenv()

Retrieve and set the API key from the .env file

OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')

Define the model to be used

model_id = "gpt-4-turbo-2024-04-09" # Replace with the correct model ID you are using

def chatgpt_conversation(conversation_log):
print("Debug - Sending message to OpenAI: ", conversation_log[-1]['content'])

headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {OPENAI_API_KEY}"
}
data = {
    "model": model_id,
    "messages": conversation_log,
    "temperature": 0.7
}

response = requests.post('https://api.openai.com/v1/chat/completions', json=data, headers=headers)

if response.status_code == 200:
    response_data = response.json()
    assistant_response = response_data['choices'][0]['message']['content'].strip()
    conversation_log.append({'role': 'assistant', 'content': assistant_response})
    print("Debug - Received response from GPT-4:", assistant_response)
else:
    error_message = f"Failed to get a valid response from OpenAI API: {response.text}"
    print("Debug - Error in communicating with GPT-4:", error_message)
    conversation_log.append({'role': 'assistant', 'content': error_message})

return conversation_log

Example usage

conversation_history = [
{'role': 'user', 'content': 'How may I help you?'},
{'role': 'user', 'content': 'Hi'}
]

updated_conversation = chatgpt_conversation(conversation_history)
print("Final conversation log:", updated_conversation)

For some reason it thinks part of my request contains json data and currently it does not need to send json data for the chatbot section of my app. there is another call by the "assessment portion" of my app that will need to compare text from a json file against user entered text to assess compliance.

Kind regards,

Eddie Van Halen

@rattrayalex rattrayalex closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants