import os
from google.colab import userdata
os.environ["OPENAI_API_KEY"] = userdata.get('OPENAI_SECRET')
!pip install openai
from openai import OpenAI
client = OpenAI(
# Defaults to os.environ.get("OPENAI_API_KEY")
)
chat_completion = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello world"}]
)
print(chat_completion.choices[0].message.content)
# Hello! How can I assist you today?
from openai import OpenAI
client = OpenAI(
# Defaults to os.environ.get("OPENAI_API_KEY")
)
chat_completion = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You always put ^^ end of text"},
{"role": "user", "content": "Hello?"},
{"role": "assistant", "content": "Hi^^"},
{"role": "user", "content": "What is your name?"},
]
)
print(chat_completion.choices[0].message.content)
# I’m known as Assistant. How can I help you today?^^