Skip to content

Commit

Permalink
Implement Close for AI/ChatStream (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshineplan authored Mar 11, 2024
1 parent 1a2910a commit 0934c48
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ai.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type AI interface {

Chatbot
ChatSession() Chatbot

Close() error
}

type Model interface {
Expand All @@ -30,6 +32,7 @@ type Chatbot interface {

type ChatStream interface {
Next() (ChatResponse, error)
Close() error
}

type ChatResponse interface {
Expand Down
9 changes: 9 additions & 0 deletions chatgpt/chatgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ func (stream *ChatStream) Next() (ai.ChatResponse, error) {
return &ChatResponse[openai.ChatCompletionStreamResponse]{resp}, nil
}

func (stream *ChatStream) Close() error {
stream.ChatCompletionStream.Close()
return nil
}

func (ai *ChatGPT) chatStream(
ctx context.Context,
history []openai.ChatCompletionMessage,
Expand Down Expand Up @@ -193,3 +198,7 @@ func (ai *ChatGPT) ChatSession() ai.Chatbot {
ai.count = nil
return &ChatSession{ai: ai}
}

func (ai *ChatGPT) Close() error {
return nil
}
4 changes: 4 additions & 0 deletions gemini/gemini.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func (stream *ChatStream) Next() (ai.ChatResponse, error) {
return &ChatResponse{resp}, nil
}

func (stream *ChatStream) Close() error {
return nil
}

func (ai *Gemini) ChatStream(ctx context.Context, parts ...string) (ai.ChatStream, error) {
if err := ai.wait(ctx); err != nil {
return nil, err
Expand Down

0 comments on commit 0934c48

Please sign in to comment.