zhipu

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: MIT Imports: 14 Imported by: 3

README

zhipu

Go Reference go codecov

中文文档

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"

	// 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"

	// ResponseFormat
	ResponseFormatText       = "text"
	ResponseFormatJSONObject = "json_object"
)
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 added in v0.1.2

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 added in v0.1.2

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

AsyncResultService creates a new async result get service

func NewAsyncResultService added in v0.1.2

func NewAsyncResultService(client *Client) *AsyncResultService

NewAsyncResultService creates a new async result get service

func (*AsyncResultService) Do added in v0.1.2

func (*AsyncResultService) SetID added in v0.1.2

SetID sets the id parameter

type AsyncResultVideo added in v0.1.2

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

AsyncResultVideo is the video result of the AsyncResultService

type BatchCancelService added in v0.0.5

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

BatchCancelService is a service to cancel a batch.

func NewBatchCancelService added in v0.1.0

func NewBatchCancelService(client *Client) *BatchCancelService

NewBatchCancelService creates a new BatchCancelService.

func (*BatchCancelService) Do added in v0.0.5

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

Do executes the batch cancel service.

func (*BatchCancelService) SetBatchID added in v0.0.5

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

SetBatchID sets the batch id for the batch cancel service.

type BatchCreateService added in v0.0.5

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

BatchCreateService is a service to create a batch.

func NewBatchCreateService added in v0.1.0

func NewBatchCreateService(client *Client) *BatchCreateService

NewBatchCreateService creates a new BatchCreateService.

func (*BatchCreateService) Do added in v0.0.5

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

Do executes the batch create service.

func (*BatchCreateService) SetCompletionWindow added in v0.0.5

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

SetCompletionWindow sets the completion window for the batch.

func (*BatchCreateService) SetEndpoint added in v0.0.5

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

SetEndpoint sets the endpoint for the batch.

func (*BatchCreateService) SetInputFileID added in v0.0.5

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

SetInputFileID sets the input file id for the batch.

func (*BatchCreateService) SetMetadata added in v0.0.5

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

SetMetadata sets the metadata for the batch.

type BatchFileWriter added in v0.0.5

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

BatchFileWriter is a writer for batch files.

func NewBatchFileWriter added in v0.0.5

func NewBatchFileWriter(w io.Writer) *BatchFileWriter

NewBatchFileWriter creates a new BatchFileWriter.

func (*BatchFileWriter) Write added in v0.0.5

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

Write writes a batch file.

type BatchGetResponse added in v0.1.0

type BatchGetResponse = BatchItem

BatchGetResponse represents the response of the batch get service.

type BatchGetService added in v0.0.5

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

BatchGetService is a service to get a batch.

func NewBatchGetService added in v0.1.0

func NewBatchGetService(client *Client) *BatchGetService

NewBatchGetService creates a new BatchGetService.

func (*BatchGetService) Do added in v0.0.5

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

Do executes the batch get service.

func (*BatchGetService) SetBatchID added in v0.0.5

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

SetBatchID sets the batch id for the batch get service.

type BatchItem added in v0.0.5

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 added in v0.0.5

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 added in v0.0.5

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

BatchListService is a service to list batches.

func NewBatchListService added in v0.1.0

func NewBatchListService(client *Client) *BatchListService

NewBatchListService creates a new BatchListService.

func (*BatchListService) Do added in v0.0.5

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

Do executes the batch list service.

func (*BatchListService) SetAfter added in v0.0.5

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

SetAfter sets the after cursor for the batch list service.

func (*BatchListService) SetLimit added in v0.0.5

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

SetLimit sets the limit for the batch list service.

type BatchRequestCounts added in v0.0.5

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 added in v0.0.6

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 added in v0.0.6

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

BatchResultReader reads batch results.

func NewBatchResultReader added in v0.0.6

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

NewBatchResultReader creates a new BatchResultReader.

func (*BatchResultReader[T]) Read added in v0.0.6

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

