Fix: parsing of content parts
This commit is contained in:
@@ -175,9 +175,16 @@ func (m *RoleMsg) ToText(i int) string {
|
|||||||
// For structured content, just take the text parts
|
// For structured content, just take the text parts
|
||||||
var textParts []string
|
var textParts []string
|
||||||
for _, part := range m.ContentParts {
|
for _, part := range m.ContentParts {
|
||||||
if partMap, ok := part.(map[string]any); ok {
|
switch p := part.(type) {
|
||||||
if partType, exists := partMap["type"]; exists && partType == "text" {
|
case TextContentPart:
|
||||||
if textVal, textExists := partMap["text"]; textExists {
|
if p.Type == "text" {
|
||||||
|
textParts = append(textParts, p.Text)
|
||||||
|
}
|
||||||
|
case ImageContentPart:
|
||||||
|
// skip images for text display
|
||||||
|
case map[string]any:
|
||||||
|
if partType, exists := p["type"]; exists && partType == "text" {
|
||||||
|
if textVal, textExists := p["text"]; textExists {
|
||||||
if textStr, isStr := textVal.(string); isStr {
|
if textStr, isStr := textVal.(string); isStr {
|
||||||
textParts = append(textParts, textStr)
|
textParts = append(textParts, textStr)
|
||||||
}
|
}
|
||||||
@@ -206,9 +213,16 @@ func (m *RoleMsg) ToPrompt() string {
|
|||||||
// For structured content, just take the text parts
|
// For structured content, just take the text parts
|
||||||
var textParts []string
|
var textParts []string
|
||||||
for _, part := range m.ContentParts {
|
for _, part := range m.ContentParts {
|
||||||
if partMap, ok := part.(map[string]any); ok {
|
switch p := part.(type) {
|
||||||
if partType, exists := partMap["type"]; exists && partType == "text" {
|
case TextContentPart:
|
||||||
if textVal, textExists := partMap["text"]; textExists {
|
if p.Type == "text" {
|
||||||
|
textParts = append(textParts, p.Text)
|
||||||
|
}
|
||||||
|
case ImageContentPart:
|
||||||
|
// skip images for text display
|
||||||
|
case map[string]any:
|
||||||
|
if partType, exists := p["type"]; exists && partType == "text" {
|
||||||
|
if textVal, textExists := p["text"]; textExists {
|
||||||
if textStr, isStr := textVal.(string); isStr {
|
if textStr, isStr := textVal.(string); isStr {
|
||||||
textParts = append(textParts, textStr)
|
textParts = append(textParts, textStr)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user