Last answered:

23 Jun 2024

Posted on:

20 May 2024

1

Code updated for the latest Openai version

Hi, I updated the code, Completion was giving me an error, this code is working at this moment, just in case you come across the same issue:

from openai import OpenAI
client = OpenAI(
    api_key=api_key)
def generate_text(prompt):
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[
            {
            "role": "user",
            "content": prompt,
            }
        ],
        max_tokens=10,
        temperature=0.7)
    return response.choices[0].message.content

also check out: openai-python

1 answers ( 0 marked as helpful)
Super learner
This user is a Super Learner. To become a Super Learner, you need to reach Level 8.
Posted on:

23 Jun 2024

0

You can either do this or downgrade to a previous version of openai (0.28.0) so you wouldnt loose your free credit on your account running the instructor code on latest version of openai . 

Submit an answer