Read reads a batch result.

type BatchResultResponse added in v0.0.6

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

BatchResultResponse is the response of a batch result.

type BatchSupport added in v0.0.5

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 added in v0.0.3

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

type ChatCompletionMeta added in v0.0.4

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 added in v0.0.3

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

type ChatCompletionMultiMessage added in v0.0.3

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 added in v0.1.0

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 added in v0.0.5

func (s *ChatCompletionService) BatchBody() any

func (*ChatCompletionService) BatchMethod added in v0.0.5

func (s *ChatCompletionService) BatchMethod() string

func (*ChatCompletionService) BatchURL added in v0.0.5

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 added in v0.0.4

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) SetResponseFormat added in v0.1.5

func (s *ChatCompletionService) SetResponseFormat(format string) *ChatCompletionService

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 added in v0.1.1

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

ChatCompletionToolCallCodeInterpreter is the code interpreter for chat completion tool call

type ChatCompletionToolCallCodeInterpreterOutput added in v0.1.1

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 added in v0.1.1

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

ChatCompletionToolCallDrawingTool is the drawing tool for chat completion tool call

type ChatCompletionToolCallDrawingToolOutput added in v0.1.1

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 added in v0.1.1

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

ChatCompletionToolCallWebBrowser is the web browser for chat completion tool call

type ChatCompletionToolCallWebBrowserOutput added in v0.1.1

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 added in v0.1.1

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

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

type ChatCompletionToolDrawingTool added in v0.1.1

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 added in v0.1.1

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 added in v0.1.2

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

AsyncResult creates a new async result get service

func (*Client) BatchCancel added in v0.1.0

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

BatchCancel creates a new BatchCancelService.

func (*Client) BatchCreate added in v0.1.0

func (c *Client) BatchCreate() *BatchCreateService

BatchCreate creates a new BatchCreateService.

func (*Client) BatchGet added in v0.1.0

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

BatchGet creates a new BatchGetService.

func (*Client) BatchList added in v0.1.0

func (c *Client) BatchList() *BatchListService

BatchList creates a new BatchListService.

func (*Client) ChatCompletion added in v0.1.0

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

ChatCompletion creates a new ChatCompletionService.

func (*Client) Embedding added in v0.1.0

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

Embedding embeds a list of text into a vector space.

func (*Client) FileCreate added in v0.1.0

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

FileCreate creates a new FileCreateService.

func (*Client) FileDelete added in v0.1.0

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

FileDeleteService creates a new FileDeleteService.

func (*Client) FileDownload added in v0.1.0

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

FileDownload creates a new FileDownloadService.

func (*Client) FileEdit added in v0.1.0

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

FileEditService creates a new FileEditService.

func (*Client) FileGet added in v0.1.0

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

FileGetService creates a new FileGetService.

func (*Client) FileList added in v0.1.0

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

FileList creates a new FileListService.

func (*Client) FineTuneCancel added in v0.1.0

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

FineTuneCancel creates a new fine tune cancel service

func (*Client) FineTuneCreate added in v0.1.0

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

FineTuneCreate creates a new fine tune create service

func (*Client) FineTuneDelete added in v0.1.0

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

FineTuneDelete creates a new fine tune delete service

func (*Client) FineTuneEventList added in v0.1.0

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

FineTuneEventList creates a new fine tune event list service

func (*Client) FineTuneGet added in v0.1.0

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

FineTuneGet creates a new fine tune get service

func (*Client) FineTuneList added in v0.1.0

func (c *Client) FineTuneList() *FineTuneListService

FineTuneList creates a new fine tune list service

func (*Client) ImageGeneration added in v0.1.0

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

ImageGeneration creates a new image generation service

func (*Client) KnowledgeCapacity added in v0.1.0

func (c *Client) KnowledgeCapacity() *KnowledgeCapacityService

KnowledgeGet creates a new knowledge get service

func (*Client) KnowledgeCreate added in v0.1.0

func (c *Client) KnowledgeCreate() *KnowledgeCreateService

KnowledgeCreate creates a new knowledge create service

func (*Client) KnowledgeDelete added in v0.1.0

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

KnowledgeDelete creates a new knowledge delete service

func (*Client) KnowledgeEdit added in v0.1.0

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

KnowledgeEdit creates a new knowledge edit service

func (*Client) KnowledgeList added in v0.1.0

func (c *Client) KnowledgeList() *KnowledgeListService

KnowledgeList list all the knowledge

func (*Client) VideoGeneration added in v0.1.2

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 added in v0.0.4

func WithHTTPClient(client *http.Client) ClientOption

WithHTTPClient set the http client of the client

func WithRestyClient added in v0.1.3

func WithRestyClient(client *resty.Client) ClientOption

WithRestyClient set the resty client of the client

type EmbeddingData added in v0.0.3

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

EmbeddingData is the data for each embedding.

type EmbeddingResponse added in v0.0.3

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 added in v0.0.3

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

EmbeddingService embeds a list of text into a vector space.

func NewEmbeddingService added in v0.1.0

func NewEmbeddingService(client *Client) *EmbeddingService

NewEmbeddingService creates a new EmbeddingService.

func (*EmbeddingService) BatchBody added in v0.0.5

func (s *EmbeddingService) BatchBody() any

func (*EmbeddingService) BatchMethod added in v0.0.5

func (s *EmbeddingService) BatchMethod() string

func (*EmbeddingService) BatchURL added in v0.0.5

func (s *EmbeddingService) BatchURL() string

func (*EmbeddingService) Do added in v0.0.3

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

func (*EmbeddingService) SetInput added in v0.0.3

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

SetInput sets the input text to embed.

func (*EmbeddingService) SetModel added in v0.0.3

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

SetModel sets the model to use for the embedding.

type FileCreateFineTuneResponse added in v0.0.5

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 added in v0.0.5

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

FileCreateKnowledgeFailedInfo is the failed info of the FileCreateKnowledgeResponse.

type FileCreateKnowledgeResponse added in v0.0.5

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

FileCreateKnowledgeResponse is the response of the FileCreateService.

type FileCreateKnowledgeSuccessInfo added in v0.0.5

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

FileCreateKnowledgeSuccessInfo is the success info of the FileCreateKnowledgeResponse.

type FileCreateResponse added in v0.0.5

type FileCreateResponse struct {
	FileCreateFineTuneResponse
	FileCreateKnowledgeResponse
}

FileCreateResponse is the response of the FileCreateService.

type FileCreateService added in v0.0.5

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

FileCreateService is a service to create a file.

func NewFileCreateService added in v0.1.0

func NewFileCreateService(client *Client) *FileCreateService

NewFileCreateService creates a new FileCreateService.

func (*FileCreateService) Do added in v0.0.5

Do makes the request.

func (*FileCreateService) SetCustomSeparator added in v0.0.5

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

SetCustomSeparator sets the custom_separator parameter of the FileCreateService.

func (*FileCreateService) SetFile added in v0.0.5

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

SetFile sets the file parameter of the FileCreateService.

func (*FileCreateService) SetKnowledgeID added in v0.0.5

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

SetKnowledgeID sets the knowledge_id parameter of the FileCreateService.

func (*FileCreateService) SetLocalFile added in v0.0.5

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

SetLocalFile sets the local_file parameter of the FileCreateService.

func (*FileCreateService) SetPurpose added in v0.0.5

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

SetPurpose sets the purpose parameter of the FileCreateService.

func (*FileCreateService) SetSentenceSize added in v0.0.5

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

SetSentenceSize sets the sentence_size parameter of the FileCreateService.

type FileDeleteService added in v0.0.5

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

FileDeleteService is a service to delete a file.

func NewFileDeleteService added in v0.1.0

func NewFileDeleteService(client *Client) *FileDeleteService

NewFileDeleteService creates a new FileDeleteService.

