Skip to content

Commit 8b0fc2a

Browse files
committed
Merge commit '2fdcbb423bb60a63c973e9ed91ec3d095d8ff05a' into minh/realtime_prompting_guide
2 parents 4fb5681 + 2fdcbb4 commit 8b0fc2a

File tree

11 files changed

+1316
-56
lines changed

11 files changed

+1316
-56
lines changed

articles/gpt-oss/fine-tune-korean.ipynb

Lines changed: 1196 additions & 0 deletions
Large diffs are not rendered by default.
File renamed without changes.

articles/openai-harmony.md

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The [`gpt-oss` models](https://openai.com/open-models) were trained on the harmo
66

77
### Roles
88

9-
Every message that the model processes has a role associated with it. The model knows about three types of roles:
9+
Every message that the model processes has a role associated with it. The model knows about five types of roles:
1010

1111
| Role | Purpose |
1212
| :---------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -52,24 +52,15 @@ encoding = load_harmony_encoding(HarmonyEncodingName.HARMONY_GPT_OSS)
5252

5353
system_message = (
5454
SystemContent.new()
55-
.with_model_identity(
56-
"You are ChatGPT, a large language model trained by OpenAI."
57-
)
5855
.with_reasoning_effort(ReasoningEffort.HIGH)
5956
.with_conversation_start_date("2025-06-28")
60-
.with_knowledge_cutoff("2024-06")
61-
.with_required_channels(["analysis", "commentary", "final"])
6257
)
6358

6459
developer_message = (
6560
DeveloperContent.new()
6661
.with_instructions("Always respond in riddles")
6762
.with_function_tools(
6863
[
69-
ToolDescription.new(
70-
"get_location",
71-
"Gets the location of the user.",
72-
),
7364
ToolDescription.new(
7465
"get_current_weather",
7566
"Gets the current weather in the provided location.",
@@ -90,7 +81,7 @@ developer_message = (
9081
},
9182
),
9283
]
93-
)
84+
)
9485
)
9586

9687
convo = Conversation.from_messages(
@@ -100,16 +91,16 @@ convo = Conversation.from_messages(
10091
Message.from_role_and_content(Role.USER, "What is the weather in Tokyo?"),
10192
Message.from_role_and_content(
10293
Role.ASSISTANT,
103-
'User asks: "What is the weather in Tokyo?" We need to use get_weather tool.',
94+
'User asks: "What is the weather in Tokyo?" We need to use get_current_weather tool.',
10495
).with_channel("analysis"),
10596
Message.from_role_and_content(Role.ASSISTANT, '{"location": "Tokyo"}')
10697
.with_channel("commentary")
107-
.with_recipient("functions.get_weather")
108-
.with_content_type("json"),
98+
.with_recipient("functions.get_current_weather")
99+
.with_content_type("<|constrain|> json"),
109100
Message.from_author_and_content(
110-
Author.new(Role.TOOL, "functions.lookup_weather"),
101+
Author.new(Role.TOOL, "functions.get_current_weather"),
111102
'{ "temperature": 20, "sunny": true }',
112-
).with_recipient("assistant").with_channel("commentary"),
103+
).with_channel("commentary"),
113104
]
114105
)
115106

@@ -202,6 +193,8 @@ Once its done generating it will stop with either a `<|return|>` token indicatin
202193

