cozeloop

package module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2026 License: Apache-2.0 Imports: 30 Imported by: 27

README

CozeLoop Callbacks

English | 简体中文

A CozeLoop callback implementation for Eino that implements the Handler interface. This enables seamless integration with Eino's application for enhanced observability.

Features

  • Implements github.com/cloudwego/eino/internel/callbacks.Handler
  • Easy integration with Eino's application

Installation

go get github.com/cloudwego/eino-ext/callbacks/cozeloop

Quick Start

package main
import (
	"context"
	"log"

	ccb "github.com/cloudwego/eino-ext/callbacks/cozeloop"
	"github.com/cloudwego/eino/callbacks"
	"github.com/coze-dev/cozeloop-go"
)

func main() {
	// 设置相关环境变量
	// COZELOOP_WORKSPACE_ID=your workspace id
	// COZELOOP_API_TOKEN=your token
	client, err := cozeloop.NewClient()
	if err != nil {
		panic(err)
	}
	defer client.Close(ctx)
	// 在服务 init 时 once 调用
	handler := ccb.NewLoopHandler(client)
	callbacks.AppendGlobalHandlers(handler)
}

Examples

See the examples directory for complete usage examples.

For More Details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBase64ThoughtSignatureFromExtra

func GetBase64ThoughtSignatureFromExtra(extra map[string]any) string

func GetSpanContext

func GetSpanContext(ctx context.Context) cozeloop.SpanContext

func GetThoughtSignatureFromExtra

func GetThoughtSignatureFromExtra(extra map[string]any) ([]byte, bool)

GetThoughtSignatureFromExtra copy from github.com/cloudwego/eino-ext/components/model/gemini, because it's go version is 1.24. we can't depend on it.

tries to read thought_signature from an Extra map.

thought_signature should be read from:

  • message.AssistantGenMultiContent[i].Extra: thought_signature on each generated output part
  • toolCall.Extra: thought_signature on toolCall
  • message.Extra: thought_signature on generated content (legacy, only used when message.AssistantGenMultiContent are absent)

The returned bool indicates whether thought_signature key exists in Extra. The returned []byte is the thought signature if available

func NewLoopHandler

func NewLoopHandler(client cozeloop.Client, opts ...Option) callbacks.Handler

func WithSpanContext

func WithSpanContext(ctx context.Context) context.Context

Types

type AggrMessageOutput

type AggrMessageOutput struct {
	Messages []*tracespec.ModelMessage `json:"messages"`
	// contains filtered or unexported fields
}

type CallbackDataParser

type CallbackDataParser interface {
	ParseInput(ctx context.Context, info *callbacks.RunInfo, input callbacks.CallbackInput) map[string]any
	ParseOutput(ctx context.Context, info *callbacks.RunInfo, output callbacks.CallbackOutput) map[string]any
	ParseStreamInput(ctx context.Context, info *callbacks.RunInfo, input *schema.StreamReader[callbacks.CallbackInput]) map[string]any
	ParseStreamOutput(ctx context.Context, info *callbacks.RunInfo, output *schema.StreamReader[callbacks.CallbackOutput]) map[string]any
}

CallbackDataParser tag parser for trace Implement CallbackDataParser and replace defaultDataParser by WithCallbackDataParser if needed

func NewDefaultDataParser

func NewDefaultDataParser(enableAggrMessageOutput bool) CallbackDataParser

type EinoVersionFn

type EinoVersionFn func() string

type Handler

type Handler struct {
	cozeloop.Client
	// contains filtered or unexported fields
}

func (*Handler) OnEnd

func (*Handler) OnEndWithStreamOutput

func (h *Handler) OnEndWithStreamOutput(ctx context.Context, info *callbacks.RunInfo, output *schema.StreamReader[callbacks.CallbackOutput]) context.Context

func (*Handler) OnError

func (h *Handler) OnError(ctx context.Context, info *callbacks.RunInfo, err error) context.Context

func (*Handler) OnStart

func (*Handler) OnStartWithStreamInput

func (h *Handler) OnStartWithStreamInput(ctx context.Context, info *callbacks.RunInfo, input *schema.StreamReader[callbacks.CallbackInput]) context.Context

type Option

type Option func(o *options)

func WithAggrMessageOutput

func WithAggrMessageOutput(enable bool) Option

func WithCallbackDataParser

func WithCallbackDataParser(parser CallbackDataParser) Option

func WithConcatFunction

func WithConcatFunction[T any](fn func([]T) (T, error)) Option

func WithEinoVersionFn

func WithEinoVersionFn(fn EinoVersionFn) Option

func WithEnableTracing

func WithEnableTracing(enable bool) Option

func WithLogger

func WithLogger(logger cozeloop.Logger) Option

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL