mirror of
https://github.com/danielmiessler/Fabric.git
synced 2026-01-10 06:48:04 -05:00
fix: improve channel management in Gemini streaming method
- Add deferred channel close at function start - Return error immediately instead of breaking loop - Remove redundant channel close statements from loop - Ensure channel closes on all exit paths consistently - chore: incoming 1832 changelog entry
This commit is contained in:
7
cmd/generate_changelog/incoming/1832.txt
Normal file
7
cmd/generate_changelog/incoming/1832.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
### PR [#1832](https://github.com/danielmiessler/Fabric/pull/1832) by [ksylvan](https://github.com/ksylvan): Improve channel management in Gemini provider
|
||||
|
||||
- Fix: improve channel management in Gemini streaming method
|
||||
- Add deferred channel close at function start
|
||||
- Return error immediately instead of breaking loop
|
||||
- Remove redundant channel close statements from loop
|
||||
- Ensure channel closes on all exit paths consistently
|
||||
@@ -131,6 +131,8 @@ func (o *Client) Send(ctx context.Context, msgs []*chat.ChatCompletionMessage, o
|
||||
|
||||
func (o *Client) SendStream(msgs []*chat.ChatCompletionMessage, opts *domain.ChatOptions, channel chan string) (err error) {
|
||||
ctx := context.Background()
|
||||
defer close(channel)
|
||||
|
||||
var client *genai.Client
|
||||
if client, err = genai.NewClient(ctx, &genai.ClientConfig{
|
||||
APIKey: o.ApiKey.Value,
|
||||
@@ -153,8 +155,7 @@ func (o *Client) SendStream(msgs []*chat.ChatCompletionMessage, opts *domain.Cha
|
||||
for response, err := range stream {
|
||||
if err != nil {
|
||||
channel <- fmt.Sprintf("Error: %v\n", err)
|
||||
close(channel)
|
||||
break
|
||||
return err
|
||||
}
|
||||
|
||||
text := o.extractTextFromResponse(response)
|
||||
@@ -162,7 +163,6 @@ func (o *Client) SendStream(msgs []*chat.ChatCompletionMessage, opts *domain.Cha
|
||||
channel <- text
|
||||
}
|
||||
}
|
||||
close(channel)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user