203194
The `final` channel will contain the answer to your user’s request. Check out the [reasoning section](#reasoning) for more details on the chain-of-thought.
204195

196+
**Implementation note:** `<|return|>` is a decode-time stop token only. When you add the assistant’s generated reply to conversation history for the next turn, replace the trailing `<|return|>` with `<|end|>` so that stored messages are fully formed as `<|start|>{header}<|message|>{content}<|end|>`. Prior messages in prompts should therefore end with `<|end|>`. For supervised targets/training examples, ending with `<|return|>` is appropriate; for persisted history, normalize to `<|end|>`.
197+
205198
### System message format
206199

207200
The system message is used to provide general information to the system. This is different to what might be considered the “system prompt” in other prompt formats. For that, check out the [developer message format](#developer-message-format).
@@ -383,7 +376,7 @@ If the model decides to call a tool it will define a `recipient` in the header o
383376
The model might also specify a `<|constrain|>` token to indicate the type of input for the tool call. In this case since it’s being passed in as JSON the `<|constrain|>` is set to `json`.
384377

385378
```
386-
<|channel|>analysis<|message|>Need to use function get_weather.<|end|><|start|>assistant<|channel|>commentary to=functions.get_weather <|constrain|>json<|message|>{"location":"San Francisco"}<|call|>
379+
<|channel|>analysis<|message|>Need to use function get_current_weather.<|end|><|start|>assistant<|channel|>commentary to=functions.get_current_weather <|constrain|>json<|message|>{"location":"San Francisco"}<|call|>
387380
```
388381

389382
#### Handling tool calls
@@ -399,7 +392,7 @@ A tool message has the following format:
399392
So in our example above
400393

401394
```
402-
<|start|>functions.get_weather to=assistant<|channel|>commentary<|message|>{"sunny": true, "temperature": 20}<|end|>
395+
<|start|>functions.get_current_weather to=assistant<|channel|>commentary<|message|>{"sunny": true, "temperature": 20}<|end|>
403396
```
404397

405398
Once you have gathered the output for the tool calls you can run inference with the complete content:
@@ -439,10 +432,10 @@ locations: string[],
439432
format?: "celsius" | "fahrenheit", // default: celsius
440433
}) => any;
441434
442-
} // namespace functions<|end|><|start|>user<|message|>What is the weather like in SF?<|end|><|start|>assistant<|channel|>analysis<|message|>Need to use function get_weather.<|end|><|start|>assistant<|channel|>commentary to=functions.get_weather <|constrain|>json<|message|>{"location":"San Francisco"}<|call|><|start|>functions.get_weather to=assistant<|channel|>commentary<|message|>{"sunny": true, "temperature": 20}<|end|><|start|>assistant
435+
} // namespace functions<|end|><|start|>user<|message|>What is the weather like in SF?<|end|><|start|>assistant<|channel|>analysis<|message|>Need to use function get_current_weather.<|end|><|start|>assistant<|channel|>commentary to=functions.get_current_weather <|constrain|>json<|message|>{"location":"San Francisco"}<|call|><|start|>functions.get_current_weather to=assistant<|channel|>commentary<|message|>{"sunny": true, "temperature": 20}<|end|><|start|>assistant
443436
```
444437

445-
As you can see above we are passing not just the function out back into the model for further sampling but also the previous chain-of-thought (“Need to use function get_weather.”) to provide the model with the necessary information to continue its chain-of-thought or provide the final answer.
438+
As you can see above we are passing not just the function out back into the model for further sampling but also the previous chain-of-thought (“Need to use function get_current_weather.”) to provide the model with the necessary information to continue its chain-of-thought or provide the final answer.
446439

447440
#### Preambles
448441

authors.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,3 +461,8 @@ hendrytl:
461461
name: "Todd Hendry"
462462
website: "https://www.linkedin.com/in/todd-hendry-962aa577/"
463463
avatar: "https://avatars.githubusercontent.com/u/36863669"
464+
465+
heejingithub:
466+
name: "Heejin Cho"
467+
website: "https://www.linkedin.com/in/heejc/"
468+
avatar: "https://avatars.githubusercontent.com/u/169293861"

examples/How_to_call_functions_with_chat_models.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
},
5252
{
5353
"cell_type": "code",
54-
"execution_count": 2,
54+
"execution_count": null,
5555
"id": "dab872c5",
5656
"metadata": {
5757
"ExecuteTime": {
@@ -66,7 +66,7 @@
6666
"from tenacity import retry, wait_random_exponential, stop_after_attempt\n",
6767
"from termcolor import colored \n",
6868
"\n",
69-
"GPT_MODEL = \"gpt-4o\"\n",
69+
"GPT_MODEL = \"gpt-5\"\n",
7070
"client = OpenAI()"
7171
]
7272
},
@@ -515,7 +515,7 @@
515515
"source": [
516516
"### Parallel Function Calling\n",
517517
"\n",
518-
"Newer models such as gpt-4o or gpt-3.5-turbo can call multiple functions in one turn."
518+
"Newer models such as gpt-5, gpt-4.1 or gpt-4o can call multiple functions in one turn."
519519
]
520520
},
521521
{
@@ -758,7 +758,7 @@
758758
"source": [
759759
"##### Steps to invoke a function call using Chat Completions API: \n",
760760
"\n",
761-
"**Step 1**: Prompt the model with content that may result in model selecting a tool to use. The description of the tools such as a function names and signature is defined in the 'Tools' list and passed to the model in API call. If selected, the function name and parameters are included in the response.<br>\n",
761+
"**Step 1**: Prompt the model with content that may result in model selecting a tool to use. The description of the tools such as a function name and signature is defined in the 'Tools' list and passed to the model in API call. If selected, the function name and parameters are included in the response.<br>\n",
762762
" \n",
763763
"**Step 2**: Check programmatically if model wanted to call a function. If true, proceed to step 3. <br> \n",
764764
"**Step 3**: Extract the function name and parameters from response, call the function with parameters. Append the result to messages. <br> \n",
@@ -767,7 +767,7 @@
767767
},
768768
{
769769
"cell_type": "code",
770-
"execution_count": 19,
770+
"execution_count": null,
771771
"id": "e8b7cb9cdc7a7616",
772772
"metadata": {
773773
"ExecuteTime": {
@@ -792,9 +792,9 @@
792792
"}]\n",
793793
"\n",
794794
"response = client.chat.completions.create(\n",
795-
" model='gpt-4o', \n",
795+
" model=GPT_MODEL, \n",
796796
" messages=messages, \n",
797-
" tools= tools, \n",
797+
" tools=tools, \n",
798798
" tool_choice=\"auto\"\n",
799799
")\n",
800800
"\n",
@@ -807,7 +807,7 @@
807807
},
808808
{
809809
"cell_type": "code",
810-
"execution_count": 20,
810+
"execution_count": null,
811811
"id": "351c39def3417776",
812812
"metadata": {
813813
"ExecuteTime": {
@@ -847,7 +847,7 @@
847847
" # Step 4: Invoke the chat completions API with the function response appended to the messages list\n",
848848
" # Note that messages with role 'tool' must be a response to a preceding message with 'tool_calls'\n",
849849
" model_response_with_function_call = client.chat.completions.create(\n",
850-
" model=\"gpt-4o\",\n",
850+
" model=GPT_MODEL,\n",
851851
" messages=messages,\n",
852852
" ) # get a new response from the model where it can see the function response\n",
853853
" print(model_response_with_function_call.choices[0].message.content)\n",

examples/api_request_parallel_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ async def process_api_requests_from_file(
253253
)
254254
await asyncio.sleep(remaining_seconds_to_pause)
255255
# ^e.g., if pause is 15 seconds and final limit was hit 5 seconds ago
256-
logging.warn(
256+
logging.warning(
257257
f"Pausing to cool down until {time.ctime(status_tracker.time_of_last_rate_limit_error + seconds_to_pause_after_rate_limit_error)}"
258258
)
259259

examples/chatgpt/gpt_actions_library/gpt_middleware_aws_function.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
"You can clone the openai-cookbook repository & take the sample python code & SAM template from the `lambda-middleware` directory:\n",
191191
"\n",
192192
"```\n",
193-
"git clone https://github.com/pap-openai/lambda-middleware\n",
193+
"git clone https://github.com/pap-openai/aws-lambda-middleware\n",
194194
"cd lambda-middleware\n",
195195
"```\n",
196196
"\n",

examples/codex/jira-github.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"\n",
1515
"This cookbook provides a practical, step-by-step approach to automating the workflow between Jira and GitHub. By labeling a Jira issue, you trigger an end-to-end process that creates a **GitHub pull request**, keeps both systems updated, and streamlines code review, all with minimal manual effort. The automation is powered by the [`codex-cli`](https://github.com/openai/openai-codex) agent running inside a GitHub Action.\n",
1616
"\n",
17-
"# <img src=\"../../images/codex_action.png\" alt=\"Full data-flow diagram\" width=\"500\"/>\n"
17+
"<img src=\"../../images/codex_action.png\" alt=\"Full data-flow diagram\" width=\"500\"/>\n"
1818
]
1919
},
2020
{

0 commit comments

Comments
 (0)