1
0
mirror of https://github.com/coalaura/whiskr.git synced 2025-12-02 20:22:52 +00:00

cleanup file attachment building

This commit is contained in:
Laura
2025-11-07 18:45:49 +01:00
parent 6d2e89ca51
commit 32fb540f02

20
chat.go
View File

@@ -211,15 +211,6 @@ func (r *Request) Parse() (*openrouter.ChatCompletionRequest, error) {
} }
if len(message.Files) > 0 { if len(message.Files) > 0 {
if content.Text != "" {
content.Multi = append(content.Multi, openrouter.ChatMessagePart{
Type: openrouter.ChatMessagePartTypeText,
Text: content.Text,
})
content.Text = ""
}
for i, file := range message.Files { for i, file := range message.Files {
if len(file.Name) > 512 { if len(file.Name) > 512 {
return nil, fmt.Errorf("file %d is invalid (name too long, max 512 characters)", i) return nil, fmt.Errorf("file %d is invalid (name too long, max 512 characters)", i)
@@ -229,15 +220,16 @@ func (r *Request) Parse() (*openrouter.ChatCompletionRequest, error) {
lines := strings.Count(file.Content, "\n") + 1 lines := strings.Count(file.Content, "\n") + 1
content.Multi = append(content.Multi, openrouter.ChatMessagePart{ if content.Text != "" {
Type: openrouter.ChatMessagePartTypeText, content.Text += "\n\n"
Text: fmt.Sprintf( }
content.Text += fmt.Sprintf(
"FILE %q LINES %d\n<<CONTENT>>\n%s\n<<END>>", "FILE %q LINES %d\n<<CONTENT>>\n%s\n<<END>>",
file.Name, file.Name,
lines, lines,
file.Content, file.Content,
), )
})
} }
} }