This API V1 thing, is it possible to get gpt-4o to give me correct code for calling the openai API or do I always have to run the openai migrate. This feels so incredibly stupid because chat gpt always gives me the wrong code or change the right code back to the wrong code. Is it supposed to be like this? Working in vscode with GitHub copilot constantly generating the wrong code for accessing the API is so tiring.
The pretrained knowledge cutoff of the AI model is October 2023 at the latest.
Version 1.0.0 of the API SDKs were released November 2023.
Thus no. Prompt the heck out of it, along with custom instructions for a programming assistant:
To receive non-working code for anything…
You’ll just need to go to the API reference on the sidebar of the forum, and ensure that you provide good Python usage information to the AI from the examples in the documentation. You can make that documentation part of a user message you continue to use for your programming pal.
Then: make that API-specific code an abstracted imported function or class file, so that the AI can’t see or damage it any more.
Real starter Python code
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": "You are a creative writer"
},
{
"role": "user",
"content": "Hi!" # This shows sending past turns again
}
{
"role": "assistant", # and the past AI response gives "memory"
"content": "Hello there! I’m your friendly creative writer bot."
}
{
"role": "user",
"content": "Produce a short poem. Subject: turtles."
}
],
temperature=.8, top_p=.8, max_completion_tokens=1000
)
print(response.choices[0].message.content)
Thank you! This helped me a lot. Thank you, thank you!
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.