embedding

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MulanPSL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

智谱 Embedding 系列模型 SDK

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Embeddings Client 客户端

func NewClient

func NewClient(timeOutSeconds int, key string, tokenExpireSeconds int) (*Client, error)

新建 Embeddings 访问客户端

@param key API Key
@param tokenExpireSeconds Token 有效秒数,当值小于等于 0 时,表示使用 API Key 鉴权,而非 Token 鉴权
@param timeOutSeconds 超时秒数
@return Client 客户端实例
@return error 错误信息

func (*Client) SyncCall

func (r *Client) SyncCall(reqBody *Request) (*Response, error)

发送同步请求

RestFul 协议实现
@param reqBody 请求体
@return *Response 返回数据
@return error 错误信息

type Data

type Data struct {
	Index     uint32        `json:"index"`     // 结果下标
	Object    string        `json:"object"`    // 结果类型,目前为 embedding
	Embedding []interface{} `json:"embedding"` // embedding 的处理结果,返回向量化表征的数组
}

模型生成的数组结果

type Request

type Request struct {
	Model public.Model `json:"model"` // 要调用的模型编码
	// 输入需要向量化的文本,支持字符串数组。
	//   embedding-2 的单条请求最多支持 512 个Tokens,数组总长度不得超过 8K;
	//   embedding-3 的单条请求最多支持 3072 个Tokens,数组总长度不得超过 8K;
	//   且数组最大不得超过 64 条。
	Input interface{} `json:"input"`
	// 向量维度,默认为 2048。
	//   Embedding-3 模型支持自定义向量维度,建议选择 256、512、1024、2048 维度
	Dimensions public.EmbeddingDimensions `json:"dimensions,omitempty"`
}

请求对象

func (*Request) Valid

func (r *Request) Valid() error

请求对象有效性验证

type Response

type Response struct {
	Model  public.Model `json:"model"`  // 模型编码
	Object string       `json:"object"` // 结果类型,目前为 list
	Data   []*Data      `json:"data"`   // 模型生成的数组结果
	Usage  *Usage       `json:"usage"`  // 模型调用结束时返回的 token 使用统计
}

同步响应对象

type Usage

type Usage struct {
	PromptTokens     uint32 `json:"prompt_tokens"`     // 用户输入的 token 数量
	CompletionTokens uint32 `json:"completion_tokens"` // 模型输出的 token 数量
	TotalTokens      uint32 `json:"total_tokens"`      // 总 token 数量
}

模型调用结束时返回的 token 使用统计

Jump to

Keyboard shortcuts

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