{"id":13414071,"url":"https://github.com/otiai10/openaigo","last_synced_at":"2025-04-04T15:08:27.307Z","repository":{"id":64589389,"uuid":"576558678","full_name":"otiai10/openaigo","owner":"otiai10","description":"OpenAI GPT3/3.5 and GPT4 ChatGPT API Client Library for Go, simple, less dependencies, and well-tested","archived":false,"fork":false,"pushed_at":"2024-05-14T00:05:14.000Z","size":220,"stargazers_count":293,"open_issues_count":2,"forks_count":37,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-28T14:06:39.408Z","etag":null,"topics":["chatgpt","chatgpt-api","chatgpt3","go","golang","openai","openai-api"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/otiai10/openaigo","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/otiai10.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-10T08:13:35.000Z","updated_at":"2025-03-15T23:21:37.000Z","dependencies_parsed_at":"2024-05-08T11:26:52.113Z","dependency_job_id":"b5a9f19c-7818-4d87-8ee1-fb47b0fdc898","html_url":"https://github.com/otiai10/openaigo","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otiai10%2Fopenaigo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otiai10%2Fopenaigo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otiai10%2Fopenaigo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otiai10%2Fopenaigo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/otiai10","download_url":"https://codeload.github.com/otiai10/openaigo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198459,"owners_count":20900080,"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":["chatgpt","chatgpt-api","chatgpt3","go","golang","openai","openai-api"],"created_at":"2024-07-30T20:01:56.867Z","updated_at":"2025-04-04T15:08:27.290Z","avatar_url":"https://github.com/otiai10.png","language":"Go","funding_links":[],"categories":["Developer Libraries, SDKs, and APIs","Third-party APIs","Go","CLIs","Golang","SDK, Libraries, Frameworks","第三方api"],"sub_categories":["Golang","Utility/Miscellaneous","Golang library, sdk or frameworks","实用程序/Miscellaneous"],"readme":"# openaigo\n\n[![Go](https://github.com/otiai10/openaigo/actions/workflows/go.yml/badge.svg)](https://github.com/otiai10/openaigo/actions/workflows/go.yml)\n[![CodeQL](https://github.com/otiai10/openaigo/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/otiai10/openaigo/actions/workflows/codeql-analysis.yml)\n[![App Test over API](https://github.com/otiai10/openaigo/actions/workflows/api.yml/badge.svg)](https://github.com/otiai10/openaigo/actions/workflows/api.yml)\n[![License](https://img.shields.io/github/license/otiai10/openaigo)](https://github.com/otiai10/openaigo/blob/main/LICENSE)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fotiai10%2Fopenaigo.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fotiai10%2Fopenaigo?ref=badge_shield)\n\u003cbr\u003e[![Maintainability](https://api.codeclimate.com/v1/badges/20c434b47940ce8ed511/maintainability)](https://codeclimate.com/github/otiai10/openaigo/maintainability)\n[![Go Report Card](https://goreportcard.com/badge/github.com/otiai10/openaigo)](https://goreportcard.com/report/github.com/otiai10/openaigo)\n[![codecov](https://codecov.io/github/otiai10/openaigo/branch/main/graph/badge.svg?token=mfAYgn6Uto)](https://codecov.io/github/otiai10/openaigo)\n\u003cbr\u003e[![Reference](https://img.shields.io/github/v/tag/otiai10/openaigo?sort=semver)](https://pkg.go.dev/github.com/otiai10/openaigo)\n[![GoDoc](https://pkg.go.dev/badge/github.com/otiai10/openaigo)](https://pkg.go.dev/github.com/otiai10/openaigo)\n\nYet another API client for `api.openai.com`.\n\nThis library is community-maintained, NOT officially supported by OpenAI.\n\n# Usage Example\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/otiai10/openaigo\"\n)\n\nfunc main() {\n\tclient := openaigo.NewClient(os.Getenv(\"OPENAI_API_KEY\"))\n\trequest := openaigo.ChatRequest{\n\t\tModel: \"gpt-4o\",\n\t\tMessages: []openaigo.Message{\n\t\t\t{Role: \"user\", Content: \"Hello!\"},\n\t\t},\n\t}\n\tctx := context.Background()\n\tresponse, err := client.Chat(ctx, request)\n\tfmt.Println(response, err)\n}\n\n```\n\nif you just want to try, hit commands below.\n\n```shell\ngit clone https://github.com/otiai10/openaigo.git\ncd openaigo\nOPENAI_API_KEY=YourAPIKey go run ./testapp/main.go\n```\n\nSee [test app](https://github.com/otiai10/openaigo/blob/main/testapp/main.go) as a working example.\n\n# API Keys?\n\nVisit https://beta.openai.com/account/api-keys and you can create your own API key to get started [for free](https://openai.com/api/pricing/).\n\n# Endpoint Support\n\n- Models\n  - [x] [List models](https://beta.openai.com/docs/api-reference/models/list)\n  - [x] [Retrieve model](https://beta.openai.com/docs/api-reference/models/retrieve)\n- Text Completions\n  - [x] [Create completion](https://beta.openai.com/docs/api-reference/completions/create)\n- **Chat Completions**\n  - [x] [Create Chat Completions](https://platform.openai.com/docs/api-reference/chat/create)\n    - [x] [with function_call](https://openai.com/blog/function-calling-and-other-api-updates) \u003c- New\n- Edits\n  - [x] [Create edits](https://beta.openai.com/docs/api-reference/edits/create)\n- Images\n  - [x] [Create image (beta)](https://beta.openai.com/docs/api-reference/images/create)\n  - [x] [Create image edit (beta)](https://beta.openai.com/docs/api-reference/images/create-edit)\n  - [x] [Create image variation (beta)](https://beta.openai.com/docs/api-reference/images/create-variation)\n- Embeddings\n  - [x] [Create embeddings](https://beta.openai.com/docs/api-reference/embeddings/create)\n- Files\n  - [x] [List files](https://beta.openai.com/docs/api-reference/files/list)\n  - [x] [Upload file](https://beta.openai.com/docs/api-reference/files/upload)\n  - [x] [Delete file](https://beta.openai.com/docs/api-reference/files/delete)\n  - [x] [Retrieve file](https://beta.openai.com/docs/api-reference/files/retrieve)\n  - [x] [Retrieve file content](https://beta.openai.com/docs/api-reference/files/retrieve-content)\n- Fine-tunes\n  - [x] [Create fine-tune](https://beta.openai.com/docs/api-reference/fine-tunes/create)\n  - [x] [List fine-tunes](https://beta.openai.com/docs/api-reference/fine-tunes/list)\n  - [x] [Retrieve fine-tune](https://beta.openai.com/docs/api-reference/fine-tunes/retrieve)\n  - [x] [Cancel fine-tune](https://beta.openai.com/docs/api-reference/fine-tunes/cancel)\n  - [x] [List fine-tune events](https://beta.openai.com/docs/api-reference/fine-tunes/events)\n  - [x] [Delete fine-tune model](https://beta.openai.com/docs/api-reference/fine-tunes/delete-model)\n- Moderation\n  - [x] [Create moderation](https://beta.openai.com/docs/api-reference/moderations/create)\n- ~~Engines~~ *(deprecated)*\n  - ~~[List engines](https://beta.openai.com/docs/api-reference/engines/list)~~\n  - ~~[Retrieve engine](https://beta.openai.com/docs/api-reference/engines/retrieve)~~\n\n# Need `function_call`?\n\n```go\nrequest := openaigo.ChatRequest{\n  Messages: []openaigo.Message{\n    {Role: \"user\", Content: \"How's the weather today in Tokyo?\"},\n  },\n  Functions: []openaigo.Function{\n    {\n      Name: \"get_weather\",\n      Parameters: openaigo.Parameters{\n        Type:       \"object\",\n        Properties: map[string]map[string]any{\n          \"location\": {\"type\": \"string\"},\n          \"date\":     {\"type\": \"string\", \"description\": \"ISO 8601 date string\"},\n        },\n        Required: []string{\"location\"},\n      },\n    }\n  },\n}\n```\n\nif you want **shorthand**, use [`functioncall`](https://pkg.go.dev/github.com/otiai10/openaigo@v1.4.0/functioncall).\n\n```go\nimport fc \"github.com/otiai10/openaigo/functioncall\"\n\nrequest.Functions = fc.Funcs{\n  \"get_weather\": {GetWeather, \"Get weather of the location\", fc.Params{\n    {\"location\", \"string\", \"location of the weather\", true},\n    {\"date\", \"string\", \"ISO 8601 date string\", true},\n  }},\n}\n```\n\nSee [test app](https://github.com/otiai10/openaigo/blob/main/testapp/main.go) as a working example.\n\n# Need `stream`?\n\n```go\nclient := openaigo.NewClient(OPENAI_API_KEY)\nrequest := openaigo.ChatRequest{\n  Stream: true,\n  StreamCallback: func(res ChatCompletionResponse, done bool, err error) {\n    // Do what you want!\n    // You might need chan handling here.\n    // See test app how you can do it.\n    // https://github.com/otiai10/openaigo/search?q=chat_completion_stream\n  },\n}\n```\n\n# Need Proxy?\n\n```go\nclient := openaigo.NewClient(OPENAI_API_KEY)\n// You can set whatever you want\ntransport := \u0026http.Transport{ Proxy: http.ProxyFromEnvironment }\nclient.HTTPClient = \u0026http.Client{ Transport: transport }\n// Done!\n```\n\n# Issues\n\nReport any issue here or any feedback is welcomed.\n\n* https://github.com/otiai10/openaigo/issues\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotiai10%2Fopenaigo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fotiai10%2Fopenaigo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotiai10%2Fopenaigo/lists"}