Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(client): resolve ToParams regression #310

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ if stream.Err() != nil {
_ = acc.Choices[0].Message.Content
```

> See the [full streaming and accumulation example]./examples/chat-completion-accumulating/main.go)
> See the [full streaming and accumulation example](./examples/chat-completion-accumulating/main.go)

</details>

Expand Down Expand Up @@ -202,7 +202,7 @@ for _, toolCall := range toolCalls {
// ... continue the conversation with the information provided by the tool
```

> See the [full tool calling example]./examples/chat-completion-tool-calling/main.go)
> See the [full tool calling example](./examples/chat-completion-tool-calling/main.go)

</details>

Expand Down Expand Up @@ -751,7 +751,8 @@ middleware has been applied.

## Microsoft Azure OpenAI

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.
To use this library with [Azure OpenAI]https://learn.microsoft.com/azure/ai-services/openai/overview),
use the option.RequestOption functions in the `azure` package.

```go
package main
Expand Down
21 changes: 14 additions & 7 deletions chatcompletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -1265,17 +1265,24 @@ func (r ChatCompletionMessage) ToParam() ChatCompletionMessageParamUnion {

func (r ChatCompletionMessage) ToAssistantMessageParam() ChatCompletionAssistantMessageParam {
var p ChatCompletionAssistantMessageParam
p.Content.OfString = toParam(r.Content, r.JSON.Content)
p.Refusal = toParam(r.Refusal, r.JSON.Refusal)
if r.JSON.Content.IsPresent() {
p.Content.OfString.Value = r.Content
}
if r.JSON.Refusal.IsPresent() {
p.Refusal = String(r.Refusal)
}
p.Audio.ID = r.Audio.ID
p.Role = r.Role
p.FunctionCall.Arguments = r.FunctionCall.Arguments
p.FunctionCall.Name = r.FunctionCall.Name
p.ToolCalls = make([]ChatCompletionMessageToolCallParam, len(r.ToolCalls))
for i, v := range r.ToolCalls {
p.ToolCalls[i].ID = v.ID
p.ToolCalls[i].Function.Arguments = v.Function.Arguments
p.ToolCalls[i].Function.Name = v.Function.Name

if len(r.ToolCalls) > 0 {
p.ToolCalls = make([]ChatCompletionMessageToolCallParam, len(r.ToolCalls))
for i, v := range r.ToolCalls {
p.ToolCalls[i].ID = v.ID
p.ToolCalls[i].Function.Arguments = v.Function.Arguments
p.ToolCalls[i].Function.Name = v.Function.Name
}
}
return p
}
Expand Down