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

Chapter 4 Python Code - API Out of date #4

Open
danielithomas opened this issue Nov 13, 2024 · 0 comments
Open

Chapter 4 Python Code - API Out of date #4

danielithomas opened this issue Nov 13, 2024 · 0 comments

Comments

@danielithomas
Copy link

danielithomas commented Nov 13, 2024

Code does not follow the current way the current openai API operates:

response = openai.ChatCompletion.create(
    engine="gpt-3.5-turbo", # engine = "deployment_name".
    messages=[
        {"role": "system", "content": system_message},
        {"role": "user", "content": instructions},
    ]
)

#print(response)
print(response['choices'][0]['message']['content'])

Should change to something like:

gpt_model = "gpt-4o"
messages=[
    {"role": "system", "content": system_message},
    {"role": "user", "content": instructions},
]

response = client.chat.completions.create(
    model=gpt_model, 
    messages=messages,
    temperature=0
)

response_message = response.choices[0].message.content
print(response_message)

Credit to a combo of the OpenAI https://github.com/openai/openai-python and a few StackOverflow answers, namely https://stackoverflow.com/questions/77444332/openai-python-package-error-chatcompletion-object-is-not-subscriptable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant