minimax/minimax-m3 model, but you can replace it
with any supported model that outputs text.
Requirements
-
An API key. The code below assumes you set it
in an environment variable:
-
The
openaiPython package. You can install it with this command:
Generate a text response
Here’s how you can generate text from a prompt or conversation history.Stream a text response
Setstream=True to receive tokens as they are generated instead of waiting
for the full response.
Analyze an image
Some LLMs accept images, allowing them to generate a description or analysis of the image visual content. You can use any supported model that accepts image input and outputs text. To pass an image, add theimage_url attribute in the messages.content
object. The inner url attribute accepts either a publicly accessible URL or a
base64-encoded data URI (for example, data:image/jpeg;base64,...).
Notice that content is an array, allowing you to pass multiple images at
once.
Analyze a video
Some LLMs accept video input, allowing them to generate a description or analysis of the video’s visual content. You can use any supported model that accepts image input and outputs text. To pass a video, add thevideo_url attribute in the messages.content
object. The inner url attribute accepts either a publicly accessible URL or a
base64-encoded data URI (for example, data:video/mp4;base64,...).
Notice that content is an array, allowing you to pass multiple videos at
once, or even a combination of videos and images.