zhipu

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: MIT, MIT Imports: 14 Imported by: 0

README

zhipu

Go Reference go

中文文档

A 3rd-Party Golang Client Library for Zhipu AI Platform

Usage

Install the package
go get -u github.com/yankeguo/zhipu
Create a client
// this will use environment variables ZHIPUAI_API_KEY
client, err := zhipu.NewClient()
// or you can specify the API key
client, err = zhipu.NewClient(zhipu.WithAPIKey("your api key"))
Use the client

ChatCompletion

service := client.ChatCompletion("glm-4-flash").
    AddMessage(zhipu.ChatCompletionMessage{
        Role: "user",
        Content: "你好",
    })

res, err := service.Do(context.Background())

if err != nil {
    zhipu.GetAPIErrorCode(err) // get the API error code
} else {
    println(res.Choices[0].Message.Content)
}

ChatCompletion (Stream)

service := client.ChatCompletion("glm-4-flash").
    AddMessage(zhipu.ChatCompletionMessage{
        Role: "user",
        Content: "你好",
    }).SetStreamHandler(func(chunk zhipu.ChatCompletionResponse) error {
        println(chunk.Choices[0].Delta.Content)
        return nil
    })

res, err := service.Do(context.Background())

if err != nil {
    zhipu.GetAPIErrorCode(err) // get the API error code
} else {
    // this package will combine the stream chunks and build a final result mimicking the non-streaming API
    println(res.Choices[0].Message.Content)
}

ChatCompletion (Stream with GLM-4-AllTools)

// CodeInterpreter
s := client.ChatCompletion("GLM-4-AllTools")
s.AddMessage(zhipu.ChatCompletionMultiMessage{
    Role: "user",
    Content: []zhipu.ChatCompletionMultiContent{
        {
            Type: "text",
            Text: "计算[5,10,20,700,99,310,978,100]的平均值和方差。",
        },
    },
})
s.AddTool(zhipu.ChatCompletionToolCodeInterpreter{
    Sandbox: zhipu.Ptr(CodeInterpreterSandboxAuto),
})
s.SetStreamHandler(func(chunk zhipu.ChatCompletionResponse) error {
    for _, c := range chunk.Choices {
        for _, tc := range c.Delta.ToolCalls {
            if tc.Type == ToolTypeCodeInterpreter && tc.CodeInterpreter != nil {
                if tc.CodeInterpreter.Input != "" {
                    // DO SOMETHING
                }
                if len(tc.CodeInterpreter.Outputs) > 0 {
                    // DO SOMETHING
                }
            }
        }
    }
    return nil
})

// WebBrowser
// CAUTION: NOT 'WebSearch'
s := client.ChatCompletion("GLM-4-AllTools")
s.AddMessage(zhipu.ChatCompletionMultiMessage{
    Role: "user",
    Content: []zhipu.ChatCompletionMultiContent{
        {
            Type: "text",
            Text: "搜索下本周深圳天气如何",
        },
    },
})
s.AddTool(zhipu.ChatCompletionToolWebBrowser{})
s.SetStreamHandler(func(chunk zhipu.ChatCompletionResponse) error {
    for _, c := range chunk.Choices {
        for _, tc := range c.Delta.ToolCalls {
            if tc.Type == ToolTypeWebBrowser && tc.WebBrowser != nil {
                if tc.WebBrowser.Input != "" {
                    // DO SOMETHING
                }
                if len(tc.WebBrowser.Outputs) > 0 {
                    // DO SOMETHING
                }
            }
        }
    }
    return nil
})
s.Do(context.Background())

// DrawingTool
s := client.ChatCompletion("GLM-4-AllTools")
s.AddMessage(zhipu.ChatCompletionMultiMessage{
    Role: "user",
    Content: []zhipu.ChatCompletionMultiContent{
        {
            Type: "text",
            Text: "画一个正弦函数图像",
        },
    },
})
s.AddTool(zhipu.ChatCompletionToolDrawingTool{})
s.SetStreamHandler(func(chunk zhipu.ChatCompletionResponse) error {
    for _, c := range chunk.Choices {
        for _, tc := range c.Delta.ToolCalls {
            if tc.Type == ToolTypeDrawingTool && tc.DrawingTool != nil {
                if tc.DrawingTool.Input != "" {
                    // DO SOMETHING
                }
                if len(tc.DrawingTool.Outputs) > 0 {
                    // DO SOMETHING
                }
            }
        }
    }
    return nil
})
s.Do(context.Background())

Embedding

service := client.Embedding("embedding-v2").SetInput("你好呀")
service.Do(context.Background())

Image Generation

service := client.ImageGeneration("cogview-3").SetPrompt("一只可爱的小猫咪")
service.Do(context.Background())

Video Generation

service := client.VideoGeneration("cogvideox").SetPrompt("一只可爱的小猫咪")
resp, err := service.Do(context.Background())

for {
    result, err := client.AsyncResult(resp.ID).Do(context.Background())

    if result.TaskStatus == zhipu.VideoGenerationTaskStatusSuccess {
        _ = result.VideoResult[0].URL
        _ = result.VideoResult[0].CoverImageURL
        break
    }

    if result.TaskStatus != zhipu.VideoGenerationTaskStatusProcessing {
        break
    }

    time.Sleep(5 * time.Second)
}

Upload File (Retrieval)

service := client.FileCreate(zhipu.FilePurposeRetrieval)
service.SetLocalFile(filepath.Join("testdata", "test-file.txt"))
service.SetKnowledgeID("your-knowledge-id")

service.Do(context.Background())

Upload File (Fine-Tune)

service := client.FileCreate(zhipu.FilePurposeFineTune)
service.SetLocalFile(filepath.Join("testdata", "test-file.jsonl"))
service.Do(context.Background())

Batch Create

service := client.BatchCreate().
  SetInputFileID("fileid").
  SetCompletionWindow(zhipu.BatchCompletionWindow24h).
  SetEndpoint(BatchEndpointV4ChatCompletions)
service.Do(context.Background())

Knowledge Base

client.KnowledgeCreate("")
client.KnowledgeEdit("")

Fine Tune

client.FineTuneCreate("")
Batch Support

Batch File Writer

f, err := os.OpenFile("batch.jsonl", os.O_CREATE|os.O_WRONLY, 0644)

bw := zhipu.NewBatchFileWriter(f)

bw.Add("action_1", client.ChatCompletion("glm-4-flash").
    AddMessage(zhipu.ChatCompletionMessage{
        Role: "user",
        Content: "你好",
    }))
bw.Add("action_2", client.Embedding("embedding-v2").SetInput("你好呀"))
bw.Add("action_3", client.ImageGeneration("cogview-3").SetPrompt("一只可爱的小猫咪"))

Batch Result Reader

br := zhipu.NewBatchResultReader[zhipu.ChatCompletionResponse](r)

for {
    var res zhipu.BatchResult[zhipu.ChatCompletionResponse]
    err := br.Read(&res)
    if err != nil {
        break
    }
}

Donation

Executing unit tests will actually call the ChatGLM API and consume my quota. Please donate and thank you for your support!

Credits

GUO YANKE, MIT License

Documentation

Index

Constants

View Source
const (
	BatchEndpointV4ChatCompletions   = "/v4/chat/completions"
	BatchEndpointV4ImagesGenerations = "/v4/images/generations"
	BatchEndpointV4Embeddings        = "/v4/embeddings"
	BatchEndpointV4VideosGenerations = "/v4/videos/generations"

	BatchCompletionWindow24h = "24h"
)
View Source
const (
	RoleSystem    = "system"
	RoleUser      = "user"
	RoleAssistant = "assistant"
	RoleTool      = "tool"

	ToolChoiceAuto = "auto"

	FinishReasonStop         = "stop"
	FinishReasonStopSequence = "stop_sequence"
	FinishReasonToolCalls    = "tool_calls"
	FinishReasonLength       = "length"
	FinishReasonSensitive    = "sensitive"
	FinishReasonNetworkError = "network_error"

	ToolTypeFunction  = "function"
	ToolTypeWebSearch = "web_search"
	ToolTypeRetrieval = "retrieval"

	MultiContentTypeText     = "text"
	MultiContentTypeImageURL = "image_url"
	MultiContentTypeVideoURL = "video_url"

	// New in GLM-4-AllTools
	ToolTypeCodeInterpreter = "code_interpreter"
	ToolTypeDrawingTool     = "drawing_tool"
	ToolTypeWebBrowser      = "web_browser"

	CodeInterpreterSandboxNone = "none"
	CodeInterpreterSandboxAuto = "auto"

	ChatCompletionStatusFailed         = "failed"
	ChatCompletionStatusCompleted      = "completed"
	ChatCompletionStatusRequiresAction = "requires_action"
)
View Source
const (
	FilePurposeFineTune  = "fine-tune"
	FilePurposeRetrieval = "retrieval"
	FilePurposeBatch     = "batch"

	KnowledgeTypeArticle                    = 1
	KnowledgeTypeQADocument                 = 2
	KnowledgeTypeQASpreadsheet              = 3
	KnowledgeTypeProductDatabaseSpreadsheet = 4
	KnowledgeTypeCustom                     = 5
)
View Source
const (
	HyperParameterAuto = "auto"

	FineTuneStatusCreate          = "create"
	FineTuneStatusValidatingFiles = "validating_files"
	FineTuneStatusQueued          = "queued"
	FineTuneStatusRunning         = "running"
	FineTuneStatusSucceeded       = "succeeded"
	FineTuneStatusFailed          = "failed"
	FineTuneStatusCancelled       = "cancelled"
)
View Source
const (
	VideoGenerationTaskStatusProcessing = "PROCESSING"
	VideoGenerationTaskStatusSuccess    = "SUCCESS"
	VideoGenerationTaskStatusFail       = "FAIL"
)
View Source
const (
	KnowledgeEmbeddingIDEmbedding2 = 3
)

Variables

View Source
var (
	// ErrAPIKeyMissing is the error when the api key is missing
	ErrAPIKeyMissing = errors.New("zhipu: api key is missing")
	// ErrAPIKeyMalformed is the error when the api key is malformed
	ErrAPIKeyMalformed = errors.New("zhipu: api key is malformed")
)

Functions

func GetAPIErrorCode

func GetAPIErrorCode(err error) string

GetAPIErrorCode returns the error code of an API error.

func GetAPIErrorMessage

func GetAPIErrorMessage(err error) string

GetAPIErrorMessage returns the error message of an API error.

func Ptr

func Ptr[T any](v T) *T

Ptr returns a pointer to the value passed in. Example:

web_search_enable = zhipu.Ptr(false)

Types

type APIError

type APIError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

func (APIError) Error

func (e APIError) Error() string

type APIErrorResponse

type APIErrorResponse struct {
	APIError `json:"error"`
}

func (APIErrorResponse) Error

func (e APIErrorResponse) Error() string

type AsyncResultResponse

type AsyncResultResponse struct {
	Model       string             `json:"model"`
	TaskStatus  string             `json:"task_status"`
	RequestID   string             `json:"request_id"`
	ID          string             `json:"id"`
	VideoResult []AsyncResultVideo `json:"video_result"`
}

AsyncResultResponse is the response of the AsyncResultService

type AsyncResultService

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

AsyncResultService creates a new async result get service

func NewAsyncResultService

func NewAsyncResultService(client *Client) *AsyncResultService

NewAsyncResultService creates a new async result get service

func (*AsyncResultService) Do

func (*AsyncResultService) SetID

SetID sets the id parameter

type AsyncResultVideo

type AsyncResultVideo struct {
	URL           string `json:"url"`
	CoverImageURL string `json:"cover_image_url"`
}

AsyncResultVideo is the video result of the AsyncResultService

type BatchCancelService

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

BatchCancelService is a service to cancel a batch.

func NewBatchCancelService

func NewBatchCancelService(client *Client) *BatchCancelService

NewBatchCancelService creates a new BatchCancelService.

func (*BatchCancelService) Do

func (s *BatchCancelService) Do(ctx context.Context) (err error)

Do executes the batch cancel service.

func (*BatchCancelService) SetBatchID

func (s *BatchCancelService) SetBatchID(batchID string) *BatchCancelService

SetBatchID sets the batch id for the batch cancel service.

type BatchCreateService

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

BatchCreateService is a service to create a batch.

func NewBatchCreateService

func NewBatchCreateService(client *Client) *BatchCreateService

NewBatchCreateService creates a new BatchCreateService.

func (*BatchCreateService) Do

func (s *BatchCreateService) Do(ctx context.Context) (res BatchItem, err error)

Do executes the batch create service.

func (*BatchCreateService) SetCompletionWindow

func (s *BatchCreateService) SetCompletionWindow(window string) *BatchCreateService

SetCompletionWindow sets the completion window for the batch.

func (*BatchCreateService) SetEndpoint

func (s *BatchCreateService) SetEndpoint(endpoint string) *BatchCreateService

SetEndpoint sets the endpoint for the batch.

func (*BatchCreateService) SetInputFileID

func (s *BatchCreateService) SetInputFileID(inputFileID string) *BatchCreateService

SetInputFileID sets the input file id for the batch.

func (*BatchCreateService) SetMetadata

func (s *BatchCreateService) SetMetadata(metadata any) *BatchCreateService

SetMetadata sets the metadata for the batch.

type BatchFileWriter

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

BatchFileWriter is a writer for batch files.

func NewBatchFileWriter

func NewBatchFileWriter(w io.Writer) *BatchFileWriter

NewBatchFileWriter creates a new BatchFileWriter.

func (*BatchFileWriter) Write

func (b *BatchFileWriter) Write(customID string, s BatchSupport) error

Write writes a batch file.

type BatchGetResponse

type BatchGetResponse = BatchItem

BatchGetResponse represents the response of the batch get service.

type BatchGetService

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

BatchGetService is a service to get a batch.

func NewBatchGetService

func NewBatchGetService(client *Client) *BatchGetService

NewBatchGetService creates a new BatchGetService.

func (*BatchGetService) Do

func (s *BatchGetService) Do(ctx context.Context) (res BatchGetResponse, err error)

Do executes the batch get service.

func (*BatchGetService) SetBatchID

func (s *BatchGetService) SetBatchID(batchID string) *BatchGetService

SetBatchID sets the batch id for the batch get service.

type BatchItem

