Documentation
¶
Index ¶
- Constants
- func SafeDeepCopyMetadata(original map[string]interface{}) map[string]interface{}
- func SafeDeepCopySyncMapMetadata(original *sync.Map) map[string]interface{}
- func SetTrace(ctx context.Context, opts ...TraceOption) context.Context
- type CallbackHandler
- func (c *CallbackHandler) OnEnd(ctx context.Context, info *callbacks.RunInfo, output callbacks.CallbackOutput) context.Context
- func (c *CallbackHandler) OnEndWithStreamOutput(ctx context.Context, info *callbacks.RunInfo, ...) context.Context
- func (c *CallbackHandler) OnError(ctx context.Context, info *callbacks.RunInfo, err error) context.Context
- func (c *CallbackHandler) OnStart(ctx context.Context, info *callbacks.RunInfo, input callbacks.CallbackInput) context.Context
- func (c *CallbackHandler) OnStartWithStreamInput(ctx context.Context, info *callbacks.RunInfo, ...) context.Context
- type Config
- type FlowTrace
- func (ft *FlowTrace) FinishSpan(ctx context.Context, runID string)
- func (ft *FlowTrace) SpanToString(ctx context.Context) (string, error)
- func (ft *FlowTrace) StartSpan(ctx context.Context, name string, state *LangsmithState) (context.Context, string, error)
- func (ft *FlowTrace) StringToSpan(val string) (*LangsmithState, error)
- type Langsmith
- type LangsmithState
- type Run
- type RunPatch
- type RunType
- type TraceOption
Constants ¶
const (
// DefaultLangsmithAPIURL Langsmith default url
DefaultLangsmithAPIURL = "https://api.smith.langchain.com"
)
Variables ¶
This section is empty.
Functions ¶
func SafeDeepCopyMetadata ¶
Types ¶
type CallbackHandler ¶
type CallbackHandler struct {
// contains filtered or unexported fields
}
CallbackHandler implements eino's Handler interface
func NewLangsmithHandler ¶
func NewLangsmithHandler(cfg *Config) (*CallbackHandler, error)
NewLangsmithHandler creates a new CallbackHandler
func (*CallbackHandler) OnEnd ¶
func (c *CallbackHandler) OnEnd(ctx context.Context, info *callbacks.RunInfo, output callbacks.CallbackOutput) context.Context
OnEnd handles successful call completion event
func (*CallbackHandler) OnEndWithStreamOutput ¶
func (c *CallbackHandler) OnEndWithStreamOutput(ctx context.Context, info *callbacks.RunInfo, output *schema.StreamReader[callbacks.CallbackOutput]) context.Context
OnEndWithStreamOutput handles streaming output completion
func (*CallbackHandler) OnError ¶
func (c *CallbackHandler) OnError(ctx context.Context, info *callbacks.RunInfo, err error) context.Context
OnError handles call failure event
func (*CallbackHandler) OnStart ¶
func (c *CallbackHandler) OnStart(ctx context.Context, info *callbacks.RunInfo, input callbacks.CallbackInput) context.Context
OnStart handles call start event
func (*CallbackHandler) OnStartWithStreamInput ¶
func (c *CallbackHandler) OnStartWithStreamInput(ctx context.Context, info *callbacks.RunInfo, input *schema.StreamReader[callbacks.CallbackInput]) context.Context
OnStartWithStreamInput handles streaming input initialization
type Config ¶
type Config struct {
APIKey string // langsmith api key
APIURL string // langsmith api url, default:https://api.smith.langchain.com
RunIDGen func(ctx context.Context) string // langsmith run_id generator
}
Config LangsmithHandler configuration
type FlowTrace ¶
type FlowTrace struct {
// contains filtered or unexported fields
}
func NewFlowTrace ¶
func (*FlowTrace) SpanToString ¶
SpanToString parse ctx's LangsmithState to string
func (*FlowTrace) StringToSpan ¶
func (ft *FlowTrace) StringToSpan(val string) (*LangsmithState, error)
StringToSpan parse string to LangsmithState
type Langsmith ¶
type Langsmith interface {
CreateRun(ctx context.Context, run *Run) error
UpdateRun(ctx context.Context, runID string, patch *RunPatch) error
}
Langsmith func interface
func NewLangsmith ¶
NewLangsmith create langsmith client
type LangsmithState ¶
type LangsmithState struct {
TraceID string `json:"trace_id"`
ParentRunID string `json:"parent_run_id"`
ParentDottedOrder string `json:"parent_dotted_order"`
Metadata *sync.Map `json:"metadata"`
Tags []string `json:"tags"`
MarshalMetadata map[string]interface{} `json:"marshal_metadata"`
}
LangsmithState maintains Langsmith call chain state
func GetOrInitState ¶
func GetOrInitState(ctx context.Context) (context.Context, *LangsmithState)
type Run ¶
type Run struct {
ID string `json:"id"` // Unique identifier for the span.
Name string `json:"name"` // The name associated with the run.
RunType RunType `json:"run_type"` // Type of run, e.g., "llm", "chain", "tool".
StartTime time.Time `json:"start_time"` // Start time of the run.
EndTime *time.Time `json:"end_time,omitempty"` // End time of the run.
Inputs map[string]interface{} `json:"inputs"` // A map or set of inputs provided to the run.
Outputs map[string]interface{} `json:"outputs,omitempty"` // A map or set of outputs generated by the run.
Error *string `json:"error,omitempty"` // Error message if the run encountered an error.
ParentRunID *string `json:"parent_run_id,omitempty"` // Unique identifier of the parent run.
TraceID string `json:"trace_id,omitempty"` // Unique identifier for the trace the run is a part of. This is also the id field of the root run of the trace
Extra map[string]interface{} `json:"extra,omitempty"` // Any extra information run.
SessionName string `json:"session_name,omitempty"` // langsmith session name
ReferenceExampleID *string `json:"reference_example_id,omitempty"` // ID of a reference example associated with the run. This is usually only present for evaluation runs.
DottedOrder string `json:"dotted_order,omitempty"` // Ordering string, hierarchical. Format: run_start_timeZrun_uuid.child_run_start_timeZchild_run_uuid...
Tags []string `json:"tags,omitempty"` // Tags or labels associated with the run.
}
type RunPatch ¶
type RunPatch struct {
EndTime *time.Time `json:"end_time,omitempty"` // End time of the run.
Inputs map[string]interface{} `json:"inputs,omitempty"` // A map or set of inputs provided to the run.
Outputs map[string]interface{} `json:"outputs,omitempty"` // A map or set of outputs generated by the run.
Error *string `json:"error,omitempty"` // Error message if the run encountered an error.
Extra map[string]interface{} `json:"extra,omitempty"` // Any extra information run.
}
RunPatch update run when it is finished or failed, patch output or error msg.
type TraceOption ¶
type TraceOption func(*traceOptions)
func WithReferenceExampleID ¶
func WithReferenceExampleID(id string) TraceOption
WithReferenceExampleID 关联到一个 example
func WithSessionName ¶
func WithSessionName(name string) TraceOption
WithSessionName 设置 Langsmith 的项目名称