-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat: add vision/image support to agent pipeline #555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -69,7 +69,7 @@ func (p *Provider) Chat(ctx context.Context, messages []Message, tools []ToolDef | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| requestBody := map[string]interface{}{ | ||||||||||||||||||||||||||||||||
| "model": model, | ||||||||||||||||||||||||||||||||
| "messages": messages, | ||||||||||||||||||||||||||||||||
| "messages": serializeMessages(messages), | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if len(tools) > 0 { | ||||||||||||||||||||||||||||||||
|
|
@@ -135,6 +135,47 @@ func (p *Provider) Chat(ctx context.Context, messages []Message, tools []ToolDef | |||||||||||||||||||||||||||||||
| return parseResponse(body) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| func serializeMessages(messages []Message) []map[string]interface{} { | ||||||||||||||||||||||||||||||||
| result := make([]map[string]interface{}, 0, len(messages)) | ||||||||||||||||||||||||||||||||
| for _, m := range messages { | ||||||||||||||||||||||||||||||||
| if len(m.Media) == 0 { | ||||||||||||||||||||||||||||||||
| msg := map[string]interface{}{ | ||||||||||||||||||||||||||||||||
| "role": m.Role, | ||||||||||||||||||||||||||||||||
| "content": m.Content, | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| if m.ToolCallID != "" { | ||||||||||||||||||||||||||||||||
| msg["tool_call_id"] = m.ToolCallID | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| if len(m.ToolCalls) > 0 { | ||||||||||||||||||||||||||||||||
| msg["tool_calls"] = m.ToolCalls | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| result = append(result, msg) | ||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| parts := make([]map[string]interface{}, 0, 1+len(m.Media)) | ||||||||||||||||||||||||||||||||
| if m.Content != "" { | ||||||||||||||||||||||||||||||||
| parts = append(parts, map[string]interface{}{ | ||||||||||||||||||||||||||||||||
| "type": "text", | ||||||||||||||||||||||||||||||||
| "text": m.Content, | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| for _, mediaURL := range m.Media { | ||||||||||||||||||||||||||||||||
| parts = append(parts, map[string]interface{}{ | ||||||||||||||||||||||||||||||||
| "type": "image_url", | ||||||||||||||||||||||||||||||||
| "image_url": map[string]interface{}{ | ||||||||||||||||||||||||||||||||
| "url": mediaURL, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| result = append(result, map[string]interface{}{ | ||||||||||||||||||||||||||||||||
| "role": m.Role, | ||||||||||||||||||||||||||||||||
| "content": parts, | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
|
Comment on lines
+171
to
+174
|
||||||||||||||||||||||||||||||||
| result = append(result, map[string]interface{}{ | |
| "role": m.Role, | |
| "content": parts, | |
| }) | |
| msg := map[string]interface{}{ | |
| "role": m.Role, | |
| "content": parts, | |
| } | |
| if m.ToolCallID != "" { | |
| msg["tool_call_id"] = m.ToolCallID | |
| } | |
| if len(m.ToolCalls) > 0 { | |
| msg["tool_calls"] = m.ToolCalls | |
| } | |
| result = append(result, msg) |
Copilot
AI
Feb 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The serializeMessages function lacks test coverage. Given the comprehensive test suite for other provider functionality (e.g., TestProviderChat_ParsesToolCalls, TestProviderChat_StripsMoonshotPrefixAndNormalizesKimiTemperature), consider adding tests for message serialization with media attachments to ensure correct OpenAI API format compliance and prevent regressions. Test cases should cover: messages with media only, messages with both text and media, and messages without media (backward compatibility).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Media field contains URLs that are passed directly to external LLM APIs without validation. Consider adding validation to ensure URLs are from trusted sources (e.g., Discord CDN for Discord messages) and don't expose internal network resources. While the URLs originate from InboundMessage.Media which likely comes from Discord, explicit validation would prevent potential SSRF vulnerabilities if the source changes or if there are bugs in upstream URL extraction.