type BatchItem struct {
	ID               string             `json:"id"`
	Object           any                `json:"object"`
	Endpoint         string             `json:"endpoint"`
	InputFileID      string             `json:"input_file_id"`
	CompletionWindow string             `json:"completion_window"`
	Status           string             `json:"status"`
	OutputFileID     string             `json:"output_file_id"`
	ErrorFileID      string             `json:"error_file_id"`
	CreatedAt        int64              `json:"created_at"`
	InProgressAt     int64              `json:"in_progress_at"`
	ExpiresAt        int64              `json:"expires_at"`
	FinalizingAt     int64              `json:"finalizing_at"`
	CompletedAt      int64              `json:"completed_at"`
	FailedAt         int64              `json:"failed_at"`
	ExpiredAt        int64              `json:"expired_at"`
	CancellingAt     int64              `json:"cancelling_at"`
	CancelledAt      int64              `json:"cancelled_at"`
	RequestCounts    BatchRequestCounts `json:"request_counts"`
	Metadata         json.RawMessage    `json:"metadata"`
}

BatchItem represents a batch item.

type BatchListResponse

type BatchListResponse struct {
	Object  string      `json:"object"`
	Data    []BatchItem `json:"data"`
	FirstID string      `json:"first_id"`
	LastID  string      `json:"last_id"`
	HasMore bool        `json:"has_more"`
}

BatchListResponse represents the response of the batch list service.

type BatchListService

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

BatchListService is a service to list batches.

func NewBatchListService

func NewBatchListService(client *Client) *BatchListService

NewBatchListService creates a new BatchListService.

func (*BatchListService) Do

func (s *BatchListService) Do(ctx context.Context) (res BatchListResponse, err error)

Do executes the batch list service.

func (*BatchListService) SetAfter

func (s *BatchListService) SetAfter(after string) *BatchListService

SetAfter sets the after cursor for the batch list service.

func (*BatchListService) SetLimit

func (s *BatchListService) SetLimit(limit int) *BatchListService

SetLimit sets the limit for the batch list service.

type BatchRequestCounts

type BatchRequestCounts struct {
	Total     int64 `json:"total"`
	Completed int64 `json:"completed"`
	Failed    int64 `json:"failed"`
}

BatchRequestCounts represents the counts of the batch requests.

type BatchResult

type BatchResult[T any] struct {
	ID       string                 `json:"id"`
	CustomID string                 `json:"custom_id"`
	Response BatchResultResponse[T] `json:"response"`
}

BatchResult is the result of a batch.

type BatchResultReader

type BatchResultReader[T any] struct {
	// contains filtered or unexported fields
}

BatchResultReader reads batch results.

func NewBatchResultReader

func NewBatchResultReader[T any](r io.Reader) *BatchResultReader[T]

NewBatchResultReader creates a new BatchResultReader.

func (*BatchResultReader[T]) Read

func (r *BatchResultReader[T]) Read(out *BatchResult[T]) error

Read reads a batch result.

type BatchResultResponse

type BatchResultResponse[T any] struct {
	StatusCode int `json:"status_code"`
	Body       T   `json:"body"`
}

BatchResultResponse is the response of a batch result.

type BatchSupport

type BatchSupport interface {
	BatchMethod() string
	BatchURL() string
	BatchBody() any
}

BatchSupport is the interface for services with batch support.

type ChatCompletionChoice

type ChatCompletionChoice struct {
	Index        int                   `json:"index"`
	FinishReason string                `json:"finish_reason"`
	Delta        ChatCompletionMessage `json:"delta"`   // stream mode
	Message      ChatCompletionMessage `json:"message"` // non-stream mode
}

ChatCompletionChoice is the choice for chat completion

type ChatCompletionMessage

type ChatCompletionMessage struct {
	Role       string                   `json:"role"`
	Content    string                   `json:"content,omitempty"`
	ToolCalls  []ChatCompletionToolCall `json:"tool_calls,omitempty"`
	ToolCallID string                   `json:"tool_call_id,omitempty"`
}

ChatCompletionMessage is the message for chat completion

type ChatCompletionMessageType

type ChatCompletionMessageType interface {
	// contains filtered or unexported methods
}

type ChatCompletionMeta

type ChatCompletionMeta struct {
	UserInfo string `json:"user_info"`
	BotInfo  string `json:"bot_info"`
	UserName string `json:"user_name"`
	BotName  string `json:"bot_name"`
}

ChatCompletionMeta is the meta for chat completion

type ChatCompletionMultiContent

type ChatCompletionMultiContent struct {
	Type     string   `json:"type"`
	Text     string   `json:"text"`
	ImageURL *URLItem `json:"image_url,omitempty"`
	VideoURL *URLItem `json:"video_url,omitempty"`
}

type ChatCompletionMultiMessage

type ChatCompletionMultiMessage struct {
	Role    string                       `json:"role"`
	Content []ChatCompletionMultiContent `json:"content"`
}

ChatCompletionMultiMessage is the multi message for chat completion

type ChatCompletionResponse

type ChatCompletionResponse struct {
	ID        string                    `json:"id"`
	Created   int64                     `json:"created"`
	Model     string                    `json:"model"`
	Choices   []ChatCompletionChoice    `json:"choices"`
	Usage     ChatCompletionUsage       `json:"usage"`
	WebSearch []ChatCompletionWebSearch `json:"web_search"`
	// Status is the status of the chat completion, only in GLM-4-AllTools
	Status string `json:"status"`
}

ChatCompletionResponse is the response for chat completion

type ChatCompletionService

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

ChatCompletionStreamService is the service for chat completion stream

func NewChatCompletionService

func NewChatCompletionService(client *Client) *ChatCompletionService

NewChatCompletionService creates a new ChatCompletionService.

func (*ChatCompletionService) AddMessage

AddMessage add the message to the chat completion

func (*ChatCompletionService) AddTool

AddFunction add the function to the chat completion

func (*ChatCompletionService) BatchBody

func (s *ChatCompletionService) BatchBody() any

func (*ChatCompletionService) BatchMethod

func (s *ChatCompletionService) BatchMethod() string

func (*ChatCompletionService) BatchURL

func (s *ChatCompletionService) BatchURL() string

func (*ChatCompletionService) Do

Do send the request of the chat completion and return the response

func (*ChatCompletionService) SetDoSample

func (s *ChatCompletionService) SetDoSample(doSample bool) *ChatCompletionService

SetTemperature set the temperature of the chat completion, optional

func (*ChatCompletionService) SetMaxTokens

func (s *ChatCompletionService) SetMaxTokens(maxTokens int) *ChatCompletionService

SetMaxTokens set the max tokens of the chat completion, optional

func (*ChatCompletionService) SetMeta

SetMeta set the meta of the chat completion, optional

func (*ChatCompletionService) SetModel

SetModel set the model of the chat completion

func (*ChatCompletionService) SetRequestID

func (s *ChatCompletionService) SetRequestID(requestID string) *ChatCompletionService

SetRequestID set the request id of the chat completion, optional

func (*ChatCompletionService) SetStop

func (s *ChatCompletionService) SetStop(stop ...string) *ChatCompletionService

SetStop set the stop of the chat completion, optional

func (*ChatCompletionService) SetStreamHandler

SetStreamHandler set the stream handler of the chat completion, optional this will enable the stream mode

func (*ChatCompletionService) SetTemperature

func (s *ChatCompletionService) SetTemperature(temperature float64) *ChatCompletionService

SetTemperature set the temperature of the chat completion, optional

func (*ChatCompletionService) SetToolChoice

func (s *ChatCompletionService) SetToolChoice(toolChoice string) *ChatCompletionService

SetToolChoice set the tool choice of the chat completion, optional

func (*ChatCompletionService) SetTopP

SetTopP set the top p of the chat completion, optional

func (*ChatCompletionService) SetUserID

func (s *ChatCompletionService) SetUserID(userID string) *ChatCompletionService

SetUserID set the user id of the chat completion, optional

type ChatCompletionStreamHandler

type ChatCompletionStreamHandler func(chunk ChatCompletionResponse) error

ChatCompletionStreamHandler is the handler for chat completion stream

type ChatCompletionTool

type ChatCompletionTool interface {
	// contains filtered or unexported methods
}

ChatCompletionTool is the interface for chat completion tool

type ChatCompletionToolCall

type ChatCompletionToolCall struct {
	ID              string                                 `json:"id"`
	Type            string                                 `json:"type"`
	Function        *ChatCompletionToolCallFunction        `json:"function,omitempty"`
	CodeInterpreter *ChatCompletionToolCallCodeInterpreter `json:"code_interpreter,omitempty"`
	DrawingTool     *ChatCompletionToolCallDrawingTool     `json:"drawing_tool,omitempty"`
	WebBrowser      *ChatCompletionToolCallWebBrowser      `json:"web_browser,omitempty"`
}

ChatCompletionToolCall is the tool call for chat completion

type ChatCompletionToolCallCodeInterpreter

type ChatCompletionToolCallCodeInterpreter struct {
	Input   string                                        `json:"input"`
	Outputs []ChatCompletionToolCallCodeInterpreterOutput `json:"outputs"`
}

ChatCompletionToolCallCodeInterpreter is the code interpreter for chat completion tool call

type ChatCompletionToolCallCodeInterpreterOutput

type ChatCompletionToolCallCodeInterpreterOutput struct {
	Type string `json:"type"`
	Logs string `json:"logs"`
	File string `json:"file"`
}

ChatCompletionToolCallCodeInterpreterOutput is the output for chat completion tool call code interpreter

type ChatCompletionToolCallDrawingTool

type ChatCompletionToolCallDrawingTool struct {
	Input   string                                    `json:"input"`
	Outputs []ChatCompletionToolCallDrawingToolOutput `json:"outputs"`
}

ChatCompletionToolCallDrawingTool is the drawing tool for chat completion tool call

type ChatCompletionToolCallDrawingToolOutput

type ChatCompletionToolCallDrawingToolOutput struct {
	Image string `json:"image"`
}

ChatCompletionToolCallDrawingToolOutput is the output for chat completion tool call drawing tool

type ChatCompletionToolCallFunction

type ChatCompletionToolCallFunction struct {
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments"`
}

ChatCompletionToolCallFunction is the function for chat completion tool call

type ChatCompletionToolCallWebBrowser

type ChatCompletionToolCallWebBrowser struct {
	Input   string                                   `json:"input"`
	Outputs []ChatCompletionToolCallWebBrowserOutput `json:"outputs"`
}

ChatCompletionToolCallWebBrowser is the web browser for chat completion tool call

type ChatCompletionToolCallWebBrowserOutput

type ChatCompletionToolCallWebBrowserOutput struct {
	Title   string `json:"title"`
	Link    string `json:"link"`
	Content string `json:"content"`
}

ChatCompletionToolCallWebBrowserOutput is the output for chat completion tool call web browser

type ChatCompletionToolCodeInterpreter

type ChatCompletionToolCodeInterpreter struct {
	Sandbox *string `json:"sandbox,omitempty"`
}

ChatCompletionToolCodeInterpreter is the code interpreter for chat completion only in GLM-4-AllTools

type ChatCompletionToolDrawingTool

type ChatCompletionToolDrawingTool struct {
}

ChatCompletionToolDrawingTool is the drawing tool for chat completion only in GLM-4-AllTools

type ChatCompletionToolFunction

type ChatCompletionToolFunction struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Parameters  any    `json:"parameters"`
}

ChatCompletionToolFunction is the function for chat completion

type ChatCompletionToolRetrieval

type ChatCompletionToolRetrieval struct {
	KnowledgeID    string `json:"knowledge_id"`
	PromptTemplate string `json:"prompt_template,omitempty"`
}

ChatCompletionToolRetrieval is the retrieval for chat completion

type ChatCompletionToolWebBrowser

type ChatCompletionToolWebBrowser struct {
}

ChatCompletionToolWebBrowser is the web browser for chat completion

type ChatCompletionToolWebSearch

type ChatCompletionToolWebSearch struct {
	Enable       *bool  `json:"enable,omitempty"`
	SearchQuery  string `json:"search_query,omitempty"`
	SearchResult bool   `json:"search_result,omitempty"`
}

ChatCompletionToolWebSearch is the web search for chat completion

type ChatCompletionUsage

type ChatCompletionUsage struct {
	PromptTokens     int64 `json:"prompt_tokens"`
	CompletionTokens int64 `json:"completion_tokens"`
	TotalTokens      int64 `json:"total_tokens"`
}

ChatCompletionUsage is the usage for chat completion

type ChatCompletionWebSearch

type ChatCompletionWebSearch struct {
	Icon    string `json:"icon"`
	Title   string `json:"title"`
	Link    string `json:"link"`
	Media   string `json:"media"`
	Content string `json:"content"`
}

ChatCompletionWebSearch is the web search result for chat completion

type Client

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

Client is the client for zhipu ai platform

func NewClient

func NewClient(optFns ...ClientOption) (client *Client, err error)

NewClient creates a new client It will read the api key from the environment variable ZHIPUAI_API_KEY It will read the base url from the environment variable ZHIPUAI_BASE_URL

func (*Client) AsyncResult

func (c *Client) AsyncResult(id string) *AsyncResultService

AsyncResult creates a new async result get service

func (*Client) BatchCancel

func (c *Client) BatchCancel(batchID string) *BatchCancelService

BatchCancel creates a new BatchCancelService.

func (*Client) BatchCreate

func (c *Client) BatchCreate() *BatchCreateService

BatchCreate creates a new BatchCreateService.

func (*Client) BatchGet

func (c *Client) BatchGet(batchID string) *BatchGetService

BatchGet creates a new BatchGetService.

func (*Client) BatchList

func (c *Client) BatchList() *BatchListService

BatchList creates a new BatchListService.

func (*Client) ChatCompletion

func (c *Client) ChatCompletion(model string) *ChatCompletionService

ChatCompletion creates a new ChatCompletionService.

func (*Client) Embedding

func (c *Client) Embedding(model string) *EmbeddingService

Embedding embeds a list of text into a vector space.

func (*Client) FileCreate

func (c *Client) FileCreate(purpose string) *FileCreateService

FileCreate creates a new FileCreateService.

func (*Client) FileDelete

func (c *Client) FileDelete(documentID string) *FileDeleteService

FileDeleteService creates a new FileDeleteService.

func (*Client) FileDownload

func (c *Client) FileDownload(fileID string) *FileDownloadService

