snippets_py
Integration
New integration from credential
openai = yepcode.integration.openai('credential-slug')
New integration from plain authentication data
from openai import OpenAI
client = OpenAI(
api_key="your-openai-api-key"
)
Completions
Create completion
completion = openai.completions.create(
model="gpt-3.5-turbo",
prompt="Say this is a test",
max_tokens=7,
temperature=0
)
print(completion.choices[0].text)
Chat
Create chat completion
chat_completion = openai.chat.completions.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello World"}])
print(chat_completion.choices[0].message.content)
Models
List models
models = openai.models.list()
print(models)
Images
Create image
response = openai.images.generate(
prompt="A cute baby sea otter",
n=2,
size="256x256"
)
print(response)