zhipu

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

@Author xiaozhaofu 2023/8/15 11:02:00

Index

Constants

View Source
const (
	ChatMessageRoleSystem    = "system"
	ChatMessageRoleUser      = "user"
	ChatMessageRoleAssistant = "assistant"
)

Chat message role defined by the OpenAI API.

View Source
const (
	DEFULTTIMES = 12
)
View Source
const (
	Turbo = "chatglm_turbo"
)

Variables

This section is empty.

Functions

func GenerateToken

func GenerateToken(apiKey string, duration time.Duration) (string, error)

GenerateToken 生成一个token.

Types

type APIError

type APIError struct {
	Code           any     `json:"code,omitempty"`
	Message        string  `json:"message"`
	Param          *string `json:"param,omitempty"`
	Type           string  `json:"type"`
	HTTPStatusCode int     `json:"-"`
}

APIError provides error information returned by the OpenAI API. InnerError struct is only valid for Azure OpenAI Service.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) UnmarshalJSON

func (e *APIError) UnmarshalJSON(data []byte) (err error)

type ChatCompletion added in v1.0.2

type ChatCompletion[T ChatCompletionRequest] interface {
	CreateChatCompletionStream(ctx context.Context, request T) (stream *GlmChatCompletionStream, err error)
	CreateChatCompletion(ctx context.Context, request T) (response ChatCompletionResponse, err error)
	// contains filtered or unexported methods
}

func NewClient

func NewClient(authToken string) ChatCompletion[ChatCompletionRequest]

type ChatCompletionChoice

type ChatCompletionChoice struct {
	Message ChatCompletionMessage `json:"message"`
}

type ChatCompletionMessage

type ChatCompletionMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model       string                  `json:"model"`  // 模型
	Messages    []ChatCompletionMessage `json:"prompt"` // prompt
	Temperature float32                 `json:"temperature,omitempty"`
	TopP        float32                 `json:"top_p,omitempty"`
	// 智谱 SSE接口调用时,用于控制每次返回内容方式是增量还是全量,不提供此参数时默认为增量返回 - true 为增量返回 - false 为全量返回
	Incremental bool `json:"incremental"`
}

ChatCompletionRequest 请求模型参数.

type ChatCompletionResponse

type ChatCompletionResponse struct {
	ID      string                 `json:"id"`
	Object  string                 `json:"object,omitempty"`
	Created int64                  `json:"created"`
	Model   string                 `json:"model"`
	Choices []ChatCompletionChoice `json:"choices"`
	Usage   Usage                  `json:"usage,omitempty"`
}

ChatCompletionResponse represents a response structure for chat completion API.

type ChatCompletionStreamChoice

type ChatCompletionStreamChoice struct {
	Delta ChatCompletionStreamChoiceDelta `json:"delta"`
}

type ChatCompletionStreamChoiceDelta

type ChatCompletionStreamChoiceDelta struct {
	Content string `json:"content"`
	Role    string `json:"role,omitempty"`
}

type ChatglmCompletionResponse

type ChatglmCompletionResponse struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		RequestID  string                  `json:"request_id"`
		TaskID     string                  `json:"task_id"`
		TaskStatus string                  `json:"task_status"`
		Choices    []ChatCompletionMessage `json:"choices"`
		Usage      struct {
			TotalTokens int `json:"total_tokens"`
		} `json:"usage"`
	} `json:"data"`
	Success bool `json:"success"`
}

ChatglmCompletionResponse Api文本返回.

type Client

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

func (*Client) CreateChatCompletion

func (c *Client) CreateChatCompletion(
	ctx context.Context,
	request ChatCompletionRequest,
) (response ChatCompletionResponse, err error)

CreateChatCompletion — API call to Create a completion for the chat message.

func (*Client) CreateChatCompletionStream

func (c *Client) CreateChatCompletionStream(
	ctx context.Context,
	request ChatCompletionRequest,
) (*GlmChatCompletionStream, error)

type ClientConfig

type ClientConfig struct {
	BaseURL    string
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

ClientConfig is a configuration of a client.

func DefaultConfig

func DefaultConfig(authToken string) ClientConfig

func (ClientConfig) String

func (ClientConfig) String() string

type ErrorResponse

type ErrorResponse struct {
	Error *APIError `json:"error,omitempty"`
}

type Event

type Event struct {
	ID    []byte
	Data  []byte
	Event []byte
	Meta  []byte
}

type GlmChatCompletionStream

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

func (GlmChatCompletionStream) Close

func (stream GlmChatCompletionStream) Close()

func (GlmChatCompletionStream) Recv

func (stream GlmChatCompletionStream) Recv() (response T, err error)

type GlmChatCompletionStreamResponse added in v1.0.2

type GlmChatCompletionStreamResponse struct {
	ID      string                       `json:"id"`
	Event   string                       `json:"event"`
	Choices []ChatCompletionStreamChoice `json:"choices"`
	Meta    GlmMeta                      `json:"meta"`
}

type GlmMeta

type GlmMeta struct {
	TaskStatus string `json:"task_status"`
	Usage      struct {
		TotalTokens int `json:"total_tokens"`
	} `json:"usage"`
	TaskID    string `json:"task_id"`
	RequestID string `json:"request_id"`
}

type RequestError

type RequestError struct {
	HTTPStatusCode int
	Err            error
}

RequestError provides informations about generic request errors.

func (*RequestError) Error

func (e *RequestError) Error() string

func (*RequestError) Unwrap

func (e *RequestError) Unwrap() error

type StreamReaderInterface added in v1.0.2

type StreamReaderInterface[T streamable] interface {
	Recv() (response T, err error)
	Close()
	// contains filtered or unexported methods
}

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

type ZpClaims

type ZpClaims struct {
	APIKey    string `json:"api_key"`
	Exp       int64  `json:"exp"`
	Timestamp int64  `json:"timestamp"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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