-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
209 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,2 @@ | ||
// Package callback provides utilities for implementing callbacks. | ||
package callback | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hupe1980/golc/schema" | ||
) | ||
|
||
// Compile time check to ensure handler satisfies the Callback interface. | ||
var _ schema.Callback = (*handler)(nil) | ||
|
||
type handler struct{} | ||
|
||
func (h *handler) AlwaysVerbose() bool { | ||
return false | ||
} | ||
|
||
func (h *handler) RaiseError() bool { | ||
return false | ||
} | ||
|
||
func (h *handler) OnLLMStart(ctx context.Context, input *schema.LLMStartInput) error { | ||
return nil | ||
} | ||
|
||
func (h *handler) OnChatModelStart(ctx context.Context, input *schema.ChatModelStartInput) error { | ||
return nil | ||
} | ||
|
||
func (h *handler) OnModelNewToken(ctx context.Context, input *schema.ModelNewTokenInput) error { | ||
return nil | ||
} | ||
|
||
func (h *handler) OnModelEnd(ctx context.Context, input *schema.ModelEndInput) error { | ||
return nil | ||
} | ||
|
||
func (h *handler) OnModelError(ctx context.Context, input *schema.ModelErrorInput) error { | ||
return nil | ||
} | ||
|
||
func (h *handler) OnChainStart(ctx context.Context, input *schema.ChainStartInput) error { | ||
return nil | ||
} | ||
|
||
func (h *handler) OnChainEnd(ctx context.Context, input *schema.ChainEndInput) error { | ||
return nil | ||
} | ||
|
||
func (h *handler) OnChainError(ctx context.Context, input *schema.ChainErrorInput) error { | ||
return nil | ||
} | ||
|
||
func (h *handler) OnAgentAction(ctx context.Context, input *schema.AgentActionInput) error { | ||
return nil | ||
} | ||
|
||
func (h *handler) OnAgentFinish(ctx context.Context, input *schema.AgentFinishInput) error { | ||
return nil | ||
} | ||
|
||
func (h *handler) OnToolStart(ctx context.Context, input *schema.ToolStartInput) error { | ||
return nil | ||
} | ||
func (h *handler) OnToolEnd(ctx context.Context, input *schema.ToolEndInput) error { | ||
return nil | ||
} | ||
func (h *handler) OnToolError(ctx context.Context, input *schema.ToolErrorInput) error { | ||
return nil | ||
} | ||
|
||
func (h *handler) OnText(ctx context.Context, input *schema.TextInput) error { | ||
return nil | ||
} | ||
|
||
func (h *handler) OnRetrieverStart(ctx context.Context, input *schema.RetrieverStartInput) error { | ||
return nil | ||
} | ||
|
||
func (h *handler) OnRetrieverEnd(ctx context.Context, input *schema.RetrieverEndInput) error { | ||
return nil | ||
} | ||
|
||
func (h *handler) OnRetrieverError(ctx context.Context, input *schema.RetrieverErrorInput) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package callback | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hupe1980/golc/schema" | ||
) | ||
|
||
// Compile time check to ensure NoopHandler satisfies the Callback interface. | ||
var _ schema.Callback = (*NoopHandler)(nil) | ||
|
||
type NoopHandler struct{} | ||
|
||
func (h *NoopHandler) AlwaysVerbose() bool { | ||
return false | ||
} | ||
|
||
func (h *NoopHandler) RaiseError() bool { | ||
return false | ||
} | ||
|
||
func (h *NoopHandler) OnLLMStart(ctx context.Context, input *schema.LLMStartInput) error { | ||
return nil | ||
} | ||
|
||
func (h *NoopHandler) OnChatModelStart(ctx context.Context, input *schema.ChatModelStartInput) error { | ||
return nil | ||
} | ||
|
||
func (h *NoopHandler) OnModelNewToken(ctx context.Context, input *schema.ModelNewTokenInput) error { | ||
return nil | ||
} | ||
|
||
func (h *NoopHandler) OnModelEnd(ctx context.Context, input *schema.ModelEndInput) error { | ||
return nil | ||
} | ||
|
||
func (h *NoopHandler) OnModelError(ctx context.Context, input *schema.ModelErrorInput) error { | ||
return nil | ||
} | ||
|
||
func (h *NoopHandler) OnChainStart(ctx context.Context, input *schema.ChainStartInput) error { | ||
return nil | ||
} | ||
|
||
func (h *NoopHandler) OnChainEnd(ctx context.Context, input *schema.ChainEndInput) error { | ||
return nil | ||
} | ||
|
||
func (h *NoopHandler) OnChainError(ctx context.Context, input *schema.ChainErrorInput) error { | ||
return nil | ||
} | ||
|
||
func (h *NoopHandler) OnAgentAction(ctx context.Context, input *schema.AgentActionInput) error { | ||
return nil | ||
} | ||
|
||
func (h *NoopHandler) OnAgentFinish(ctx context.Context, input *schema.AgentFinishInput) error { | ||
return nil | ||
} | ||
|
||
func (h *NoopHandler) OnToolStart(ctx context.Context, input *schema.ToolStartInput) error { | ||
return nil | ||
} | ||
func (h *NoopHandler) OnToolEnd(ctx context.Context, input *schema.ToolEndInput) error { | ||
return nil | ||
} | ||
func (h *NoopHandler) OnToolError(ctx context.Context, input *schema.ToolErrorInput) error { | ||
return nil | ||
} | ||
|
||
func (h *NoopHandler) OnText(ctx context.Context, input *schema.TextInput) error { | ||
return nil | ||
} | ||
|
||
func (h *NoopHandler) OnRetrieverStart(ctx context.Context, input *schema.RetrieverStartInput) error { | ||
return nil | ||
} | ||
|
||
func (h *NoopHandler) OnRetrieverEnd(ctx context.Context, input *schema.RetrieverEndInput) error { | ||
return nil | ||
} | ||
|
||
func (h *NoopHandler) OnRetrieverError(ctx context.Context, input *schema.RetrieverErrorInput) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package callback | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/hupe1980/golc/schema" | ||
) | ||
|
||
// Compile time check to ensure StreamWriterHandler satisfies the Callback interface. | ||
var _ schema.Callback = (*StreamWriterHandler)(nil) | ||
|
||
type StreamWriterHandlerOptions struct { | ||
Writer io.Writer | ||
} | ||
|
||
type StreamWriterHandler struct { | ||
NoopHandler | ||
writer io.Writer | ||
opts StreamWriterHandlerOptions | ||
} | ||
|
||
func NewStreamWriterHandler(optFns ...func(o *StreamWriterHandlerOptions)) *StreamWriterHandler { | ||
opts := StreamWriterHandlerOptions{ | ||
Writer: os.Stdout, | ||
} | ||
|
||
for _, fn := range optFns { | ||
fn(&opts) | ||
} | ||
|
||
return &StreamWriterHandler{ | ||
writer: opts.Writer, | ||
opts: opts, | ||
} | ||
} | ||
|
||
func (cb *StreamWriterHandler) AlwaysVerbose() bool { | ||
return true | ||
} | ||
|
||
func (cb *StreamWriterHandler) OnModelNewToken(ctx context.Context, input *schema.ModelNewTokenInput) error { | ||
fmt.Fprint(cb.writer, input.Token) | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.