From 1f527ffc50e3eed72248c3323bf0db3e7a54e061 Mon Sep 17 00:00:00 2001 From: "1808837298@qq.com" <1808837298@qq.com> Date: Tue, 11 Feb 2025 19:54:13 +0800 Subject: [PATCH] feat: enhance OpenAI request and response DTOs - Add `Prefix` and `ReasoningContent` fields to Message struct - Add getter and setter methods for `Prefix` - Make `ToolCall.ID` field optional (fix #749) --- dto/openai_request.go | 23 ++++++++++++++++++----- dto/openai_response.go | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/dto/openai_request.go b/dto/openai_request.go index 628b3dd2..0f6411bb 100644 --- a/dto/openai_request.go +++ b/dto/openai_request.go @@ -86,11 +86,13 @@ func (r GeneralOpenAIRequest) ParseInput() []string { } type Message struct { - Role string `json:"role"` - Content json.RawMessage `json:"content"` - Name *string `json:"name,omitempty"` - ToolCalls json.RawMessage `json:"tool_calls,omitempty"` - ToolCallId string `json:"tool_call_id,omitempty"` + Role string `json:"role"` + Content json.RawMessage `json:"content"` + Name *string `json:"name,omitempty"` + Prefix *bool `json:"prefix,omitempty"` + ReasoningContent string `json:"reasoning_content,omitempty"` + ToolCalls json.RawMessage `json:"tool_calls,omitempty"` + ToolCallId string `json:"tool_call_id,omitempty"` } type MediaContent struct { @@ -116,6 +118,17 @@ const ( ContentTypeInputAudio = "input_audio" ) +func (m *Message) GetPrefix() bool { + if m.Prefix == nil { + return false + } + return *m.Prefix +} + +func (m *Message) SetPrefix(prefix bool) { + m.Prefix = &prefix +} + func (m *Message) ParseToolCalls() []ToolCall { if m.ToolCalls == nil { return nil diff --git a/dto/openai_response.go b/dto/openai_response.go index 4b4a614e..2e0e2221 100644 --- a/dto/openai_response.go +++ b/dto/openai_response.go @@ -81,7 +81,7 @@ func (c *ChatCompletionsStreamResponseChoiceDelta) GetContentString() string { type ToolCall struct { // Index is not nil only in chat completion chunk object Index *int `json:"index,omitempty"` - ID string `json:"id"` + ID string `json:"id,omitempty"` Type any `json:"type"` Function FunctionCall `json:"function"` }