MarkTechPost@AI 13小时前
A Developer’s Guide to OpenAI’s GPT-5 Model Capabilities
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文介绍了OpenAI最新模型GPT-5的四大新功能:Verbosity参数控制回复详细程度,Free-form Function Calling直接发送原始文本 payload,Context-Free Grammar (CFG)约束输出格式,以及Minimal Reasoning减少推理步骤提升速度。这些功能让GPT-5在细节控制、外部连接和效率方面更加强大,适用于多种开发场景。

📊 Verbosity参数:允许用户通过low、medium、high三个等级控制模型回复的详细程度,低等级输出简洁,高等级适合解释或教学,输出token数量随等级线性增长。

🔧 Free-form Function Calling:让GPT-5可直接发送Python脚本、SQL查询等原始文本payload到外部工具,无需JSON格式化,便于连接代码沙箱、数据库和shell环境。

📈 Context-Free Grammar (CFG):通过正则表达式等规则约束模型输出格式,确保SQL、JSON或代码的语法正确性,相比GPT-4在相同规则下输出更精准。

🚀 Minimal Reasoning:减少推理步骤以提升响应速度,特别适合数据提取、格式化等轻量级任务,默认中等推理级别,可显著缩短首次生成token的时间。

📈 Context-Free Grammar (CFG):通过正则表达式等规则约束模型输出格式,确保SQL、JSON或代码的语法正确性,相比GPT-4在相同规则下输出更精准。

In this tutorial, we’ll explore the new capabilities introduced in OpenAI’s latest model, GPT-5. The update brings several powerful features, including the Verbosity parameter, Free-form Function Calling, Context-Free Grammar (CFG), and Minimal Reasoning. We’ll look at what they do and how to use them in practice. Check out the Full Codes here.

Installing the libraries

!pip install pandas openai

To get an OpenAI API key, visit https://platform.openai.com/settings/organization/api-keys and generate a new key. If you’re a new user, you may need to add billing details and make a minimum payment of $5 to activate API access. Check out the Full Codes here.

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

Verbosity Parameter

The Verbosity parameter lets you control how detailed the model’s replies are without changing your prompt.

from openai import OpenAIimport pandas as pdfrom IPython.display import displayclient = 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 DataFramedf = pd.DataFrame(data)# Display nicely with centered headerspd.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 scale roughly linearly with verbosity: low (731) → medium (1017) → high (1263).

Free-Form Function Calling

Free-form function calling lets GPT-5 send raw text payloads—like Python scripts, SQL queries, or shell commands—directly to your tool, without the JSON formatting used in GPT-4. Check out the Full Codes here.

This makes it easier to connect GPT-5 to external runtimes such as:

from openai import OpenAIclient = 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 output shows GPT-5 generating raw Python code that counts the vowels in the word pineapple, calculates the cube of that count, and prints both values. Instead of returning a structured JSON object (like GPT-4 typically would for tool calls), GPT-5 delivers plain executable code. This makes it possible to feed the result directly into a Python runtime without extra parsing.

Context-Free Grammar (CFG)

A Context-Free Grammar (CFG) is a set of production rules that define valid strings in a language. Each rule rewrites a non-terminal symbol into terminals and/or other non-terminals, without depending on the surrounding context.

CFGs are useful when you want to strictly constrain the model’s output so it always follows the syntax of a programming language, data format, or other structured text — for example, ensuring generated SQL, JSON, or code is always syntactically correct.

For comparison, we’ll run the same script using GPT-4 and GPT-5 with an identical CFG to see how both models adhere to the grammar rules and how their outputs differ in accuracy and speed. Check out the Full Codes here.

from openai import OpenAIimport reclient = 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 formatresponse = 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 OpenAIclient = 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 shows how GPT-5 can adhere more closely to a specified format when using a Context-Free Grammar.

With the same grammar rules, GPT-4 produced extra text around the email address (“Sure, here’s a test email you can use for John Doe: johndoe@example.com”), which makes it invalid according to the strict format requirement.

GPT-5, however, output exactly john.doe@example.com, matching the grammar and passing validation. This demonstrates GPT-5’s improved ability to follow CFG constraints precisely. Check out the Full Codes here.

Minimal Reasoning

Minimal reasoning mode runs GPT-5 with very few or no reasoning tokens, reducing latency and delivering a faster time-to-first-token.

It’s ideal for deterministic, lightweight tasks such as:

Because the model skips most intermediate reasoning steps, responses are quick and concise. If not specified, the reasoning effort defaults to medium. Check out the Full Codes here.

import timefrom openai import OpenAIclient = OpenAI()prompt = "Classify the given number as odd or even. Return one word only."start_time = time.time()  # Start timerresponse = 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 outputoutput_text = ""for item in response.output:    if hasattr(item, "content"):        for content in item.content:            if hasattr(content, "text"):                output_text += content.textprint("--------------------------------")print("Output:", output_text)print(f"Latency: {latency:.3f} seconds")

Check out the Full Codes here. Feel free to check out our GitHub Page for Tutorials, Codes and Notebooks. Also, feel free to follow us on Twitter and don’t forget to join our 100k+ ML SubReddit and Subscribe to our Newsletter.

The post A Developer’s Guide to OpenAI’s GPT-5 Model Capabilities appeared first on MarkTechPost.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

GPT-5 OpenAI AI功能
相关文章