Merge pull request #1828 from ksylvan/kayvan/fix-empty-input-bug

Fix empty string detection in chatter and AI clients
This commit is contained in:
Kayvan Sylvan 2025-11-14 21:22:53 -08:00 committed by GitHub
commit 14c95d7bc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 9 additions and 3 deletions

View file

@ -0,0 +1,6 @@
### PR [#1828](https://github.com/danielmiessler/Fabric/pull/1828) by [ksylvan](https://github.com/ksylvan): Fix empty string detection in chatter and AI clients
- Chore: improve message handling by trimming whitespace in content checks
- Remove default space in `BuildSession` message content
- Trim whitespace in `anthropic` message content check
- Trim whitespace in `gemini` message content check

View file

@ -175,7 +175,7 @@ func (o *Chatter) BuildSession(request *domain.ChatRequest, raw bool) (session *
if request.Message == nil {
request.Message = &chat.ChatCompletionMessage{
Role: chat.ChatMessageRoleUser,
Content: " ",
Content: "",
}
}

View file

@ -356,7 +356,7 @@ func (an *Client) toMessages(msgs []*chat.ChatCompletionMessage) (ret []anthropi
lastRoleWasUser := false
for _, msg := range msgs {
if msg.Content == "" {
if strings.TrimSpace(msg.Content) == "" {
continue // Skip empty messages
}

View file

@ -456,7 +456,7 @@ func (o *Client) convertMessages(msgs []*chat.ChatCompletionMessage) []*genai.Co
content.Role = "user"
}
if msg.Content != "" {
if strings.TrimSpace(msg.Content) != "" {
content.Parts = append(content.Parts, &genai.Part{Text: msg.Content})
}