mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-17 17:16:38 +08:00
fix: update text handling to ensure nil checks and pointer usage for message content
This commit is contained in:
parent
34c7523f01
commit
d236477531
@ -159,7 +159,9 @@ func ConvertRequest(c *gin.Context, textRequest model.GeneralOpenAIRequest) (*Re
|
|||||||
var content Content
|
var content Content
|
||||||
if part.Type == model.ContentTypeText {
|
if part.Type == model.ContentTypeText {
|
||||||
content.Type = "text"
|
content.Type = "text"
|
||||||
content.Text = part.Text
|
if part.Text != nil {
|
||||||
|
content.Text = *part.Text
|
||||||
|
}
|
||||||
} else if part.Type == model.ContentTypeImageURL {
|
} else if part.Type == model.ContentTypeImageURL {
|
||||||
content.Type = "image"
|
content.Type = "image"
|
||||||
content.Source = &ImageSource{
|
content.Source = &ImageSource{
|
||||||
|
@ -20,7 +20,7 @@ var ModelsSupportSystemInstruction = []string{
|
|||||||
"gemini-2.0-flash", "gemini-2.0-flash-exp",
|
"gemini-2.0-flash", "gemini-2.0-flash-exp",
|
||||||
"gemini-2.0-flash-thinking-exp-01-21",
|
"gemini-2.0-flash-thinking-exp-01-21",
|
||||||
"gemini-2.0-flash-lite",
|
"gemini-2.0-flash-lite",
|
||||||
"gemini-2.0-flash-exp-image-generation",
|
// "gemini-2.0-flash-exp-image-generation",
|
||||||
"gemini-2.0-pro-exp-02-05",
|
"gemini-2.0-pro-exp-02-05",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,9 +109,9 @@ func ConvertRequest(textRequest model.GeneralOpenAIRequest) *ChatRequest {
|
|||||||
var parts []Part
|
var parts []Part
|
||||||
imageNum := 0
|
imageNum := 0
|
||||||
for _, part := range openaiContent {
|
for _, part := range openaiContent {
|
||||||
if part.Type == model.ContentTypeText {
|
if part.Type == model.ContentTypeText && part.Text != nil && *part.Text != "" {
|
||||||
parts = append(parts, Part{
|
parts = append(parts, Part{
|
||||||
Text: part.Text,
|
Text: *part.Text,
|
||||||
})
|
})
|
||||||
} else if part.Type == model.ContentTypeImageURL {
|
} else if part.Type == model.ContentTypeImageURL {
|
||||||
imageNum += 1
|
imageNum += 1
|
||||||
@ -276,7 +276,7 @@ func responseGeminiChat2OpenAI(response *ChatResponse) *openai.TextResponse {
|
|||||||
// Add to content items
|
// Add to content items
|
||||||
contentItems = append(contentItems, model.MessageContent{
|
contentItems = append(contentItems, model.MessageContent{
|
||||||
Type: model.ContentTypeText,
|
Type: model.ContentTypeText,
|
||||||
Text: part.Text,
|
Text: &part.Text,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,9 @@ func ConvertRequest(request model.GeneralOpenAIRequest) *ChatRequest {
|
|||||||
for _, part := range openaiContent {
|
for _, part := range openaiContent {
|
||||||
switch part.Type {
|
switch part.Type {
|
||||||
case model.ContentTypeText:
|
case model.ContentTypeText:
|
||||||
contentText = part.Text
|
if part.Text != nil {
|
||||||
|
contentText = *part.Text
|
||||||
|
}
|
||||||
case model.ContentTypeImageURL:
|
case model.ContentTypeImageURL:
|
||||||
_, data, _ := image.GetImageFromUrl(part.ImageURL.Url)
|
_, data, _ := image.GetImageFromUrl(part.ImageURL.Url)
|
||||||
imageUrls = append(imageUrls, data)
|
imageUrls = append(imageUrls, data)
|
||||||
|
@ -140,7 +140,7 @@ func (m Message) ParseContent() []MessageContent {
|
|||||||
if ok {
|
if ok {
|
||||||
contentList = append(contentList, MessageContent{
|
contentList = append(contentList, MessageContent{
|
||||||
Type: ContentTypeText,
|
Type: ContentTypeText,
|
||||||
Text: content,
|
Text: &content,
|
||||||
})
|
})
|
||||||
return contentList
|
return contentList
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ func (m Message) ParseContent() []MessageContent {
|
|||||||
if subStr, ok := contentMap["text"].(string); ok {
|
if subStr, ok := contentMap["text"].(string); ok {
|
||||||
contentList = append(contentList, MessageContent{
|
contentList = append(contentList, MessageContent{
|
||||||
Type: ContentTypeText,
|
Type: ContentTypeText,
|
||||||
Text: subStr,
|
Text: &subStr,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
case ContentTypeImageURL:
|
case ContentTypeImageURL:
|
||||||
@ -197,7 +197,7 @@ type ImageURL struct {
|
|||||||
type MessageContent struct {
|
type MessageContent struct {
|
||||||
// Type should be one of the following: text/input_audio
|
// Type should be one of the following: text/input_audio
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
Text string `json:"text"`
|
Text *string `json:"text,omitempty"`
|
||||||
ImageURL *ImageURL `json:"image_url,omitempty"`
|
ImageURL *ImageURL `json:"image_url,omitempty"`
|
||||||
InputAudio *InputAudio `json:"input_audio,omitempty"`
|
InputAudio *InputAudio `json:"input_audio,omitempty"`
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user