FileDownload creates a new FileDownloadService.

func (*Client) FileEdit

func (c *Client) FileEdit(documentID string) *FileEditService

FileEditService creates a new FileEditService.

func (*Client) FileGet

func (c *Client) FileGet(documentID string) *FileGetService

FileGetService creates a new FileGetService.

func (*Client) FileList

func (c *Client) FileList(purpose string) *FileListService

FileList creates a new FileListService.

func (*Client) FineTuneCancel

func (c *Client) FineTuneCancel(jobID string) *FineTuneCancelService

FineTuneCancel creates a new fine tune cancel service

func (*Client) FineTuneCreate

func (c *Client) FineTuneCreate(model string) *FineTuneCreateService

FineTuneCreate creates a new fine tune create service

func (*Client) FineTuneDelete

func (c *Client) FineTuneDelete(jobID string) *FineTuneDeleteService

FineTuneDelete creates a new fine tune delete service

func (*Client) FineTuneEventList

func (c *Client) FineTuneEventList(jobID string) *FineTuneEventListService

FineTuneEventList creates a new fine tune event list service

func (*Client) FineTuneGet

func (c *Client) FineTuneGet(jobID string) *FineTuneGetService

FineTuneGet creates a new fine tune get service

func (*Client) FineTuneList

func (c *Client) FineTuneList() *FineTuneListService

FineTuneList creates a new fine tune list service

func (*Client) ImageGeneration

func (c *Client) ImageGeneration(model string) *ImageGenerationService

ImageGeneration creates a new image generation service

func (*Client) KnowledgeCapacity

func (c *Client) KnowledgeCapacity() *KnowledgeCapacityService

KnowledgeGet creates a new knowledge get service

func (*Client) KnowledgeCreate

func (c *Client) KnowledgeCreate() *KnowledgeCreateService

KnowledgeCreate creates a new knowledge create service

func (*Client) KnowledgeDelete

func (c *Client) KnowledgeDelete(knowledgeID string) *KnowledgeDeleteService

KnowledgeDelete creates a new knowledge delete service

func (*Client) KnowledgeEdit

func (c *Client) KnowledgeEdit(knowledgeID string) *KnowledgeEditService

KnowledgeEdit creates a new knowledge edit service

func (*Client) KnowledgeList

func (c *Client) KnowledgeList() *KnowledgeListService

KnowledgeList list all the knowledge

func (*Client) VideoGeneration

func (c *Client) VideoGeneration(model string) *VideoGenerationService

VideoGeneration creates a new video generation service

type ClientOption

type ClientOption func(opts *clientOptions)

ClientOption is a function that configures the client

func WithAPIKey

func WithAPIKey(apiKey string) ClientOption

WithAPIKey set the api key of the client

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL set the base url of the client

func WithDebug

func WithDebug(debug bool) ClientOption

WithDebug set the debug mode of the client

func WithHTTPClient

func WithHTTPClient(client *http.Client) ClientOption

WithHTTPClient set the http client of the client

type EmbeddingData

type EmbeddingData struct {
	Embedding []float64 `json:"embedding"`
	Index     int       `json:"index"`
	Object    string    `json:"object"`
}

EmbeddingData is the data for each embedding.

type EmbeddingResponse

type EmbeddingResponse struct {
	Model  string              `json:"model"`
	Data   []EmbeddingData     `json:"data"`
	Object string              `json:"object"`
	Usage  ChatCompletionUsage `json:"usage"`
}

EmbeddingResponse is the response from the embedding service.

type EmbeddingService

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

EmbeddingService embeds a list of text into a vector space.

func NewEmbeddingService

func NewEmbeddingService(client *Client) *EmbeddingService

NewEmbeddingService creates a new EmbeddingService.

func (*EmbeddingService) BatchBody

func (s *EmbeddingService) BatchBody() any

func (*EmbeddingService) BatchMethod

func (s *EmbeddingService) BatchMethod() string

func (*EmbeddingService) BatchURL

func (s *EmbeddingService) BatchURL() string

func (*EmbeddingService) Do

func (s *EmbeddingService) Do(ctx context.Context) (res EmbeddingResponse, err error)

func (*EmbeddingService) SetInput

func (s *EmbeddingService) SetInput(input string) *EmbeddingService

SetInput sets the input text to embed.

func (*EmbeddingService) SetModel

func (s *EmbeddingService) SetModel(model string) *EmbeddingService

SetModel sets the model to use for the embedding.

type FileCreateFineTuneResponse

type FileCreateFineTuneResponse struct {
	Bytes     int64  `json:"bytes"`
	CreatedAt int64  `json:"created_at"`
	Filename  string `json:"filename"`
	Object    string `json:"object"`
	Purpose   string `json:"purpose"`
	ID        string `json:"id"`
}

FileCreateFineTuneResponse is the response of the FileCreateService.

type FileCreateKnowledgeFailedInfo

type FileCreateKnowledgeFailedInfo struct {
	Filename   string `json:"fileName"`
	FailReason string `json:"failReason"`
}

FileCreateKnowledgeFailedInfo is the failed info of the FileCreateKnowledgeResponse.

type FileCreateKnowledgeResponse

type FileCreateKnowledgeResponse struct {
	SuccessInfos []FileCreateKnowledgeSuccessInfo `json:"successInfos"`
	FailedInfos  []FileCreateKnowledgeFailedInfo  `json:"failedInfos"`
}

FileCreateKnowledgeResponse is the response of the FileCreateService.

type FileCreateKnowledgeSuccessInfo

type FileCreateKnowledgeSuccessInfo struct {
	Filename   string `json:"fileName"`
	DocumentID string `json:"documentId"`
}

FileCreateKnowledgeSuccessInfo is the success info of the FileCreateKnowledgeResponse.

type FileCreateResponse

type FileCreateResponse struct {
	FileCreateFineTuneResponse
	FileCreateKnowledgeResponse
}

FileCreateResponse is the response of the FileCreateService.

type FileCreateService

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

FileCreateService is a service to create a file.

func NewFileCreateService

func NewFileCreateService(client *Client) *FileCreateService

NewFileCreateService creates a new FileCreateService.

func (*FileCreateService) Do

Do makes the request.

func (*FileCreateService) SetCustomSeparator

func (s *FileCreateService) SetCustomSeparator(customSeparator string) *FileCreateService

SetCustomSeparator sets the custom_separator parameter of the FileCreateService.

func (*FileCreateService) SetFile

func (s *FileCreateService) SetFile(file io.Reader, filename string) *FileCreateService

SetFile sets the file parameter of the FileCreateService.

func (*FileCreateService) SetKnowledgeID

func (s *FileCreateService) SetKnowledgeID(knowledgeID string) *FileCreateService

SetKnowledgeID sets the knowledge_id parameter of the FileCreateService.

func (*FileCreateService) SetLocalFile

func (s *FileCreateService) SetLocalFile(localFile string) *FileCreateService

SetLocalFile sets the local_file parameter of the FileCreateService.

func (*FileCreateService) SetPurpose

func (s *FileCreateService) SetPurpose(purpose string) *FileCreateService

SetPurpose sets the purpose parameter of the FileCreateService.

func (*FileCreateService) SetSentenceSize

func (s *FileCreateService) SetSentenceSize(sentenceSize int) *FileCreateService

