Chore: interface{} -> any
This commit is contained in:
@@ -91,7 +91,7 @@ type ImageContentPart struct {
|
|||||||
type RoleMsg struct {
|
type RoleMsg struct {
|
||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Content string `json:"-"`
|
Content string `json:"-"`
|
||||||
ContentParts []interface{} `json:"-"`
|
ContentParts []any `json:"-"`
|
||||||
ToolCallID string `json:"tool_call_id,omitempty"` // For tool response messages
|
ToolCallID string `json:"tool_call_id,omitempty"` // For tool response messages
|
||||||
KnownTo []string `json:"known_to,omitempty"`
|
KnownTo []string `json:"known_to,omitempty"`
|
||||||
hasContentParts bool // Flag to indicate which content type to marshal
|
hasContentParts bool // Flag to indicate which content type to marshal
|
||||||
@@ -103,7 +103,7 @@ func (m *RoleMsg) MarshalJSON() ([]byte, error) {
|
|||||||
// Use structured content format
|
// Use structured content format
|
||||||
aux := struct {
|
aux := struct {
|
||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Content []interface{} `json:"content"`
|
Content []any `json:"content"`
|
||||||
ToolCallID string `json:"tool_call_id,omitempty"`
|
ToolCallID string `json:"tool_call_id,omitempty"`
|
||||||
KnownTo []string `json:"known_to,omitempty"`
|
KnownTo []string `json:"known_to,omitempty"`
|
||||||
}{
|
}{
|
||||||
@@ -135,7 +135,7 @@ func (m *RoleMsg) UnmarshalJSON(data []byte) error {
|
|||||||
// First, try to unmarshal as structured content format
|
// First, try to unmarshal as structured content format
|
||||||
var structured struct {
|
var structured struct {
|
||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Content []interface{} `json:"content"`
|
Content []any `json:"content"`
|
||||||
ToolCallID string `json:"tool_call_id,omitempty"`
|
ToolCallID string `json:"tool_call_id,omitempty"`
|
||||||
KnownTo []string `json:"known_to,omitempty"`
|
KnownTo []string `json:"known_to,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,6 @@ func (m *RoleMsg) UnmarshalJSON(data []byte) error {
|
|||||||
|
|
||||||
func (m *RoleMsg) ToText(i int) string {
|
func (m *RoleMsg) ToText(i int) string {
|
||||||
icon := fmt.Sprintf("(%d)", i)
|
icon := fmt.Sprintf("(%d)", i)
|
||||||
|
|
||||||
// Convert content to string representation
|
// Convert content to string representation
|
||||||
var contentStr string
|
var contentStr string
|
||||||
if !m.hasContentParts {
|
if !m.hasContentParts {
|
||||||
@@ -177,7 +176,7 @@ 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]interface{}); ok {
|
if partMap, ok := part.(map[string]any); ok {
|
||||||
if partType, exists := partMap["type"]; exists && partType == "text" {
|
if partType, exists := partMap["type"]; exists && partType == "text" {
|
||||||
if textVal, textExists := partMap["text"]; textExists {
|
if textVal, textExists := partMap["text"]; textExists {
|
||||||
if textStr, isStr := textVal.(string); isStr {
|
if textStr, isStr := textVal.(string); isStr {
|
||||||
@@ -189,7 +188,6 @@ func (m *RoleMsg) ToText(i int) string {
|
|||||||
}
|
}
|
||||||
contentStr = strings.Join(textParts, " ") + " "
|
contentStr = strings.Join(textParts, " ") + " "
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if already has role annotation (/completion makes them)
|
// check if already has role annotation (/completion makes them)
|
||||||
if !strings.HasPrefix(contentStr, m.Role+":") {
|
if !strings.HasPrefix(contentStr, m.Role+":") {
|
||||||
icon = fmt.Sprintf("(%d) <%s>: ", i, m.Role)
|
icon = fmt.Sprintf("(%d) <%s>: ", i, m.Role)
|
||||||
@@ -206,7 +204,7 @@ 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]interface{}); ok {
|
if partMap, ok := part.(map[string]any); ok {
|
||||||
if partType, exists := partMap["type"]; exists && partType == "text" {
|
if partType, exists := partMap["type"]; exists && partType == "text" {
|
||||||
if textVal, textExists := partMap["text"]; textExists {
|
if textVal, textExists := partMap["text"]; textExists {
|
||||||
if textStr, isStr := textVal.(string); isStr {
|
if textStr, isStr := textVal.(string); isStr {
|
||||||
@@ -231,7 +229,7 @@ func NewRoleMsg(role, content string) RoleMsg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewMultimodalMsg creates a RoleMsg with structured content parts (text and images)
|
// NewMultimodalMsg creates a RoleMsg with structured content parts (text and images)
|
||||||
func NewMultimodalMsg(role string, contentParts []interface{}) RoleMsg {
|
func NewMultimodalMsg(role string, contentParts []any) RoleMsg {
|
||||||
return RoleMsg{
|
return RoleMsg{
|
||||||
Role: role,
|
Role: role,
|
||||||
ContentParts: contentParts,
|
ContentParts: contentParts,
|
||||||
@@ -256,7 +254,7 @@ func (m *RoleMsg) IsContentParts() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetContentParts returns the content parts of the message
|
// GetContentParts returns the content parts of the message
|
||||||
func (m *RoleMsg) GetContentParts() []interface{} {
|
func (m *RoleMsg) GetContentParts() []any {
|
||||||
return m.ContentParts
|
return m.ContentParts
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,9 +275,9 @@ func (m *RoleMsg) AddTextPart(text string) {
|
|||||||
if !m.hasContentParts {
|
if !m.hasContentParts {
|
||||||
// Convert to content parts format
|
// Convert to content parts format
|
||||||
if m.Content != "" {
|
if m.Content != "" {
|
||||||
m.ContentParts = []interface{}{TextContentPart{Type: "text", Text: m.Content}}
|
m.ContentParts = []any{TextContentPart{Type: "text", Text: m.Content}}
|
||||||
} else {
|
} else {
|
||||||
m.ContentParts = []interface{}{}
|
m.ContentParts = []any{}
|
||||||
}
|
}
|
||||||
m.hasContentParts = true
|
m.hasContentParts = true
|
||||||
}
|
}
|
||||||
@@ -293,9 +291,9 @@ func (m *RoleMsg) AddImagePart(imageURL string) {
|
|||||||
if !m.hasContentParts {
|
if !m.hasContentParts {
|
||||||
// Convert to content parts format
|
// Convert to content parts format
|
||||||
if m.Content != "" {
|
if m.Content != "" {
|
||||||
m.ContentParts = []interface{}{TextContentPart{Type: "text", Text: m.Content}}
|
m.ContentParts = []any{TextContentPart{Type: "text", Text: m.Content}}
|
||||||
} else {
|
} else {
|
||||||
m.ContentParts = []interface{}{}
|
m.ContentParts = []any{}
|
||||||
}
|
}
|
||||||
m.hasContentParts = true
|
m.hasContentParts = true
|
||||||
}
|
}
|
||||||
@@ -467,7 +465,7 @@ type LlamaCPPReq struct {
|
|||||||
Stream bool `json:"stream"`
|
Stream bool `json:"stream"`
|
||||||
// For multimodal requests, prompt should be an object with prompt_string and multimodal_data
|
// For multimodal requests, prompt should be an object with prompt_string and multimodal_data
|
||||||
// For regular requests, prompt is a string
|
// For regular requests, prompt is a string
|
||||||
Prompt interface{} `json:"prompt"` // Can be string or object with prompt_string and multimodal_data
|
Prompt any `json:"prompt"` // Can be string or object with prompt_string and multimodal_data
|
||||||
Temperature float32 `json:"temperature"`
|
Temperature float32 `json:"temperature"`
|
||||||
DryMultiplier float32 `json:"dry_multiplier"`
|
DryMultiplier float32 `json:"dry_multiplier"`
|
||||||
Stop []string `json:"stop"`
|
Stop []string `json:"stop"`
|
||||||
@@ -500,7 +498,7 @@ type PromptObject struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewLCPReq(prompt, model string, multimodalData []string, props map[string]float32, stopStrings []string) LlamaCPPReq {
|
func NewLCPReq(prompt, model string, multimodalData []string, props map[string]float32, stopStrings []string) LlamaCPPReq {
|
||||||
var finalPrompt interface{}
|
var finalPrompt any
|
||||||
if len(multimodalData) > 0 {
|
if len(multimodalData) > 0 {
|
||||||
// When multimodal data is present, use the object format as per Python example:
|
// When multimodal data is present, use the object format as per Python example:
|
||||||
// { "prompt": { "prompt_string": "...", "multimodal_data": [...] } }
|
// { "prompt": { "prompt_string": "...", "multimodal_data": [...] } }
|
||||||
|
|||||||
Reference in New Issue
Block a user