transport

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageTypeOther = iota
	MessageTypeContent
	MessageTypeDocument
)
View Source
const (
	TraceStatusUnspecified = iota
	TraceStatusRunning
	TraceStatusCompleted
	TraceStatusFailed
)

Variables

View Source
var (
	TraceExpiry = time.Hour * 24
)

Functions

func ProcessCompletionStream

func ProcessCompletionStream(ctx context.Context, ms MessageStream, cs api.CompletionStream) (string, error)

Types

type Document

type Document struct {
	Title   string `json:"title"`
	Content string `json:"content"`
	Source  string `json:"source"`
}

type MessageStream

type MessageStream interface {
	Send(ctx context.Context, payload MessageStreamPayload) error

	Recv(ctx context.Context) (*MessageStreamPayload, error)

	// Text reads the entire message stream and returns its content
	//
	// Note this will not retrieve any Documents sent in the stream
	Text(ctx context.Context) (string, error)

	GetID() string
}

type MessageStreamPayload

type MessageStreamPayload struct {
	ID     int         `json:"id"`
	Status string      `json:"status"`
	Type   MessageType `json:"type"`

	Content  string   `json:"content"`
	Document Document `json:"document"`
}

type MessageType

type MessageType int

type RedisStream

type RedisStream struct {
	// contains filtered or unexported fields
}

func (*RedisStream) GetID

func (s *RedisStream) GetID() string

func (*RedisStream) Recv

func (RedisStream) Send

func (s RedisStream) Send(ctx context.Context, payload MessageStreamPayload) error

func (*RedisStream) Text

func (s *RedisStream) Text(ctx context.Context) (string, error)

type RedisTransport

type RedisTransport struct {
	// contains filtered or unexported fields
}

func NewRedisTransport

func NewRedisTransport(rdb *redis.Client) *RedisTransport

func (*RedisTransport) GetMessageStream

func (t *RedisTransport) GetMessageStream(id string) (MessageStream, error)

func (RedisTransport) GetTrace

func (t RedisTransport) GetTrace(ctx context.Context, traceId string) (*RequestTrace, error)

func (RedisTransport) SetTrace

func (t RedisTransport) SetTrace(ctx context.Context, trace *RequestTrace) error

type RequestTrace

type RequestTrace struct {
	ID          string `redis:"id"`
	Status      int    `redis:"status"`
	StartedAt   int64  `redis:"started_at"`
	CompletedAt int64  `redis:"completed_at"`
	Query       string `redis:"query"`
	User        string `redis:"user"`
}

type TraceStatus

type TraceStatus int

type Transport

type Transport interface {
	GetMessageStream(id string) (MessageStream, error)
	SetTrace(ctx context.Context, trace *RequestTrace) error
	GetTrace(ctx context.Context, traceId string) (*RequestTrace, error)
}

Jump to

Keyboard shortcuts

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