func (*FileDeleteService) Do added in v0.0.5

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

Do makes the request.

func (*FileDeleteService) SetDocumentID deprecated added in v0.1.0

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

Deprecated: use SetFileID instead.

func (*FileDeleteService) SetFileID added in v0.1.4

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

SetFileID sets the file_id parameter of the FileDeleteService.

type FileDownloadService added in v0.0.5

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

FileDownloadService is a service to download a file.

func NewFileDownloadService added in v0.1.0

func NewFileDownloadService(client *Client) *FileDownloadService

NewFileDownloadService creates a new FileDownloadService.

func (*FileDownloadService) Do added in v0.0.5

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

Do makes the request.

func (*FileDownloadService) SetFileID added in v0.1.0

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

SetFileID sets the file_id parameter of the FileDownloadService.

func (*FileDownloadService) SetOutput added in v0.0.5

SetOutput sets the output parameter of the FileDownloadService.

func (*FileDownloadService) SetOutputFile added in v0.0.5

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

SetOutputFile sets the output_file parameter of the FileDownloadService.

type FileEditService added in v0.0.5

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

FileEditService is a service to edit a file.

func NewFileEditService added in v0.1.0

func NewFileEditService(client *Client) *FileEditService

NewFileEditService creates a new FileEditService.

func (*FileEditService) Do added in v0.0.5

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

Do makes the request.

func (*FileEditService) SetCustomSeparator added in v0.0.5

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

SetSentenceSize sets the sentence_size parameter of the FileEditService.

func (*FileEditService) SetDocumentID added in v0.1.0

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

SetDocumentID sets the document_id parameter of the FileEditService.

func (*FileEditService) SetKnowledgeType added in v0.0.5

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

SetKnowledgeType sets the knowledge_type parameter of the FileEditService.

func (*FileEditService) SetSentenceSize added in v0.0.5

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

SetSentenceSize sets the sentence_size parameter of the FileEditService.

type FileFailInfo added in v0.0.5

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

FileFailInfo is the failed info of the FileListKnowledgeItem.

type FileGetResponse added in v0.0.5

type FileGetResponse = FileListKnowledgeItem

FileGetResponse is the response of the FileGetService.

type FileGetService added in v0.0.5

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

FileGetService is a service to get a file.

func NewFileGetService added in v0.1.0

func NewFileGetService(client *Client) *FileGetService

NewFileGetService creates a new FileGetService.

func (*FileGetService) Do added in v0.0.5

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

Do makes the request.

func (*FileGetService) SetDocumentID added in v0.1.0

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

SetDocumentID sets the document_id parameter of the FileGetService.

type FileListFineTuneItem added in v0.0.5

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 added in v0.0.5

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

FileListFineTuneResponse is the response of the FileListService.

type FileListKnowledgeItem added in v0.0.5

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 added in v0.0.5

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

FileListKnowledgeResponse is the response of the FileListService.

type FileListResponse added in v0.0.5

type FileListResponse struct {
	FileListKnowledgeResponse
	FileListFineTuneResponse
}

FileListResponse is the response of the FileListService.

type FileListService added in v0.0.5

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

FileListService is a service to list files.

func NewFileListService added in v0.1.0

func NewFileListService(client *Client) *FileListService

NewFileListService creates a new FileListService.

func (*FileListService) Do added in v0.0.5

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

Do makes the request.

func (*FileListService) SetAfter added in v0.0.5

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

SetAfter sets the after parameter of the FileListService.

func (*FileListService) SetKnowledgeID added in v0.0.5

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

SetKnowledgeID sets the knowledge_id parameter of the FileListService.

func (*FileListService) SetLimit added in v0.0.5

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

SetLimit sets the limit parameter of the FileListService.

func (*FileListService) SetOrder added in v0.0.5

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

SetOrder sets the order parameter of the FileListService.

func (*FileListService) SetPage added in v0.0.5

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

SetPage sets the page parameter of the FileListService.

