Categorygithub.com/sunny0826/go-chatglm
repositorypackage
0.1.0
Repository: https://github.com/sunny0826/go-chatglm.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

Go ChatGLM

Go Reference Go Report Card

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,
}

Example

Sync

package main

import (
	"fmt"
	"github.com/sunny0826/go-chatglm"
	"os"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	m := chatglm.ModelAPI{
		Model:       chatglm.ChatGLMLite,
		TopP:        0.7,
		Temperature: 0.9,
		Prompt: []map[string]interface{}{
			{"role": "user", "content": "你好"},
			{"role": "assistant", "content": "我是人工智能助手"},
			{"role": "user", "content": "你叫什么名字"},
			{"role": "assistant", "content": "我叫chatGLM"},
			{"role": "user", "content": "你都可以做些什么事"},
		},
	}
	resp, err := m.Invoke(apiKey)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(resp)
}

Async

Start async invoke job

package main

import (
	"fmt"
	"os"

	"github.com/sunny0826/go-chatglm"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	m := chatglm.ModelAPI{
		Model:       chatglm.ChatGLMLite,
		TopP:        0.7,
		Temperature: 1,
		Prompt: []map[string]interface{}{
			{"role": "user", "content": "你好"},
			{"role": "assistant", "content": "我是人工智能助手"},
			{"role": "user", "content": "你叫什么名字"},
			{"role": "assistant", "content": "我叫chatGLM"},
			{"role": "user", "content": "你都可以做些什么事"},
		},
	}
	resp, err := m.AsyncInvoke(apiKey)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(resp)
}

Response

map[code:200 data:map[request_id:7874899228181488751 task_id:75753966931688458417874899228181488752 task_status:PROCESSING] msg:操作成功 success:true]

Query async invoke result

package main

import (
	"fmt"
	"os"

	"github.com/sunny0826/go-chatglm"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	taskID := "75753966931688458417874899228181488752"
	m := chatglm.ModelAPI{Model: chatglm.ChatGLMLite}
	resp, err := m.QueryAsyncInvokeResult(apiKey, taskID)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(resp)
}