OpenAI

OpenAI Chat Completions in Python Notebook

Learn to create a chat completion using OpenAI's API by setting up system, assistant, and user messages. This recipe details how to generate responses with token limits, choose specific AI models, and print results. Ideal for developers building chatbots and managing AI-driven conversations in Python.

Required packages

You need below packages to use the code generated by recipe. All packages are automatically installed in MLJAR Studio.

openai>=1.35.14

Interactive recipe

You can use below interactive recipe to generate code. This recipe is available in MLJAR Studio.

In the below recipe, we assume that you have following variables available in your notebook:

  • client (type OpenAI)

Python code

# Python code will be here

Code explanation

  1. Create chat completion.
  2. Get response and print it.