Skip to content

Commit 7a42197

Browse files
committed
hook up open-ai "responses" api (text). tools are still unimplemented as well as other media types
1 parent 126a289 commit 7a42197

14 files changed

Lines changed: 1773 additions & 511 deletions

.golangci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
linters:
2+
disable:
3+
- unused
4+
- unusedfunc
5+
- unusedparams
6+
issues:
7+
exclude-rules:
8+
- linters:
9+
- unused
10+
text: "unused parameter"

aiprompts/openai-streaming-text.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
For **just text streaming**, you only need to handle these 3 core events:
2+
3+
## Essential Events
4+
5+
### 1. `response.created`
6+
7+
```json
8+
{
9+
"type": "response.created",
10+
"response": {
11+
"id": "resp_abc123",
12+
"created_at": 1640995200,
13+
"model": "gpt-5"
14+
}
15+
}
16+
```
17+
18+
**Purpose**: Initialize response tracking (like Anthropic's `message_start`)
19+
20+
### 2. `response.output_text.delta`
21+
22+
```json
23+
{
24+
"type": "response.output_text.delta",
25+
"item_id": "msg_abc123",
26+
"delta": "Hello, how can I"
27+
}
28+
```
29+
30+
**Purpose**: Stream text chunks (like Anthropic's `text_delta`)
31+
32+
### 3. `response.completed`
33+
34+
```json
35+
{
36+
"type": "response.completed",
37+
"response": {
38+
"usage": {
39+
"input_tokens": 100,
40+
"output_tokens": 200
41+
}
42+
}
43+
}
44+
```
45+
46+
**Purpose**: Finalize response (like Anthropic's `message_stop`)
47+
48+
## Optional but Recommended
49+
50+
### 4. `error`
51+
52+
```json
53+
{
54+
"type": "error",
55+
"code": "rate_limit_exceeded",
56+
"message": "Rate limit exceeded"
57+
}
58+
```
59+
60+
**Purpose**: Handle errors gracefully
61+
62+
---
63+
64+
That's it for basic text streaming! You can ignore all the `response.output_item.added/done`, tool calling, reasoning, and annotation events if you just want simple text responses.
65+
66+
Your Go implementation would be:
67+
68+
1. Parse SSE stream
69+
2. Switch on `event.type`
70+
3. Handle these 4 event types
71+
4. Accumulate text from `delta` fields
72+
5. Emit to your existing SSE handler
73+
74+
Much simpler than the full implementation.

0 commit comments

Comments
 (0)