Skip to content

Instantly share code, notes, and snippets.

@namgivu
Created March 3, 2024 20:44
Show Gist options
  • Save namgivu/e2e207dc5913e66ac605b684d6d95b1f to your computer and use it in GitHub Desktop.
Save namgivu/e2e207dc5913e66ac605b684d6d95b1f to your computer and use it in GitHub Desktop.
convert legacy ChatComplete syntax
# before
completions = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": prompt},
],
temperature=0.4,
max_tokens=999,
)
res = completions['choices'][0]['message']['content']
# after
completions = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": prompt},
],
temperature=0.4,
max_tokens=999,
)
res = completions.choices[0].message.content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment