OpenAI API 快速开发手册 - 库
库
Python库
我们提供了一个Python库,您可以按照以下方式安装:
$ pip install openai
安装后,您可以使用绑定和您的秘密密钥运行以下代码:
import os
import openai
# 从环境变量或秘密管理服务中加载您的API密钥
openai.api_key = os.getenv("OPENAI_API_KEY")
chat_completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world"}])
绑定还会安装一个命令行实用程序,您可以按照以下方式使用它:
$ openai api chat_completions.create -m gpt-3.5-turbo -g user "Hello world"
Node.js库
我们还有一个Node.js库,您可以通过在Node.js项目目录中运行以下命令来安装:
$ npm install openai
安装后,您可以使用库和您的秘密密钥运行以下代码:
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const chat_completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: "Hello world" }],
});
Azure OpenAI库
微软的Azure团队维护了兼容OpenAI API和Azure OpenAI服务的库。阅读以下库的文档,了解如何在OpenAI API中使用它们。
- Azure OpenAI .NET客户端库
- Azure OpenAI JavaScript客户端库
- Azure OpenAI Java客户端库
- Azure OpenAI Go客户端库
社区库
以下库由更广泛的开发者社区构建和维护。如果您想在此处添加新的库,请按照我们的帮助中心文章上的说明添加社区库。您还可以在GitHub上关注我们的OpenAPI规范存储库,及时了解我们对API进行更改的更新。
请注意,OpenAI不验证这些项目的正确性或安全性。使用它们时要自行承担风险!
-
C# / .NET
- Betalgo.OpenAI by Betalgo
- OpenAI-API-dotnet by OkGoDoIt
- OpenAI-DotNet by RageAgainstThePixel
-
C++
- liboai by D7EAD
-
Clojure
- openai-clojure by wkok
-
Crystal
- openai-crystal by sferik
-
Dart/Flutter
- openai by anasfik
-
Delphi
- DelphiOpenAI by HemulGM
-
Elixir
- openai.ex by mgallo
-
Go
- go-gpt3 by sashabaranov
-
Java
- openai-java by Theo Kanning
-
Julia
- OpenAI.jl by rory-linehan
-
Kotlin
- openai-kotlin by Mouaad Aallam
-
Node.js
- openai-api by Njerschow
- openai-api-node by erlapso
- gpt-x by ceifa
- gpt3 by poteat
- gpts by thencc
- @dalenguyen/openai by dalenguyen
- tectalic/openai by tectalic
-
PHP
- orhanerday/open-ai by orhanerday
- tectalic/openai by tectalic
- openai-php clinet by openai-php
-
Python
- chronology by OthersideAI
-
R
- rgpt3 by ben-aaron188
-
Ruby
- openai by nileshtrivedi
- ruby-openai by alexrudall
-
Rust
- async-openai by 64bit
- fieri by lbkolev
-
Scala
- openai-scala-client by cequence-io
-
Swift
- OpenAIKit by dylanshine
- OpenAI by MacPaw
-
Unity
- OpenAi-Api-Unity by hexthedev
- com.openai.unity by RageAgainstThePixel
-
Unreal Engine
- OpenAI-Api-Unreal by KellanM