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:
20
chat.go
20
chat.go
@@ -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,
|
||||||
),
|
)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user