Generative AI

OPELAI-5 Modela-5 Model Developer Guide

In this lesson, we will examine new skills imported in the recent Opelai model, GPT-5. The renewal brings a few powerful features, including a young man's paramet, the calling of free work form, free language system (CFG), and less thought. We will look at what they do and how they use them to work. Look Full codes here.

Installing libraries

!pip install pandas openai

Finding the Opelai API key, visit and generate a new key. If you are a new user, you may need to add payment information and make a minimum payment of $ 5 to activate API access. Look Full codes here.

import os
from getpass import getpass
os.environ['OPENAI_API_KEY'] = getpass('Enter OpenAI API Key: ')

VERSION Parameter

Marbosity Parameter allows you to control how model answers are specified without changing your immediate.

  • It is low → short and short, small text.
  • Contents (default) → Balanced information and clarity.
  • Top → Most detailed, ready for definitions, AUGHTITS, or teaching. Look Full codes here.
from openai import OpenAI
import pandas as pd
from IPython.display import display

client = OpenAI()

question = "Write a poem about a detective and his first solve"

data = []

for verbosity in ["low", "medium", "high"]:
    response = client.responses.create(
        model="gpt-5-mini",
        input=question,
        text={"verbosity": verbosity}
    )

    # Extract text
    output_text = ""
    for item in response.output:
        if hasattr(item, "content"):
            for content in item.content:
                if hasattr(content, "text"):
                    output_text += content.text

    usage = response.usage
    data.append({
        "Verbosity": verbosity,
        "Sample Output": output_text,
        "Output Tokens": usage.output_tokens
    })
# Create DataFrame
df = pd.DataFrame(data)

# Display nicely with centered headers
pd.set_option('display.max_colwidth', None)
styled_df = df.style.set_table_styles(
    [
        {'selector': 'th', 'props': [('text-align', 'center')]},  # Center column headers
        {'selector': 'td', 'props': [('text-align', 'left')]}     # Left-align table cells
    ]
)

display(styled_df)

The output tokens are specifically measured with the vendaurire: low (731) → Medium (1017) → High (1263).

Free Driver of Form

Free form forms GPT-5 Submit payment of green texts – such as Python documents, SQL documents, SQL questions, or SQL regulations, or JSON Commands-specific in your Format is used in GPT-4. Look Full codes here.

This makes it easy to connect GPT-5 to external times such as:

  • Sandbox code (Python, C ++, Java, etc.)
  • SQL Details (Green Effects SQL directly)
  • Shell locations (Relevant results – Run Bash)
  • The generator prepared
from openai import OpenAI

client = OpenAI()

response = client.responses.create(
    model="gpt-5-mini",
    input="Please use the code_exec tool to calculate the cube of the number of vowels in the word 'pineapple'",
    text={"format": {"type": "text"}},
    tools=[
        {
            "type": "custom",
            "name": "code_exec",
            "description": "Executes arbitrary python code",
        }
    ]
)
print(response.output[1].input)

This release shows the GPT-5 code that produces the pypic code in the name Pineeapple, colored the cube of the figure, and prints both. Instead of returning the Organized item (such as GPT-4 Generally non-Toolbars), GPT-5 relies visible visible code. This makes it possible to feed the outcome directly during the Python performance without additional parsing.

GRAMMAR FREERACT-free (CFG)

Unlimited Grammar Program (CFG) a set of production rules describing the valid strings in the language. Each law is rewriting a chronic seal in terminals and / or other non-terminals, without subject to the surrounding claw.

The CFGS is useful when you want to press the model out of the system and therefore following the Syntax of the Syntal, Format, or other organized text – to formulate SQL, JSON, or code is always correct.

Comparison, we will use the same script using GPT-4 and GPT-5 with the same CFG to see that the models attached language rules and how different their effects are different. Look Full codes here.

from openai import OpenAI
import re

client = OpenAI()

email_regex = r"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,}$"

prompt = "Give me a valid email address for John Doe. It can be a dummy email"

# No grammar constraints -- model might give prose or invalid format
response = client.responses.create(
    model="gpt-4o",  # or earlier
    input=prompt
)

output = response.output_text.strip()
print("GPT Output:", output)
print("Valid?", bool(re.match(email_regex, output)))
from openai import OpenAI

client = OpenAI()

email_regex = r"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,}$"

prompt = "Give me a valid email address for John Doe. It can be a dummy email"

response = client.responses.create(
    model="gpt-5",  # grammar-constrained model
    input=prompt,
    text={"format": {"type": "text"}},
    tools=[
        {
            "type": "custom",
            "name": "email_grammar",
            "description": "Outputs a valid email address.",
            "format": {
                "type": "grammar",
                "syntax": "regex",
                "definition": email_regex
            }
        }
    ],
    parallel_tool_calls=False
)

print("GPT-5 Output:", response.output[1].input)

This example illustrates how GPT-5 can adhere closely in the specified format when using a state-owned language system.

With similar grammar laws, GPT-4 generates additional text around the email address (“Here the test email you can use to John Doe: [email protected]”), Which makes it unemployed in accordance with a solid need for formatting.

GPT-5, however, directly output [email protected]to match the language and transmission of language. This shows the advanced GPT-5 power following CFG issues accurately. Look Full codes here.

A little thinking

The small consultation mode works GPT-5 with very few items or no imaginary tokens, reducing the latency and has brought for a quick time.

Ready for decisive, lightweight activities such as:

  • Data release
  • Formatting
  • Brief rewrite
  • Simple separation

Because the model skips central measures, the answers are fast and short. If not specified, the funny consultation attempt in the medium. Look Full codes here.

import time
from openai import OpenAI

client = OpenAI()

prompt = "Classify the given number as odd or even. Return one word only."

start_time = time.time()  # Start timer

response = client.responses.create(
    model="gpt-5",
    input=[
        { "role": "developer", "content": prompt },
        { "role": "user", "content": "57" }
    ],
    reasoning={
        "effort": "minimal"  # Faster time-to-first-token
    },
)

latency = time.time() - start_time  # End timer

# Extract model's text output
output_text = ""
for item in response.output:
    if hasattr(item, "content"):
        for content in item.content:
            if hasattr(content, "text"):
                output_text += content.text

print("--------------------------------")
print("Output:", output_text)
print(f"Latency: {latency:.3f} seconds")


I am the student of the community engineering (2022) from Jamia Millia Islamia, New Delhi, and I am very interested in data science, especially neural networks and their application at various locations.

Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button