Гнучкість введення та мультимодальність

Робота з OpenAI Responses API

James Chapman

AI Curriculum Manager, DataCamp

Гнучкість введення

Підказки як рядки

response = client.responses.create(
    model="gpt-5.4-mini"
    input="How old is the Earth?",
    instructions="Answer concisely."
)
  • input → введення користувача
  • instructions → поведінка + вимоги

Підказки за ролями

response = client.responses.create(
    model="gpt-5.4-mini"
    input=[
        {"role": "system",
         "content": "Answer concisely."},
        {"role": "user",
         "content": "How old is the Earth?"}
    ]
)
Робота з OpenAI Responses API

Повідомлення з ролями

response = client.responses.create(
    model="gpt-5.4-mini"
    input=[
        {"role": "system", "content": "Answer concisely."},

{"role": "user", "content": "How old is the Sun?"},
{"role": "assistant", "content": "4.603 billion years"},
{"role": "user", "content": "How old is the Earth?"}
] )
Робота з OpenAI Responses API
sys_prompt = "You are a helpful Teacher who provides concise, personalized explanations."
latest_response_id = None 

while True:
    user_input = input("You: ").strip()
    if user_input.lower() == "exit":
        break

    response = client.responses.create(
        model="gpt-5.4-mini",
        instructions=sys_prompt,
        input=user_input,
        previous_response_id=latest_response_id
    )

    print(f"\nAssistant: {response.output_text}\n")
    latest_response_id = response.id
Робота з OpenAI Responses API
messages = [{"role": "system"},
            {"content": "You are a helpful Teacher who provides concise, personalized explanations."}]


while True: user_input = input("You: ").strip() if user_input.lower() == "exit": break messages.append({"role": "user", "content": user_input})
response = client.responses.create( model="gpt-5.4-mini", input=messages )
print(f"\nAssistant: {response.output_text}\n") messages.append({"role": "assistant", "content": response.output_text})
Робота з OpenAI Responses API

Зображення у підказках!

  • Мультимодальність: взаємодія через кілька типів контенту

Графік акцій AAPL з yahoo!finance

1 Графік акцій Apple, Inc. з yahoo!finance
Робота з OpenAI Responses API

URL зображень у підказках

response = client.responses.create(
    model="gpt-5.4-mini",
    input=[

{"role": "user", "content": [ {"type": "input_text", "text": "Briefly interpret this stock plot."}, {"type": "input_image", "image_url": "https://...stock_performance.jpg"}]}
] )
print(response.output_text)
Робота з OpenAI Responses API

URL зображень у підказках

- Висновок: Помірне зниження дня — закриття на
277.18, приблизно −0.26% від попереднього
закриття; після закриття трохи знизилось до
276.94.

Графік акцій AAPL з yahoo!finance

1 Графік акцій Apple, Inc. з yahoo!finance
Робота з OpenAI Responses API

Зображення з локальних файлів

import base64
# Encode binary data as ASCII text characters
with open(image_path, "rb") as f:
    image_base64 = base64.b64encode(f.read()).decode("utf-8")
response = client.responses.create(
    model="gpt-5.4-mini",
    input=[
        {"role": "user", "content": [
          {"type": "input_text", "text": "Briefly interpret this stock plot."},

{"type": "input_image", "image_url": f"data:image/jpeg;base64,{image_base64}"}]}
] )
Робота з OpenAI Responses API

Давайте потренуємось!

Робота з OpenAI Responses API

Preparing Video For Download...