mirror of
https://github.com/mudler/cogito.git
synced 2026-07-23 10:25:44 -04:00
63abdec718
* feat: support streaming mode Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat: support streaming mode for tool calls Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat: add decision with streaming Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
32 lines
820 B
Go
32 lines
820 B
Go
package cogito
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/sashabaranov/go-openai"
|
|
)
|
|
|
|
// LLMUsage represents token usage information from an LLM response
|
|
type LLMUsage struct {
|
|
PromptTokens int
|
|
CompletionTokens int
|
|
TotalTokens int
|
|
}
|
|
|
|
type LLM interface {
|
|
Ask(ctx context.Context, f Fragment) (Fragment, error)
|
|
CreateChatCompletion(ctx context.Context, request openai.ChatCompletionRequest) (LLMReply, LLMUsage, error)
|
|
}
|
|
|
|
// StreamingLLM extends LLM with streaming support.
|
|
// Consumers should type-assert: if sllm, ok := llm.(StreamingLLM); ok { ... }
|
|
type StreamingLLM interface {
|
|
LLM
|
|
CreateChatCompletionStream(ctx context.Context, request openai.ChatCompletionRequest) (<-chan StreamEvent, error)
|
|
}
|
|
|
|
type LLMReply struct {
|
|
ChatCompletionResponse openai.ChatCompletionResponse
|
|
ReasoningContent string
|
|
}
|