{"id":13651116,"url":"https://github.com/ConnectAI-E/Go-Wenxin","last_synced_at":"2025-04-22T22:30:30.514Z","repository":{"id":171366162,"uuid":"647197005","full_name":"ConnectAI-E/Go-Wenxin","owner":"ConnectAI-E","description":"🚗 ERNIE wrapper for Go  文心一言 Go语言SDK","archived":false,"fork":false,"pushed_at":"2023-06-22T09:31:00.000Z","size":86,"stargazers_count":24,"open_issues_count":3,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-20T01:33:06.068Z","etag":null,"topics":["baidubce","chatgpt","connect-ai","go","golang","streaming","wenxin","wenxinyiyan"],"latest_commit_sha":null,"homepage":"https://www.connectai-e.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ConnectAI-E.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-05-30T09:07:59.000Z","updated_at":"2024-10-20T02:58:59.000Z","dependencies_parsed_at":"2024-01-14T12:38:39.480Z","dependency_job_id":null,"html_url":"https://github.com/ConnectAI-E/Go-Wenxin","commit_stats":null,"previous_names":["connectai-e/go-wenxin"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConnectAI-E%2FGo-Wenxin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConnectAI-E%2FGo-Wenxin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConnectAI-E%2FGo-Wenxin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConnectAI-E%2FGo-Wenxin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ConnectAI-E","download_url":"https://codeload.github.com/ConnectAI-E/Go-Wenxin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250333855,"owners_count":21413469,"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":["baidubce","chatgpt","connect-ai","go","golang","streaming","wenxin","wenxinyiyan"],"created_at":"2024-08-02T02:00:45.349Z","updated_at":"2025-04-22T22:30:30.247Z","avatar_url":"https://github.com/ConnectAI-E.png","language":"Go","funding_links":[],"categories":["企联AI"],"sub_categories":[],"readme":"\n\u003cp align='center'\u003e\n    \u003cimg src='https://github.com/ConnectAI-E/go-wenxin/assets/50035229/84af1dfe-43c2-456b-85ce-52e787e034cb' alt='' width='1300'/\u003e\n\u003c/p\u003e\n\n\n## Baidu Wenxin SDK\n\n\u003e 百度文心一言 golang sdk \n\n### 功能及特点\n\n1. 全接口字段注释\n2. ChatCompletions 文心一言云服务\n3. ChatEbInstant ErnieBot-Lite\n4. 无缝对接官方文档：单轮问答、历史记忆问答、流返回\n5. 支持Swagger文档 和 ApiFox 文档\n\n### Swagger 文档\n- [打开在线Swagger编辑器](https://editor.swagger.io/)\n- 导入[Swagger Api 文档](./output/apis.swagger.yaml)\n\u003cimg width=\"1200\" alt=\"image\" src=\"https://github.com/ConnectAI-E/MidJourney-Web/assets/50035229/cab8814a-468c-41ab-94a3-b067e528f147\"\u003e\n\n### 使用方法\n\n1. 访问 https://console.bce.baidu.com/ai/#/ai/wenxinworkshop/app/list 并创建应用。\n2. 取 API Key 作为 ClientId，Secret Key 作为 ClientSecret。\n3. 使用 New 方法并根据传参说明生成 client。\n\n### 示例\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/ConnectAI-E/go-wenxin/baidubce\"\n\tai_customv1 \"github.com/ConnectAI-E/go-wenxin/gen/go/baidubce/ai_custom/v1\"\n\tbaidubcev1 \"github.com/ConnectAI-E/go-wenxin/gen/go/baidubce/v1\"\n)\n\n//init client\n\nfunc main() {\n\tctx := context.Background()\n\tvar opts []baidubce.Option\n\topts = append(opts, baidubce.WithTokenRequest(\u0026baidubcev1.TokenRequest{\n\t\tGrantType:    \"client_credentials\",\n\t\tClientId:     \"YOUR BAIDU_API Key\",\n\t\tClientSecret: \"YOUR BAIDU_SECRET Key\",\n\t}))\n\tclient, _ := baidubce.New(opts...)\n\n\t//chat\n\treq := \u0026ai_customv1.ChatCompletionsRequest{\n\t\tUser: \"feishu-user\",\n\t\tMessages: []*ai_customv1.Message{\n\t\t\t{Role: \"user\", Content: \"嗨\"},\n\t\t},\n\t}\n\tres, _ := client.ChatCompletions(ctx, req)\n\n\tfmt.Println(res.Result) // output: 嗨！有什么我可以帮助你的吗？\n}\n\n```\n\n\n### 快速上手:\n\n\u003cdetails\u003e\n\u003csummary\u003eErnieBot completion\u003c/summary\u003e\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/ConnectAI-E/go-wenxin/baidubce\"\n\tai_customv1 \"github.com/ConnectAI-E/go-wenxin/gen/go/baidubce/ai_custom/v1\"\n\tbaidubcev1 \"github.com/ConnectAI-E/go-wenxin/gen/go/baidubce/v1\"\n)\n\n//init client\n\nfunc main() {\n\tctx := context.Background()\n\tvar opts []baidubce.Option\n\topts = append(opts, baidubce.WithTokenRequest(\u0026baidubcev1.TokenRequest{\n\t\tGrantType:    \"client_credentials\",\n\t\tClientId:     \"YOUR BAIDU_API Key\",\n\t\tClientSecret: \"YOUR BAIDU_SECRET Key\",\n\t}))\n\tclient, _ := baidubce.New(opts...)\n\n\t//chat\n\treq := \u0026ai_customv1.ChatCompletionsRequest{\n\t\tUser: \"feishu-user\",\n\t\tMessages: []*ai_customv1.Message{\n\t\t\t{Role: \"user\", Content: \"嗨\"},\n\t\t},\n\t}\n\tres, _ := client.ChatCompletions(ctx, req)\n\n\tfmt.Println(res.Result) // output: 嗨！有什么我可以帮助你的吗？\n}\n```\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003eErnieBot stream completion\u003c/summary\u003e\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"github.com/ConnectAI-E/go-wenxin/baidubce\"\n\tai_customv1 \"github.com/ConnectAI-E/go-wenxin/gen/go/baidubce/ai_custom/v1\"\n\tbaidubcev1 \"github.com/ConnectAI-E/go-wenxin/gen/go/baidubce/v1\"\n\t\"io\"\n)\n\n//init client\n\nfunc main() {\n\tctx := context.Background()\n\tvar opts []baidubce.Option\n\topts = append(opts, baidubce.WithTokenRequest(\u0026baidubcev1.TokenRequest{\n\t\tGrantType:    \"client_credentials\",\n\t\tClientId:     \"YOUR BAIDU_API Key\",\n\t\tClientSecret: \"YOUR BAIDU_SECRET Key\",\n\t}))\n\tclient, _ := baidubce.New(opts...)\n\n\t//chat\n\treq := \u0026ai_customv1.ChatCompletionsRequest{\n\t\tStream: true,\n\t\tMessages: []*ai_customv1.Message{\n\t\t\t{Role: \"user\",\n\t\t\t\tContent: \"用鲁迅的口气写一封道歉信，给领导说对不起，我不该在会议上睡觉。200字左右\"},\n\t\t},\n\t}\n\tstream, _ := client.ChatCompletionsStream(ctx, req)\n\tdefer stream.CloseSend()\n\tfor {\n\t\tresponse, err := stream.Recv()\n\t\tif errors.Is(err, io.EOF) {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\tfmt.Println(err)\n\t\t\tbreak\n\t\t}\n\t\tfmt.Printf(response.Result)\n\t}\n\n}\n\n```\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003eErnieBot history stream completion\u003c/summary\u003e\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"github.com/ConnectAI-E/go-wenxin/baidubce\"\n\tai_customv1 \"github.com/ConnectAI-E/go-wenxin/gen/go/baidubce/ai_custom/v1\"\n\tbaidubcev1 \"github.com/ConnectAI-E/go-wenxin/gen/go/baidubce/v1\"\n\t\"io\"\n)\n\n//init client\n\nfunc main() {\n\tctx := context.Background()\n\tvar opts []baidubce.Option\n\topts = append(opts, baidubce.WithTokenRequest(\u0026baidubcev1.TokenRequest{\n\t\tGrantType:    \"client_credentials\",\n\t\tClientId:     \"YOUR BAIDU_API Key\",\n\t\tClientSecret: \"YOUR BAIDU_SECRET Key\",\n\t}))\n\tclient, _ := baidubce.New(opts...)\n\n\t//chat\n\treq := \u0026ai_customv1.ChatCompletionsRequest{\n\t\tStream: true,\n\t\tMessages: []*ai_customv1.Message{\n\t\t\t{Role: \"user\", Content: \"推荐三本书\"},\n\t\t\t{Role: \"assistant\", Content: \"1. 《活着》、《许三观卖血记》和《被掩埋的巨人》\\n2. 《小王子》、《浮生六记》和《人类简史》\\n3. 《百年孤独》、《查泰莱夫人的情人》和《1984》\"},\n\t\t\t{Role: \"user\",\n\t\t\t\tContent: \"从中选一本适合小朋友看的\"},\n\t\t},\n\t}\n\tstream, _ := client.ChatCompletionsStream(ctx, req)\n\tdefer stream.CloseSend()\n\tfor {\n\t\tresponse, err := stream.Recv()\n\t\tif errors.Is(err, io.EOF) {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\tfmt.Println(err)\n\t\t\tbreak\n\t\t}\n\t\tfmt.Printf(response.Result) //建议选择《小王子》一书，这本书的故事简单易懂，讲述了一个外星王子来到地球上的经历，以及他与一朵玫瑰、一只狐狸之间的奇遇。这本书的插图也很精美，有助于小朋友理解故事情节。此外，《小王子》一书中的寓言和哲理也对小朋友有一定启示作用，帮助他们理解人性\n\t}\n\n}\n\n\n```\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FConnectAI-E%2FGo-Wenxin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FConnectAI-E%2FGo-Wenxin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FConnectAI-E%2FGo-Wenxin/lists"}