func (*FileListService) SetPurpose added in v0.0.5

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

SetPurpose sets the purpose parameter of the FileListService.

type FineTuneCancelService added in v0.0.6

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

FineTuneCancelService creates a new fine tune cancel

func NewFineTuneCancelService added in v0.1.0

func NewFineTuneCancelService(client *Client) *FineTuneCancelService

NewFineTuneCancelService creates a new FineTuneCancelService

func (*FineTuneCancelService) Do added in v0.0.6

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

Do makes the request

func (*FineTuneCancelService) SetJobID added in v0.0.6

SetJobID sets the jobID parameter

type FineTuneCreateResponse added in v0.0.6

type FineTuneCreateResponse = FineTuneItem

FineTuneCreateResponse is the response of the FineTuneCreateService

type FineTuneCreateService added in v0.0.6

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

FineTuneCreateService creates a new fine tune

func NewFineTuneCreateService added in v0.1.0

func NewFineTuneCreateService(client *Client) *FineTuneCreateService

NewFineTuneCreateService creates a new FineTuneCreateService

func (*FineTuneCreateService) Do added in v0.0.6

Do makes the request

func (*FineTuneCreateService) SetBatchSize added in v0.0.6

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

SetBatchSize sets the batchSize parameter

func (*FineTuneCreateService) SetBatchSizeAuto added in v0.0.6

func (s *FineTuneCreateService) SetBatchSizeAuto() *FineTuneCreateService

SetBatchSizeAuto sets the batchSize parameter to auto

func (*FineTuneCreateService) SetLearningRateMultiplier added in v0.0.6

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

SetLearningRateMultiplier sets the learningRateMultiplier parameter

func (*FineTuneCreateService) SetLearningRateMultiplierAuto added in v0.0.6

func (s *FineTuneCreateService) SetLearningRateMultiplierAuto() *FineTuneCreateService

SetLearningRateMultiplierAuto sets the learningRateMultiplier parameter to auto

func (*FineTuneCreateService) SetModel added in v0.0.6

SetModel sets the model parameter

func (*FineTuneCreateService) SetNEpochs added in v0.0.6

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

SetNEpochs sets the nEpochs parameter

func (*FineTuneCreateService) SetNEpochsAuto added in v0.0.6

func (s *FineTuneCreateService) SetNEpochsAuto() *FineTuneCreateService

SetNEpochsAuto sets the nEpochs parameter to auto

func (*FineTuneCreateService) SetRequestID added in v0.0.6

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

SetRequestID sets the requestID parameter

func (*FineTuneCreateService) SetSuffix added in v0.0.6

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

SetSuffix sets the suffix parameter

func (*FineTuneCreateService) SetTrainingFile added in v0.0.6

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

SetTrainingFile sets the trainingFile parameter

func (*FineTuneCreateService) SetValidationFile added in v0.0.6

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

SetValidationFile sets the validationFile parameter

type FineTuneDeleteService added in v0.0.6

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

FineTuneDeleteService creates a new fine tune delete

func NewFineTuneDeleteService added in v0.1.0

func NewFineTuneDeleteService(client *Client) *FineTuneDeleteService

NewFineTuneDeleteService creates a new FineTuneDeleteService

func (*FineTuneDeleteService) Do added in v0.0.6

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

Do makes the request

func (*FineTuneDeleteService) SetJobID added in v0.0.6

SetJobID sets the jobID parameter

type FineTuneEventData added in v0.0.6

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 added in v0.0.6

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 added in v0.0.6

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 added in v0.0.6

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

FineTuneEventListService creates a new fine tune event list

func NewFineTuneEventListService added in v0.1.0

func NewFineTuneEventListService(client *Client) *FineTuneEventListService

NewFineTuneEventListService creates a new FineTuneEventListService

func (*FineTuneEventListService) Do added in v0.0.6

Do makes the request

func (*FineTuneEventListService) SetAfter added in v0.0.6