SetSentenceSize sets the sentence_size parameter of the FileCreateService.

type FileDeleteService

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

FileDeleteService is a service to delete a file.

func NewFileDeleteService

func NewFileDeleteService(client *Client) *FileDeleteService

NewFileDeleteService creates a new FileDeleteService.

func (*FileDeleteService) Do

func (s *FileDeleteService) Do(ctx context.Context) (err error)

Do makes the request.

func (*FileDeleteService) SetDocumentID

func (s *FileDeleteService) SetDocumentID(documentID string) *FileDeleteService

SetDocumentID sets the document_id parameter of the FileDeleteService.

type FileDownloadService

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

FileDownloadService is a service to download a file.

func NewFileDownloadService

func NewFileDownloadService(client *Client) *FileDownloadService

NewFileDownloadService creates a new FileDownloadService.

func (*FileDownloadService) Do

func (s *FileDownloadService) Do(ctx context.Context) (err error)

Do makes the request.

func (*FileDownloadService) SetFileID

func (s *FileDownloadService) SetFileID(fileID string) *FileDownloadService

SetFileID sets the file_id parameter of the FileDownloadService.

func (*FileDownloadService) SetOutput

SetOutput sets the output parameter of the FileDownloadService.

func (*FileDownloadService) SetOutputFile

func (s *FileDownloadService) SetOutputFile(filename string) *FileDownloadService

SetOutputFile sets the output_file parameter of the FileDownloadService.

type FileEditService

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

FileEditService is a service to edit a file.

func NewFileEditService

func NewFileEditService(client *Client) *FileEditService

NewFileEditService creates a new FileEditService.

func (*FileEditService) Do

func (s *FileEditService) Do(ctx context.Context) (err error)

Do makes the request.

func (*FileEditService) SetCustomSeparator

func (s *FileEditService) SetCustomSeparator(customSeparator ...string) *FileEditService

SetSentenceSize sets the sentence_size parameter of the FileEditService.

func (*FileEditService) SetDocumentID

func (s *FileEditService) SetDocumentID(documentID string) *FileEditService

SetDocumentID sets the document_id parameter of the FileEditService.

func (*FileEditService) SetKnowledgeType

func (s *FileEditService) SetKnowledgeType(knowledgeType int) *FileEditService

SetKnowledgeType sets the knowledge_type parameter of the FileEditService.

func (*FileEditService) SetSentenceSize

func (s *FileEditService) SetSentenceSize(sentenceSize int) *FileEditService

SetSentenceSize sets the sentence_size parameter of the FileEditService.

type FileFailInfo

type FileFailInfo struct {
	EmbeddingCode int    `json:"embedding_code"`
	EmbeddingMsg  string `json:"embedding_msg"`
}

FileFailInfo is the failed info of the FileListKnowledgeItem.

type FileGetResponse

type FileGetResponse = FileListKnowledgeItem

FileGetResponse is the response of the FileGetService.

type FileGetService

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

FileGetService is a service to get a file.

func NewFileGetService

func NewFileGetService(client *Client) *FileGetService

NewFileGetService creates a new FileGetService.

func (*FileGetService) Do

func (s *FileGetService) Do(ctx context.Context) (res FileGetResponse, err error)

Do makes the request.

func (*FileGetService) SetDocumentID

func (s *FileGetService) SetDocumentID(documentID string) *FileGetService

SetDocumentID sets the document_id parameter of the FileGetService.

type FileListFineTuneItem

type FileListFineTuneItem struct {
	Bytes     int64  `json:"bytes"`
	CreatedAt int64  `json:"created_at"`
	Filename  string `json:"filename"`
	ID        string `json:"id"`
	Object    string `json:"object"`
	Purpose   string `json:"purpose"`
}

FileListFineTuneItem is the item of the FileListFineTuneResponse.

type FileListFineTuneResponse

type FileListFineTuneResponse struct {
	Object string                 `json:"object"`
	Data   []FileListFineTuneItem `json:"data"`
}

FileListFineTuneResponse is the response of the FileListService.

type FileListKnowledgeItem

type FileListKnowledgeItem struct {
	ID              string        `json:"id"`
	Name            string        `json:"name"`
	URL             string        `json:"url"`
	Length          int64         `json:"length"`
	SentenceSize    int64         `json:"sentence_size"`
	CustomSeparator []string      `json:"custom_separator"`
	EmbeddingStat   int           `json:"embedding_stat"`
	FailInfo        *FileFailInfo `json:"failInfo"`
	WordNum         int64         `json:"word_num"`
	ParseImage      int           `json:"parse_image"`
}

FileListKnowledgeItem is the item of the FileListKnowledgeResponse.

type FileListKnowledgeResponse

type FileListKnowledgeResponse struct {
	Total int                     `json:"total"`
	List  []FileListKnowledgeItem `json:"list"`
}

FileListKnowledgeResponse is the response of the FileListService.

type FileListResponse

type FileListResponse struct {
	FileListKnowledgeResponse
	FileListFineTuneResponse
}

FileListResponse is the response of the FileListService.

type FileListService

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

FileListService is a service to list files.

func NewFileListService

func NewFileListService(client *Client) *FileListService

NewFileListService creates a new FileListService.

func (*FileListService) Do

func (s *FileListService) Do(ctx context.Context) (res FileListResponse, err error)

Do makes the request.

func (*FileListService) SetAfter

func (s *FileListService) SetAfter(after string) *FileListService

SetAfter sets the after parameter of the FileListService.

func (*FileListService) SetKnowledgeID

func (s *FileListService) SetKnowledgeID(knowledgeID string) *FileListService

SetKnowledgeID sets the knowledge_id parameter of the FileListService.

func (*FileListService) SetLimit

func (s *FileListService) SetLimit(limit int) *FileListService

SetLimit sets the limit parameter of the FileListService.

func (*FileListService) SetOrder

func (s *FileListService) SetOrder(asc bool) *FileListService

SetOrder sets the order parameter of the FileListService.

func (*FileListService) SetPage

func (s *FileListService) SetPage(page int) *FileListService

SetPage sets the page parameter of the FileListService.

func (*FileListService) SetPurpose

func (s *FileListService) SetPurpose(purpose string) *FileListService

SetPurpose sets the purpose parameter of the FileListService.

type FineTuneCancelService

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

FineTuneCancelService creates a new fine tune cancel

func NewFineTuneCancelService

func NewFineTuneCancelService(client *Client) *FineTuneCancelService

NewFineTuneCancelService creates a new FineTuneCancelService

func (*FineTuneCancelService) Do

func (s *FineTuneCancelService) Do(ctx context.Context) (res FineTuneItem, err error)

Do makes the request

func (*FineTuneCancelService) SetJobID

SetJobID sets the jobID parameter

type FineTuneCreateResponse

type FineTuneCreateResponse = FineTuneItem

FineTuneCreateResponse is the response of the FineTuneCreateService

type FineTuneCreateService

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

FineTuneCreateService creates a new fine tune

func NewFineTuneCreateService

func NewFineTuneCreateService(client *Client) *FineTuneCreateService

NewFineTuneCreateService creates a new FineTuneCreateService

func (*FineTuneCreateService) Do

Do makes the request

func (*FineTuneCreateService) SetBatchSize

