ChatGLM golang restapi sdk
go get -u github.com/leverly/ChatGLM
import ( "github.com/leverly/ChatGLM/client" )
proxy = client.NewChatGLMClient("XXX.XXX", 30*time.Second)
prompt := []client.Message{ {Role: "user", Content: "hello world"}, }
response, err := proxy.Invoke("chatglm_6b", 0.2, prompt)
taskId, err := proxy.AsyncInvoke("chatglm_6b", 0.2, prompt)
response, err := proxy.AsyncInvokeTask("chatglm_6b", taskId)
type StreamCallback struct { }
func (s *StreamCallback) OnData(data *client.SSEInvokeResponse) { fmt.Print(data.Data) }
func (s *StreamCallback) OnFinish(data *client.SSEInvokeResponse) { fmt.Println(data.Data) }
err := proxy.SSEInvoke("chatglm_6b", 0.2, prompt, &StreamCallback{})