Skip to content

Commit 4fba869

Browse files
fix(client): resolve ToParams regression (#311)
Resolve some regressions in the ChatCompletionMessage.ToParam() method. Elide nulls from assistant, when creating a follow up request. Elide empty tool calls. Also contains some documentation fixes. Co-authored-by: Jacob Zimmerman <[email protected]>
1 parent db4bd1f commit 4fba869

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ if stream.Err() != nil {
140140
_ = acc.Choices[0].Message.Content
141141
```
142142

143-
> See the [full streaming and accumulation example]./examples/chat-completion-accumulating/main.go)
143+
> See the [full streaming and accumulation example](./examples/chat-completion-accumulating/main.go)
144144
145145
</details>
146146

@@ -206,7 +206,7 @@ for _, toolCall := range toolCalls {
206206
// ... continue the conversation with the information provided by the tool
207207
```
208208

209-
> See the [full tool calling example]./examples/chat-completion-tool-calling/main.go)
209+
> See the [full tool calling example](./examples/chat-completion-tool-calling/main.go)
210210
211211
</details>
212212

@@ -755,7 +755,8 @@ middleware has been applied.
755755

756756
## Microsoft Azure OpenAI
757757

758-
To use this library with [Azure OpenAI]https://learn.microsoft.com/azure/ai-services/openai/overview), use the ption.RequestOption functions in the `azure` package.
758+
To use this library with [Azure OpenAI]https://learn.microsoft.com/azure/ai-services/openai/overview),
759+
use the option.RequestOption functions in the `azure` package.
759760

760761
```go
761762
package main

chatcompletion.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -1265,17 +1265,24 @@ func (r ChatCompletionMessage) ToParam() ChatCompletionMessageParamUnion {
12651265

12661266
func (r ChatCompletionMessage) ToAssistantMessageParam() ChatCompletionAssistantMessageParam {
12671267
var p ChatCompletionAssistantMessageParam
1268-
p.Content.OfString = toParam(r.Content, r.JSON.Content)
1269-
p.Refusal = toParam(r.Refusal, r.JSON.Refusal)
1268+
if r.JSON.Content.IsPresent() {
1269+
p.Content.OfString.Value = r.Content
1270+
}
1271+
if r.JSON.Refusal.IsPresent() {
1272+
p.Refusal = String(r.Refusal)
1273+
}
12701274
p.Audio.ID = r.Audio.ID
12711275
p.Role = r.Role
12721276
p.FunctionCall.Arguments = r.FunctionCall.Arguments
12731277
p.FunctionCall.Name = r.FunctionCall.Name
1274-
p.ToolCalls = make([]ChatCompletionMessageToolCallParam, len(r.ToolCalls))
1275-
for i, v := range r.ToolCalls {
1276-
p.ToolCalls[i].ID = v.ID
1277-
p.ToolCalls[i].Function.Arguments = v.Function.Arguments
1278-
p.ToolCalls[i].Function.Name = v.Function.Name
1278+
1279+
if len(r.ToolCalls) > 0 {
1280+
p.ToolCalls = make([]ChatCompletionMessageToolCallParam, len(r.ToolCalls))
1281+
for i, v := range r.ToolCalls {
1282+
p.ToolCalls[i].ID = v.ID
1283+
p.ToolCalls[i].Function.Arguments = v.Function.Arguments
1284+
p.ToolCalls[i].Function.Name = v.Function.Name
1285+
}
12791286
}
12801287
return p
12811288
}

0 commit comments

Comments
 (0)