Просмотр исходного кода

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)
1808837298@qq.com 1 год назад
Родитель
Сommit
1f527ffc50
2 измененных файлов с 19 добавлено и 6 удалено
  1. 18 5
      dto/openai_request.go
  2. 1 1
      dto/openai_response.go

+ 18 - 5
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

+ 1 - 1
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"`
 }