chatglm

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

README

Go ChatGLM

Go Reference Go Report Card GitHub release (with filter)

Synchronization with official Python SDK feature & version numbers.

This library provides unofficial Go clients for ChatGLM API. We support:

Installation:

go get github.com/sunny0826/go-chatglm

Select Model

  • ChatGLMLite
  • ChatGLMStd
  • ChatGLMPro
m := chatglm.ModelAPI{
    Model:       chatglm.ChatGLMLite,
    // Model:       chatglm.ChatGLMStd,
    // Model:       chatglm.ChatGLMPro,
}

Examples

license

Apache License 2.0

Documentation

Index

Constants

View Source
const (
	BaseURL         = "https://open.bigmodel.cn/api/paas/v3/model-api"
	InvokeTypeSync  = "invoke"
	InvokeTypeAsync = "async-invoke"
	InvokeTypeSSE   = "sse-invoke"
	APITimeout      = 300 * time.Second
	ChatGLMLite     = "chatglm_lite"
	ChatGLMStd      = "chatglm_std"
	ChatGLMPro      = "chatglm_pro"
)
View Source
const (
	APITokenTTLSeconds = 3 * 60
	APIKeyPartCount    = 2
)

Variables

This section is empty.

Functions

func QueryAsyncInvokeResult

func QueryAsyncInvokeResult(apiKey, taskID string) (map[string]interface{}, error)

Types

type Event

type Event struct {
	ID    string
	Event string
	Data  string
	Retry int
	Meta  map[string]string
}

Event represents an SSE event.

type ModelAPI

type ModelAPI struct {
	Model       string
	Prompt      []map[string]interface{}
	TopP        float64
	Temperature float64
}

func (ModelAPI) AsyncInvoke

func (m ModelAPI) AsyncInvoke(apiKey string) (map[string]interface{}, error)

func (ModelAPI) Invoke

func (m ModelAPI) Invoke(apiKey string) (map[string]interface{}, error)

func (ModelAPI) SSEInvoke

func (m ModelAPI) SSEInvoke(apiKey string) (*SSEClient, error)

type SSEClient

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

SSEClient represents a Server-Sent Events (SSE) client.

func NewSSEClient

func NewSSEClient(eventSource io.Reader, charEnc string) *SSEClient

NewSSEClient creates a new SSEClient instance.

func (*SSEClient) ReadEvents

func (c *SSEClient) ReadEvents() <-chan Event

ReadEvents reads SSE events from the event source and returns them as a channel.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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