SetAfter sets the after parameter

func (*FineTuneEventListService) SetJobID added in v0.0.6

SetJobID sets the jobID parameter

func (*FineTuneEventListService) SetLimit added in v0.0.6

SetLimit sets the limit parameter

type FineTuneGetService added in v0.0.6

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

FineTuneGetService creates a new fine tune get

func NewFineTuneGetService added in v0.1.0

func NewFineTuneGetService(client *Client) *FineTuneGetService

NewFineTuneGetService creates a new FineTuneGetService

func (*FineTuneGetService) Do added in v0.0.6

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

Do makes the request

func (*FineTuneGetService) SetJobID added in v0.0.6

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

SetJobID sets the jobID parameter

type FineTuneItem added in v0.0.6

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 added in v0.0.6

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

FineTuneListResponse is the response of the FineTuneListService

type FineTuneListService added in v0.0.6

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

FineTuneListService creates a new fine tune list

func NewFineTuneListService added in v0.1.0

func NewFineTuneListService(client *Client) *FineTuneListService

NewFineTuneListService creates a new FineTuneListService

func (*FineTuneListService) Do added in v0.0.6

Do makes the request

func (*FineTuneListService) SetAfter added in v0.0.6

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

SetAfter sets the after parameter

func (*FineTuneListService) SetLimit added in v0.0.6

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

SetLimit sets the limit parameter

type IDItem added in v0.0.6

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

IDItem is a struct that contains an ID.

type ImageGenerationResponse added in v0.0.3

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

ImageGenerationResponse is the response of the ImageGenerationService

type ImageGenerationService added in v0.0.3

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

ImageGenerationService creates a new image generation

func NewImageGenerationService added in v0.1.0

func NewImageGenerationService(client *Client) *ImageGenerationService

NewImageGenerationService creates a new ImageGenerationService

func (*ImageGenerationService) BatchBody added in v0.0.5

func (s *ImageGenerationService) BatchBody() any

func (*ImageGenerationService) BatchMethod added in v0.0.5

func (s *ImageGenerationService) BatchMethod() string

func (*ImageGenerationService) BatchURL added in v0.0.5

func (s *ImageGenerationService) BatchURL() string

func (*ImageGenerationService) Do added in v0.0.3

func (*ImageGenerationService) SetModel added in v0.0.3

SetModel sets the model parameter

func (*ImageGenerationService) SetPrompt added in v0.0.3

SetPrompt sets the prompt parameter

func (*ImageGenerationService) SetUserID added in v0.0.3

SetUserID sets the userID parameter

type KnowledgeCapacityItem added in v0.1.0

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

KnowledgeCapacityItem is an item in the knowledge capacity

type KnowledgeCapacityResponse added in v0.1.0

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

KnowledgeCapacityResponse is the response of the KnowledgeCapacityService

type KnowledgeCapacityService added in v0.1.0

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

KnowledgeCapacityService query the capacity of the knowledge

func NewKnowledgeCapacityService added in v0.1.0

func NewKnowledgeCapacityService(client *Client) *KnowledgeCapacityService

SetKnowledgeID sets the knowledge id

func (*KnowledgeCapacityService) Do added in v0.1.0

Do query the capacity of the knowledge

type KnowledgeCreateResponse added in v0.0.6

type KnowledgeCreateResponse = IDItem

KnowledgeCreateResponse is the response of the KnowledgeCreateService

type KnowledgeCreateService added in v0.0.6

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

KnowledgeCreateService creates a new knowledge

func NewKnowledgeCreateService added in v0.1.0

func NewKnowledgeCreateService(client *Client) *KnowledgeCreateService

NewKnowledgeCreateService creates a new KnowledgeCreateService

func (*KnowledgeCreateService) Do added in v0.0.6

Do creates the knowledge

func (*KnowledgeCreateService) SetDescription added in v0.0.6

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

SetDescription sets the description of the knowledge

