Documentation
¶
Index ¶
- Constants
- Variables
- func Close(ctx context.Context)
- func Flush(ctx context.Context)
- func GetPrompt(ctx context.Context, param GetPromptParam, options ...GetPromptOption) (*entity.Prompt, error)
- func GetWorkspaceID() string
- func PromptFormat(ctx context.Context, prompt *entity.Prompt, variables map[string]any, ...) (messages []*entity.Message, err error)
- func SetLogLevel(level LogLevel)
- func SetLogger(l Logger)
- func Version() string
- type AuthError
- type Client
- type GetPromptOption
- type GetPromptParam
- type HttpClient
- type LogLevel
- type Logger
- type Option
- func WithAPIBaseURL(apiBaseURL string) Option
- func WithAPIToken(apiToken string) Option
- func WithHTTPClient(client HttpClient) Option
- func WithJWTOAuthClientID(clientID string) Option
- func WithJWTOAuthPrivateKey(privateKey string) Option
- func WithJWTOAuthPublicKeyID(publicKeyID string) Option
- func WithPromptCacheMaxCount(count int) Option
- func WithPromptCacheRefreshInterval(interval time.Duration) Option
- func WithPromptTrace(enable bool) Option
- func WithTimeout(timeout time.Duration) Option
- func WithUltraLargeTraceReport(enable bool) Option
- func WithUploadTimeout(timeout time.Duration) Option
- func WithWorkspaceID(workspaceID string) Option
- type PromptClient
- type PromptFormatOption
- type RemoteServiceError
- type Span
- type SpanContext
- type StartSpanOption
- type TraceClient
Constants ¶
const ( // environment keys for loop client EnvApiBaseURL = "COZELOOP_API_BASE_URL" EnvWorkspaceID = "COZELOOP_WORKSPACE_ID" EnvApiToken = "COZELOOP_API_TOKEN" EnvJwtOAuthClientID = "COZELOOP_JWT_OAUTH_CLIENT_ID" EnvJwtOAuthPrivateKey = "COZELOOP_JWT_OAUTH_PRIVATE_KEY" EnvJwtOAuthPublicKeyID = "COZELOOP_JWT_OAUTH_PUBLIC_KEY_ID" // ComBaseURL = consts.ComBaseURL CnBaseURL = consts.CnBaseURL )
const ( LogLevelDebug LogLevel = logger.LogLevelDebug LogLevelInfo = logger.LogLevelInfo LogLevelWarn = logger.LogLevelWarn LogLevelError = logger.LogLevelError LogLevelFatal = logger.LogLevelFatal )
Variables ¶
var ( ErrInvalidParam = consts.ErrInvalidParam ErrHeaderParent = consts.ErrHeaderParent ErrRemoteService = consts.ErrRemoteService ErrAuthInfoRequired = consts.ErrAuthInfoRequired ErrParsePrivateKey = consts.ErrParsePrivateKey )
Functions ¶
func GetPrompt ¶
func GetPrompt(ctx context.Context, param GetPromptParam, options ...GetPromptOption) (*entity.Prompt, error)
GetPrompt get prompt by prompt key and version
func PromptFormat ¶
func PromptFormat(ctx context.Context, prompt *entity.Prompt, variables map[string]any, options ...PromptFormatOption) ( messages []*entity.Message, err error)
PromptFormat format prompt with variables
func SetLogLevel ¶
func SetLogLevel(level LogLevel)
SetLogLevel set log level. By default, the log level is set to Info. Note that this method is not thread-safe. Should be called before any other method.
Types ¶
type Client ¶
type Client interface {
// PromptClient interface of prompt client
PromptClient
// TraceClient interface of trace client
TraceClient
// GetWorkspaceID return workspace id
GetWorkspaceID() string
// Close Close the client. Should be called before program exit.
Close(ctx context.Context)
}
Client interface of loop client. The client is thread-safe. **Do not** create multiple instances.
type GetPromptOption ¶
type GetPromptOption func(option *prompt.GetPromptOptions)
type GetPromptParam ¶
type GetPromptParam = prompt.GetPromptParam
type HttpClient ¶
type HttpClient = httpclient.HTTPClient
HttpClient Interface of HttpClient, can use http.DefaultClient
type Option ¶
type Option func(o *options)
func WithAPIBaseURL ¶
WithAPIBaseURL set api base url. Generally, there's no need to use it. Default is http://api.coze.cn
func WithAPIToken ¶
WithAPIToken set api token. You can get it from https://www.coze.cn/open/oauth/pats **APIToken is just used for testing.** You should use JWTOauth in production.
func WithHTTPClient ¶
func WithHTTPClient(client HttpClient) Option
WithHTTPClient set http client. All http call inside SDK will use this HttpClient. Default is http.DefaultClient
func WithJWTOAuthClientID ¶
WithJWTOAuthClientID set jwt oauth client id. You can get it from https://www.coze.cn/open/oauth/apps
func WithJWTOAuthPrivateKey ¶
WithJWTOAuthPrivateKey set jwt oauth private key. You can get it from https://www.coze.cn/open/oauth/apps
func WithJWTOAuthPublicKeyID ¶
WithJWTOAuthPublicKeyID set jwt oauth public key id. You can get it from https://www.coze.cn/open/oauth/apps
func WithPromptCacheMaxCount ¶
WithPromptCacheMaxCount set prompt cache max count. Default is 100
func WithPromptCacheRefreshInterval ¶
WithPromptCacheRefreshInterval set prompt cache refresh interval. Default is 10 minute
func WithPromptTrace ¶
WithPromptTrace set whether to report trace when get and format prompt. Default is false
func WithTimeout ¶
WithTimeout set timeout when communicating with loop server. Default is 3s
func WithUltraLargeTraceReport ¶
WithUltraLargeTraceReport set whether to report ultra large trace report. Default is false
func WithUploadTimeout ¶
WithUploadTimeout set timeout when uploading images or files to loop server. Default is 30s
func WithWorkspaceID ¶
WithWorkspaceID set workspace id.
type PromptClient ¶
type PromptClient interface {
// GetPrompt get prompt by prompt key and version.
// if version is not set, the latest version of the corresponding prompt will be obtained.
GetPrompt(ctx context.Context, param GetPromptParam, options ...GetPromptOption) (*entity.Prompt, error)
// PromptFormat format prompt with variables
PromptFormat(ctx context.Context, prompt *entity.Prompt, variables map[string]any, options ...PromptFormatOption) (messages []*entity.Message, err error)
}
PromptClient interface of prompt client.
type PromptFormatOption ¶
type PromptFormatOption func(option *prompt.PromptFormatOptions)
type RemoteServiceError ¶
type RemoteServiceError = consts.RemoteServiceError
type Span ¶
type Span interface {
SpanContext
// SetTags sets business custom tags.
SetTags(ctx context.Context, tagKVs map[string]interface{})
// SetBaggage sets tags and also passes these tags to other downstream spans (assuming
//the user uses ToHeader and FromHeader to handle header passing between services).
SetBaggage(ctx context.Context, baggageItems map[string]string)
// Finish The span will be reported only after an explicit call to Finish.
// Under the hood, it is actually placed in an asynchronous queue waiting to be reported.
Finish(ctx context.Context)
// GetStartTime returns the start time of the Span.
GetStartTime() time.Time
// ToHeader Convert the span to headers. Used for cross-process correlation.
ToHeader() (map[string]string, error)
// contains filtered or unexported methods
}
Span is the interface for span.
func GetSpanFromContext ¶
GetSpanFromContext Get the span from the context.
func StartSpan ¶
func StartSpan(ctx context.Context, name, spanType string, opts ...StartSpanOption) (context.Context, Span)
StartSpan Generate a span that automatically links to the previous span in the context. The start time of the span starts counting from the call of StartSpan. The generated span will be automatically written into the context. Subsequent spans that need to be chained should call StartSpan based on the new context.
type SpanContext ¶
type SpanContext interface {
GetSpanID() string
GetTraceID() string
GetBaggage() map[string]string
}
SpanContext is the interface for span Baggage transfer.
func GetSpanFromHeader ¶
func GetSpanFromHeader(ctx context.Context, header map[string]string) SpanContext
GetSpanFromHeader Get the span from the header.
type StartSpanOption ¶
type StartSpanOption = func(o *startSpanOptions)
StartSpanOption is used to set options for the span.
func WithChildOf ¶
func WithChildOf(s SpanContext) StartSpanOption
WithChildOf Set the parent span of the span. This field is optional. If not specified, the parent span will be looked up from the context. If not found, the current span will have no parent.
func WithStartNewTrace ¶
func WithStartNewTrace() StartSpanOption
WithStartNewTrace Set the parent span of the span. This field is optional. If specified, start a span of a new trace.
func WithStartTime ¶
func WithStartTime(t time.Time) StartSpanOption
WithStartTime Set the start time of the span. This field is optional. If not specified, the time when StartSpan is called will be used as the default.
type TraceClient ¶
type TraceClient interface {
// StartSpan Generate a span that automatically links to the previous span in the context.
// The start time of the span starts counting from the call of StartSpan.
// The generated span will be automatically written into the context.
// Subsequent spans that need to be chained should call StartSpan based on the new context.
StartSpan(ctx context.Context, name, spanType string, opts ...StartSpanOption) (context.Context, Span)
// GetSpanFromContext Get the span from the context.
GetSpanFromContext(ctx context.Context) Span
// GetSpanFromHeader Get the span from the header.
GetSpanFromHeader(ctx context.Context, header map[string]string) SpanContext
// Flush Force the reporting of spans in the queue.
Flush(ctx context.Context)
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
attribute
module
|
|
|
examples
|
|
|
init/error
command
|
|
|
init/log
command
|
|
|
init/oauth_jwt
command
|
|
|
init/pat
command
|
|
|
prompt
command
|
|
|
trace/large_text
command
|
|
|
trace/multi_modality
command
|
|
|
trace/parent_child
command
|
|
|
trace/simple
command
|
|
|
trace/transfer_between_services
command
|
|
|
spec
module
|