This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from moeakwak/main
support multimodal_text content and attachments
- Loading branch information
Showing
2 changed files
with
30 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,36 @@ | ||
package imitate | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func ConvertToString(chatgptResponse *ChatGPTResponse, previousText *StringStruct, role bool, id string, model string) string { | ||
text := strings.ReplaceAll(chatgptResponse.Message.Content.Parts[0], *&previousText.Text, "") | ||
var text string | ||
|
||
if len(chatgptResponse.Message.Content.Parts) == 1 { | ||
if part, ok := chatgptResponse.Message.Content.Parts[0].(string); ok { | ||
text = strings.ReplaceAll(part, previousText.Text, "") | ||
previousText.Text = part | ||
} else { | ||
text = fmt.Sprintf("%v", chatgptResponse.Message.Content.Parts[0]) | ||
} | ||
} else { | ||
// When using GPT-4 messages with images (multimodal_text), the length of 'parts' might be 2. | ||
// Since the chatgpt API currently does not support multimodal content | ||
// and there is no official format for multimodal content, | ||
// the content is temporarily returned as is. | ||
var parts []string | ||
for _, part := range chatgptResponse.Message.Content.Parts { | ||
parts = append(parts, fmt.Sprintf("%v", part)) | ||
} | ||
text = strings.Join(parts, ", ") | ||
} | ||
|
||
translatedResponse := NewChatCompletionChunk(text, id, model) | ||
if role { | ||
translatedResponse.Choices[0].Delta.Role = chatgptResponse.Message.Author.Role | ||
} | ||
previousText.Text = chatgptResponse.Message.Content.Parts[0] | ||
|
||
return "data: " + translatedResponse.String() + "\n\n" | ||
} |