func (*KnowledgeCreateService) SetEmbeddingID added in v0.0.6

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

SetEmbeddingID sets the embedding id of the knowledge

func (*KnowledgeCreateService) SetName added in v0.0.6

SetName sets the name of the knowledge

type KnowledgeDeleteService added in v0.0.6

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

KnowledgeDeleteService deletes a knowledge

func NewKnowledgeDeleteService added in v0.1.0

func NewKnowledgeDeleteService(client *Client) *KnowledgeDeleteService

NewKnowledgeDeleteService creates a new KnowledgeDeleteService

func (*KnowledgeDeleteService) Do added in v0.0.6

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

Do deletes the knowledge

func (*KnowledgeDeleteService) SetKnowledgeID added in v0.0.6

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

SetKnowledgeID sets the knowledge id

type KnowledgeEditService added in v0.0.6

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

KnowledgeEditService edits a knowledge

func NewKnowledgeEditService added in v0.1.0

func NewKnowledgeEditService(client *Client) *KnowledgeEditService

NewKnowledgeEditService creates a new KnowledgeEditService

func (*KnowledgeEditService) Do added in v0.0.6

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

Do edits the knowledge

func (*KnowledgeEditService) SetDescription added in v0.0.6

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

SetDescription sets the description of the knowledge

func (*KnowledgeEditService) SetEmbeddingID added in v0.0.6

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

SetEmbeddingID sets the embedding id of the knowledge

func (*KnowledgeEditService) SetKnowledgeID added in v0.1.0

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

SetKnowledgeID sets the knowledge id

func (*KnowledgeEditService) SetName added in v0.0.6

SetName sets the name of the knowledge

type KnowledgeItem added in v0.0.6

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 added in v0.0.6

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

KnowledgeListResponse is the response of the KnowledgeListService

type KnowledgeListService added in v0.0.6

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

KnowledgeListService lists the knowledge

func NewKnowledgeListService added in v0.1.0

func NewKnowledgeListService(client *Client) *KnowledgeListService

NewKnowledgeListService creates a new KnowledgeListService

func (*KnowledgeListService) Do added in v0.0.6

Do lists the knowledge

func (*KnowledgeListService) SetPage added in v0.0.6

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

SetPage sets the page of the knowledge list

func (*KnowledgeListService) SetSize added in v0.0.6

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 added in v0.0.6

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 added in v0.0.6

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

func (*StringOr[T]) SetString added in v0.0.6

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

SetString sets the string value of the struct.

func (*StringOr[T]) SetValue added in v0.0.6

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

SetValue sets the value of the struct.

func (*StringOr[T]) UnmarshalJSON added in v0.0.6

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

type URLItem added in v0.1.0

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

URLItem is a struct that contains a URL.

type VideoGenerationResponse added in v0.1.2

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 added in v0.1.2

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

VideoGenerationService creates a new video generation

func NewVideoGenerationService added in v0.1.2

func NewVideoGenerationService(client *Client) *VideoGenerationService

func (*VideoGenerationService) BatchBody added in v0.1.2

func (s *VideoGenerationService) BatchBody() any

func (*VideoGenerationService) BatchMethod added in v0.1.2

func (s *VideoGenerationService) BatchMethod() string

func (*VideoGenerationService) BatchURL added in v0.1.2

func (s *VideoGenerationService) BatchURL() string

func (*VideoGenerationService) Do added in v0.1.2

func (*VideoGenerationService) SetImageURL added in v0.1.2

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

SetImageURL sets the imageURL parameter

func (*VideoGenerationService) SetModel added in v0.1.2

SetModel sets the model parameter

func (*VideoGenerationService) SetPrompt added in v0.1.2

SetPrompt sets the prompt parameter

func (*VideoGenerationService) SetRequestID added in v0.1.2

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

SetRequestID sets the requestID parameter

func (*VideoGenerationService) SetUserID added in v0.1.2

SetUserID sets the userID parameter

Jump to

Keyboard shortcuts

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