func (s *FineTuneCreateService) SetBatchSize(batchSize int) *FineTuneCreateService

SetBatchSize sets the batchSize parameter

func (*FineTuneCreateService) SetBatchSizeAuto

func (s *FineTuneCreateService) SetBatchSizeAuto() *FineTuneCreateService

SetBatchSizeAuto sets the batchSize parameter to auto

func (*FineTuneCreateService) SetLearningRateMultiplier

func (s *FineTuneCreateService) SetLearningRateMultiplier(learningRateMultiplier float64) *FineTuneCreateService

SetLearningRateMultiplier sets the learningRateMultiplier parameter

func (*FineTuneCreateService) SetLearningRateMultiplierAuto

func (s *FineTuneCreateService) SetLearningRateMultiplierAuto() *FineTuneCreateService

SetLearningRateMultiplierAuto sets the learningRateMultiplier parameter to auto

func (*FineTuneCreateService) SetModel

SetModel sets the model parameter

func (*FineTuneCreateService) SetNEpochs

func (s *FineTuneCreateService) SetNEpochs(nEpochs int) *FineTuneCreateService

SetNEpochs sets the nEpochs parameter

func (*FineTuneCreateService) SetNEpochsAuto

func (s *FineTuneCreateService) SetNEpochsAuto() *FineTuneCreateService

SetNEpochsAuto sets the nEpochs parameter to auto

func (*FineTuneCreateService) SetRequestID

func (s *FineTuneCreateService) SetRequestID(requestID string) *FineTuneCreateService

SetRequestID sets the requestID parameter

func (*FineTuneCreateService) SetSuffix

func (s *FineTuneCreateService) SetSuffix(suffix string) *FineTuneCreateService

SetSuffix sets the suffix parameter

func (*FineTuneCreateService) SetTrainingFile

func (s *FineTuneCreateService) SetTrainingFile(trainingFile string) *FineTuneCreateService

SetTrainingFile sets the trainingFile parameter

func (*FineTuneCreateService) SetValidationFile

func (s *FineTuneCreateService) SetValidationFile(validationFile string) *FineTuneCreateService

SetValidationFile sets the validationFile parameter

type FineTuneDeleteService

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

FineTuneDeleteService creates a new fine tune delete

func NewFineTuneDeleteService

func NewFineTuneDeleteService(client *Client) *FineTuneDeleteService

NewFineTuneDeleteService creates a new FineTuneDeleteService

func (*FineTuneDeleteService) Do

func (s *FineTuneDeleteService) Do(ctx context.Context) (res FineTuneItem, err error)

Do makes the request

func (*FineTuneDeleteService) SetJobID

SetJobID sets the jobID parameter

type FineTuneEventData

type FineTuneEventData struct {
	Acc           float64 `json:"acc"`
	Loss          float64 `json:"loss"`
	CurrentSteps  int64   `json:"current_steps"`
	RemainingTime string  `json:"remaining_time"`
	ElapsedTime   string  `json:"elapsed_time"`
	TotalSteps    int64   `json:"total_steps"`
	Epoch         int64   `json:"epoch"`
	TrainedTokens int64   `json:"trained_tokens"`
	LearningRate  float64 `json:"learning_rate"`
}

FineTuneEventData is the data of the FineTuneEventItem

type FineTuneEventItem

type FineTuneEventItem struct {
	ID        string            `json:"id"`
	Type      string            `json:"type"`
	Level     string            `json:"level"`
	Message   string            `json:"message"`
	Object    string            `json:"object"`
	CreatedAt int64             `json:"created_at"`
	Data      FineTuneEventData `json:"data"`
}

FineTuneEventItem is the item of the FineTuneEventListResponse

type FineTuneEventListResponse

type FineTuneEventListResponse struct {
	Data    []FineTuneEventItem `json:"data"`
	HasMore bool                `json:"has_more"`
	Object  string              `json:"object"`
}

FineTuneEventListResponse is the response of the FineTuneEventListService

type FineTuneEventListService

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

FineTuneEventListService creates a new fine tune event list

func NewFineTuneEventListService

func NewFineTuneEventListService(client *Client) *FineTuneEventListService

NewFineTuneEventListService creates a new FineTuneEventListService

func (*FineTuneEventListService) Do

Do makes the request

func (*FineTuneEventListService) SetAfter

SetAfter sets the after parameter

func (*FineTuneEventListService) SetJobID

SetJobID sets the jobID parameter

func (*FineTuneEventListService) SetLimit

SetLimit sets the limit parameter

type FineTuneGetService

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

FineTuneGetService creates a new fine tune get

func NewFineTuneGetService

func NewFineTuneGetService(client *Client) *FineTuneGetService

NewFineTuneGetService creates a new FineTuneGetService

func (*FineTuneGetService) Do

func (s *FineTuneGetService) Do(ctx context.Context) (res FineTuneItem, err error)

Do makes the request

func (*FineTuneGetService) SetJobID

func (s *FineTuneGetService) SetJobID(jobID string) *FineTuneGetService

SetJobID sets the jobID parameter

type FineTuneItem

type FineTuneItem struct {
	ID             string   `json:"id"`
	RequestID      string   `json:"request_id"`
	FineTunedModel string   `json:"fine_tuned_model"`
	Status         string   `json:"status"`
	Object         string   `json:"object"`
	TrainingFile   string   `json:"training_file"`
	ValidationFile string   `json:"validation_file"`
	Error          APIError `json:"error"`
}

FineTuneItem is the item of the FineTune

type FineTuneListResponse

type FineTuneListResponse struct {
	Data   []FineTuneItem `json:"data"`
	Object string         `json:"object"`
}

FineTuneListResponse is the response of the FineTuneListService

type FineTuneListService

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

FineTuneListService creates a new fine tune list

func NewFineTuneListService

func NewFineTuneListService(client *Client) *FineTuneListService

NewFineTuneListService creates a new FineTuneListService

func (*FineTuneListService) Do

Do makes the request

func (*FineTuneListService) SetAfter

func (s *FineTuneListService) SetAfter(after string) *FineTuneListService

SetAfter sets the after parameter

func (*FineTuneListService) SetLimit

func (s *FineTuneListService) SetLimit(limit int) *FineTuneListService

SetLimit sets the limit parameter

type IDItem

type IDItem struct {
	ID string `json:"id,omitempty"`
}

IDItem is a struct that contains an ID.

type ImageGenerationResponse

type ImageGenerationResponse struct {
	Created int64     `json:"created"`
	Data    []URLItem `json:"data"`
}

ImageGenerationResponse is the response of the ImageGenerationService

type ImageGenerationService

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

ImageGenerationService creates a new image generation

func NewImageGenerationService

func NewImageGenerationService(client *Client) *ImageGenerationService

NewImageGenerationService creates a new ImageGenerationService

func (*ImageGenerationService) BatchBody

func (s *ImageGenerationService) BatchBody() any

func (*ImageGenerationService) BatchMethod

func (s *ImageGenerationService) BatchMethod() string

func (*ImageGenerationService) BatchURL

func (s *ImageGenerationService) BatchURL() string

func (*ImageGenerationService) Do

func (*ImageGenerationService) SetModel

SetModel sets the model parameter

func (*ImageGenerationService) SetPrompt

