OpenAI

Python OpenAI Chat Completion

Learn how to create chat completions using OpenAI models in Python. This guide covers setting up a client, sending user and system role messages, specifying a token limit, handling the API call, and printing the response content for seamless integration.

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.

Python code

# Python code will be here

Code explanation

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

OpenAI cookbook

Code recipes from OpenAI cookbook.