{"id":21301969,"url":"https://github.com/liudding/go-llm-api","last_synced_at":"2025-07-11T20:31:29.695Z","repository":{"id":197323821,"uuid":"697637193","full_name":"liudding/go-llm-api","owner":"liudding","description":"百度文心一言千帆 GO SDK；智谱 AI、腾讯混元、讯飞星火、商汤日日新、MinMax","archived":false,"fork":false,"pushed_at":"2024-04-20T04:36:32.000Z","size":60,"stargazers_count":12,"open_issues_count":5,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T08:41:33.195Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/liudding.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-09-28T06:57:44.000Z","updated_at":"2024-08-27T00:17:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"f143d9c1-0109-449e-a1ae-92a507aed891","html_url":"https://github.com/liudding/go-llm-api","commit_stats":null,"previous_names":["liudding/go-llm-api"],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/liudding/go-llm-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liudding%2Fgo-llm-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liudding%2Fgo-llm-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liudding%2Fgo-llm-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liudding%2Fgo-llm-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liudding","download_url":"https://codeload.github.com/liudding/go-llm-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liudding%2Fgo-llm-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264892264,"owners_count":23679262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-21T15:53:39.802Z","updated_at":"2025-07-11T20:31:26.760Z","avatar_url":"https://github.com/liudding.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# go-llm-api\r\n\r\n\r\n百度千帆、智谱 Ai、腾讯混元、讯飞星火、商汤日日新、MinMax 等的大语言模型非官方 API，支持以下模型：\r\n\r\n* 百度千帆平台所有模型\r\n* 智谱 AI 模型\r\n* 腾讯混元\r\n* 等等\r\n\r\n## Installation\r\n\r\n```\r\ngo get github.com/liudding/go-llm-api\r\n```\r\n要求 go 版本最低是 1.18.\r\n\r\n\r\n## Usage\r\n\r\n### 百度千帆 Ernie:\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"context\"\r\n\t\"fmt\"\r\n\t \"github.com/liudding/github.com/liudding/go-llm-api/baidu\"\r\n)\r\n\r\nfunc main() {\r\n\tclient := NewClient(\"xxxx\", \"yyyy\", true)\r\n\tstream, err := client.CreateChatCompletionStream(context.Background(), ChatCompletionRequest{\r\n\t\tMessages: []ChatCompletionMessage{\r\n\t\t\t{\r\n\t\t\t\tRole:    ChatMessageRoleUser,\r\n\t\t\t\tContent: \"Hello!\",\r\n\t\t\t},\r\n\t\t},\r\n\t\tStream: true,\r\n\t})\r\n\r\n\tdefer stream.Close()\r\n\r\n\tfmt.Println(\"Stream response: \")\r\n\tfor {\r\n\t\tresponse, err := stream.Recv()\r\n\t\tif errors.Is(err, io.EOF) {\r\n\t\t\tfmt.Printf(\"\\nStream finished: %d %s\\n\", response.ErrorCode, response.ErrorMsg)\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tif err != nil {\r\n\t\t\tfmt.Printf(\"\\nStream error: %v\\n\", err)\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tfmt.Printf(\"error: %s\\n\", response.ErrorMsg)\r\n\t\tfmt.Printf(\"resp: %s\\n\", response.Result)\r\n\t}\r\n}\r\n\r\n```\r\n\r\n### 智谱\r\n\r\n```go\r\ntoken, _ := zhipu.GenerateAuthToken(l.svcCtx.Config.ZhipuAi.Key, time.Minute*60)\r\nclient := zhipu.NewClient(token)\r\n\r\nstream, err := client.CreateChatCompletionStream(context.Background(), zhipu.ChatCompletionRequest{\r\n\tPrompt: []zhipu.ChatCompletionMessage{\r\n\t\t{\r\n\t\t\tRole:    zhipu.ChatMessageRoleUser,\r\n\t\t\tContent: prompt,\r\n\t\t},\r\n\t},\r\n\tTemperature: 0.7,\r\n\t//RequestId:   \"\",\r\n\tIncremental: true,\r\n\t//ReturnType:  \"\",\r\n\t//Ref:         ChatCompletionRef{},\r\n}, zhipu.ModelTurbo)\r\n\r\ndefer stream.Close()\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliudding%2Fgo-llm-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliudding%2Fgo-llm-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliudding%2Fgo-llm-api/lists"}