SetPrompt sets the prompt parameter

func (*ImageGenerationService) SetSize

func (*ImageGenerationService) SetUserID

SetUserID sets the userID parameter

type KnowledgeCapacityItem

type KnowledgeCapacityItem struct {
	WordNum int64 `json:"word_num"`
	Length  int64 `json:"length"`
}

KnowledgeCapacityItem is an item in the knowledge capacity

type KnowledgeCapacityResponse

type KnowledgeCapacityResponse struct {
	Used  KnowledgeCapacityItem `json:"used"`
	Total KnowledgeCapacityItem `json:"total"`
}

KnowledgeCapacityResponse is the response of the KnowledgeCapacityService

type KnowledgeCapacityService

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

KnowledgeCapacityService query the capacity of the knowledge

func NewKnowledgeCapacityService

func NewKnowledgeCapacityService(client *Client) *KnowledgeCapacityService

SetKnowledgeID sets the knowledge id

func (*KnowledgeCapacityService) Do

Do query the capacity of the knowledge

type KnowledgeCreateResponse

type KnowledgeCreateResponse = IDItem

KnowledgeCreateResponse is the response of the KnowledgeCreateService

type KnowledgeCreateService

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

KnowledgeCreateService creates a new knowledge

func NewKnowledgeCreateService

func NewKnowledgeCreateService(client *Client) *KnowledgeCreateService

NewKnowledgeCreateService creates a new KnowledgeCreateService

func (*KnowledgeCreateService) Do

Do creates the knowledge

func (*KnowledgeCreateService) SetDescription

func (s *KnowledgeCreateService) SetDescription(description string) *KnowledgeCreateService

SetDescription sets the description of the knowledge

func (*KnowledgeCreateService) SetEmbeddingID

func (s *KnowledgeCreateService) SetEmbeddingID(embeddingID int) *KnowledgeCreateService

SetEmbeddingID sets the embedding id of the knowledge

func (*KnowledgeCreateService) SetName

SetName sets the name of the knowledge

type KnowledgeDeleteService

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

KnowledgeDeleteService deletes a knowledge

func NewKnowledgeDeleteService

func NewKnowledgeDeleteService(client *Client) *KnowledgeDeleteService

NewKnowledgeDeleteService creates a new KnowledgeDeleteService

func (*KnowledgeDeleteService) Do

func (s *KnowledgeDeleteService) Do(ctx context.Context) (err error)

Do deletes the knowledge

func (*KnowledgeDeleteService) SetKnowledgeID

func (s *KnowledgeDeleteService) SetKnowledgeID(knowledgeID string) *KnowledgeDeleteService

SetKnowledgeID sets the knowledge id

type KnowledgeEditService

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

KnowledgeEditService edits a knowledge

func NewKnowledgeEditService

func NewKnowledgeEditService(client *Client) *KnowledgeEditService

NewKnowledgeEditService creates a new KnowledgeEditService

func (*KnowledgeEditService) Do

func (s *KnowledgeEditService) Do(ctx context.Context) (err error)

Do edits the knowledge

func (*KnowledgeEditService) SetDescription

func (s *KnowledgeEditService) SetDescription(description string) *KnowledgeEditService

SetDescription sets the description of the knowledge

func (*KnowledgeEditService) SetEmbeddingID

func (s *KnowledgeEditService) SetEmbeddingID(embeddingID int) *KnowledgeEditService

SetEmbeddingID sets the embedding id of the knowledge

func (*KnowledgeEditService) SetKnowledgeID

func (s *KnowledgeEditService) SetKnowledgeID(knowledgeID string) *KnowledgeEditService

SetKnowledgeID sets the knowledge id

func (*KnowledgeEditService) SetName

SetName sets the name of the knowledge

type KnowledgeItem

type KnowledgeItem struct {
	ID               string `json:"id"`
	Name             string `json:"name"`
	Description      string `json:"description"`
	Icon             string `json:"icon"`
	Background       string `json:"background"`
	EmbeddingID      int    `json:"embedding_id"`
	CustomIdentifier string `json:"custom_identifier"`
	WordNum          int64  `json:"word_num"`
	Length           int64  `json:"length"`
	DocumentSize     int64  `json:"document_size"`
}

KnowledgeItem is an item in the knowledge list

type KnowledgeListResponse

type KnowledgeListResponse struct {
	List  []KnowledgeItem `json:"list"`
	Total int             `json:"total"`
}

KnowledgeListResponse is the response of the KnowledgeListService

type KnowledgeListService

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

KnowledgeListService lists the knowledge

func NewKnowledgeListService

func NewKnowledgeListService(client *Client) *KnowledgeListService

NewKnowledgeListService creates a new KnowledgeListService

func (*KnowledgeListService) Do

Do lists the knowledge

func (*KnowledgeListService) SetPage

func (s *KnowledgeListService) SetPage(page int) *KnowledgeListService

SetPage sets the page of the knowledge list

func (*KnowledgeListService) SetSize

func (s *KnowledgeListService) SetSize(size int) *KnowledgeListService

SetSize sets the size of the knowledge list

type M

type M = map[string]any

M is a shorthand for map[string]any.

type StringOr

type StringOr[T any] struct {
	String *string
	Value  *T
}

StringOr is a struct that can be either a string or a value of type T.

func (StringOr[T]) MarshalJSON

func (f StringOr[T]) MarshalJSON() ([]byte, error)

func (*StringOr[T]) SetString

func (f *StringOr[T]) SetString(v string)

SetString sets the string value of the struct.

func (*StringOr[T]) SetValue

func (f *StringOr[T]) SetValue(v T)

SetValue sets the value of the struct.

func (*StringOr[T]) UnmarshalJSON

func (f *StringOr[T]) UnmarshalJSON(data []byte) error

type URLItem

type URLItem struct {
	URL string `json:"url,omitempty"`
}

URLItem is a struct that contains a URL.

type VideoGenerationResponse

type VideoGenerationResponse struct {
	RequestID  string `json:"request_id"`
	ID         string `json:"id"`
	Model      string `json:"model"`
	TaskStatus string `json:"task_status"`
}

VideoGenerationResponse is the response of the VideoGenerationService

type VideoGenerationService

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

VideoGenerationService creates a new video generation

func NewVideoGenerationService

func NewVideoGenerationService(client *Client) *VideoGenerationService

func (*VideoGenerationService) BatchBody

func (s *VideoGenerationService) BatchBody() any

func (*VideoGenerationService) BatchMethod

func (s *VideoGenerationService) BatchMethod() string

func (*VideoGenerationService) BatchURL

func (s *VideoGenerationService) BatchURL() string

func (*VideoGenerationService) Do

func (*VideoGenerationService) SetImageURL

func (s *VideoGenerationService) SetImageURL(imageURL string) *VideoGenerationService

SetImageURL sets the imageURL parameter

func (*VideoGenerationService) SetModel

SetModel sets the model parameter

func (*VideoGenerationService) SetPrompt

SetPrompt sets the prompt parameter

func (*VideoGenerationService) SetRequestID

func (s *VideoGenerationService) SetRequestID(requestID string) *VideoGenerationService

SetRequestID sets the requestID parameter

func (*VideoGenerationService) SetUserID

SetUserID sets the userID parameter

Jump to

Keyboard shortcuts

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