**WARNING**: I'm currently not in a position to update this repo and keep up with changes to the OpenAI Api. From my end, I doubt updates will come. However, I will gladly accept pull requests to fix any problems in the code base. If anyone is interested in being a more active maintainer of the repo, please let me know.
# OpenAi Api Unity
A simple OpenAI API wrapper for Unity
This is a community library. I am not officially affiliated with OpenAi.
Big shout out to:
* [@OkGoDoIt](https://github.com/OkGoDoIt): This code base is heavily based on the [OpenAI-API-dotnet Repo](https://github.com/OkGoDoIt/OpenAI-API-dotnet), which is a dotnet wrapper for the OpenAI Api
* [@ivomarel](https://github.com/ivomarel): For the [OpenAI_Unity Repo](https://github.com/hexthedev/OpenAI_Unity)
To report bugs, problems, suggestions please submit [Github Issues](https://github.com/hexthedev/OpenAi-Api-Unity/issues)
If anyone wants to contribute, [Pull Requests](https://github.com/hexthedev/OpenAi-Api-Unity/pulls) are welcome
## Status
| Api Call | Implemented | Bare-Minimum Tests | Thourough Tests |
| --- | --- | --- | --- |
| `GET /engines` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| `GET /engines/{engine_id}` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| `POST /engines/{engine_id}/completions` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| `GET /engines/{engine_id}/completions/browser_stream` | :x: | :heavy_minus_sign: | :heavy_minus_sign: |
| `POST /engines/{engine_id}/search` | :heavy_check_mark: | :heavy_check_mark: | :heavy_minus_sign: |
| `POST /classifications` | :heavy_check_mark: | :heavy_check_mark: | :heavy_minus_sign: |
| `POST /answers` | :heavy_check_mark: | :heavy_check_mark: | :heavy_minus_sign: |
| `GET /files` | :heavy_check_mark: | :heavy_minus_sign: | :heavy_minus_sign: |
| `POST /files/{file_id}` | :x: | :heavy_minus_sign: | :heavy_minus_sign: |
| `GET /files/{file_id}` | :heavy_check_mark: | :heavy_minus_sign: | :heavy_minus_sign: |
| `POST /chat/completions` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
## Overview
This is a simple OpenAI API wrapper that implements the API calls found in the [OpenAI Api Reference](https://beta.openai.com/docs/api-reference) as Coroutines and Async functions.
The syntax follows the docs as closely as possible. For example, the API call Create Completion at the endpoint `https://api.openai.com/v1/engines/{engine_id}/completions` is called using `OpenAiApiV1.Engines.Engine("<engine_id>").Completions.CreateCompletionCoroutine`. The API call Chat Completion at the endpoint `https://api.openai.com/v1/chat/completions` is called using `OpenAiApiV1.Chat.Completions.CreateChatCompletionCoroutine`.
To learn more:
1. Read the Quick Start section below to see a basic example of how to use the wrapper
2. Refer to the [Documentation](https://github.com/hexthedev/OpenAi-Api-Unity/tree/main/Documentation) for a more detailed explanation of the library
### What is and isn't tested
I've tested the list below. Testing for all other use cases will come with time
* Editor scripts and editor windows using async versions of API calls
* Coroutine api calls in Play Mode
* I have not tested builds, but should work since it's really just Native C#. Any issues will likely be platform related.
* Unit Tested basic use cases and any issue I found along the way, to ensure stability
* Only tested on a Windows machine. If Linux/Mac authentication doesn't work as expected, please let me know.
* I do not have an organization, I have not been able to test the organization key functionality during authentication
# Quick Start
See video: https://youtu.be/Ju-i0sxsX7E
## Install
**Unity Package Manager (Recommended):**
Go to the Unity Package Manager (`Window > Package Manager`), and click the `+` icon in the top left hand corner. Choose `Add package from git URL...` and provide the url `https://github.com/hexthedev/OpenAi-Api-Unity.git`.
**Unity Package:**
Go to https://github.com/hexthedev/OpenAi-Api-Unity/releases and download the desired release. Once downloaded, open the file and follow the instructions to import it into Unity.
**Git Submodule**:
For more advanced git users, you can simply add this repo as a submodule in your assets folder. This is especially useful if you want to edit, change and version the `OpenAi Api Unity` code.
## Authenticate
Add a file to the path `~/.openai/auth.json` (Linux/Mac) or `%USERPROFILE%/.openai/auth.json` (Windows)
if you only have an API key, the `auth.json` should look like this
```json
{
"private_api_key":"<YOUR_KEY>"
}
```
If you have an organization key, the `auth.json` should look like this
```json
{
"private_api_key":"<YOUR_KEY>",
"organization":"<YOUR_ORGANIZATION_ID>"
}
```
## Editor Script
To see an example of a completion in an editor script:
* From the top bar to to `OpenAi > Examples > Completion In Editor Window`.
* To see the code, Click the `Code` reference at the top of the window.
## Play Script
To see an example of a completion at Runtime:
* If you're working on a scene, save the scene you are working on
* From the top bar click `OpenAi > Examples > Completion At Runtime`
* Look at the `CompletionExample` object in the hierarchy and check out the code in `ExampleOpenAiApiRuntime`
* Press play and run the scene
To see an example of chat completion at Runtime:
* If you're working on a scene, save the scene you are working on
* From the top bar click `OpenAi > Examples > Chat At Runtime`
* Look at the `ChatCompletionExample` object in the hierarchy and check out the code in `ExampleChatRuntime`
* Press play and run the scene
# What Next
The above quick start is an extremely simple way to use the `OpenAi Api Unity` library. For more advanced use cases, refer to the [OpenAi Api Unity Documentation](https://github.com/hexthedev/OpenAi-Api-Unity/tree/main/Documentation)
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
OpenAi-Api-Unity-0.2.9.tar.gz (269个子文件)
openai.api.unity.editor.tests.asmdef 563B
openai.api.unity.tests.asmdef 525B
openai.api.unity.editor.asmdef 406B
openai.api.unity.asmdef 32B
DefaultChatCompletionArgs.asset 550B
DefaultCompletionArgs.asset 531B
DefaultAuthArgsV1.asset 455B
V1PlayTests.cs 24KB
AApiResource.cs 13KB
AnswerRequestV1.cs 9KB
CompletionRequestV1.cs 8KB
JsonBuilder.cs 8KB
ChatCompletionRequestV1.cs 7KB
ClassificationRequestV1.cs 7KB
ChatCompletionsResourceV1.cs 5KB
CompletionsResourceV1.cs 5KB
JsonSyntaxAnalyzerTests.cs 4KB
JsonSyntaxAnalyzer.cs 4KB
UTJsonObjectTests.cs 4KB
SOAuthArgsV1.cs 3KB
SOChatCompletionArgsV1.cs 3KB
OpenAiChatCompleterV1.cs 3KB
OpenAiApiV1.cs 3KB
V1BugTests.cs 3KB
AMonoSingleton.cs 3KB
ChatCompletionV1.cs 3KB
ClassificationsResourceV1.cs 3KB
JsonLexer.cs 3KB
StringOrArray.cs 3KB
OpenAiCompleterV1.cs 3KB
CompletionV1.cs 3KB
JsonLexerTests.cs 3KB
ClassificationV1.cs 3KB
FileV1.cs 2KB
SOCompletionArgsV1.cs 2KB
ChatChoiceV1.cs 2KB
AnswersResourceV1.cs 2KB
OpenAiApiGatewayV1.cs 2KB
SearchResourceV1.cs 2KB
EngineResourceV1.cs 2KB
UsageV1.cs 2KB
ExampleOpenAiApiUnityEditor.cs 2KB
ChoiceV1.cs 2KB
AnswerV1.cs 2KB
FileResourceV1.cs 2KB
EngineV1.cs 2KB
SearchRequestV1.cs 2KB
TestManager.cs 2KB
SelectedExampleV1.cs 2KB
SOAuthArgsV1Editor.cs 2KB
EnginesResourceV1.cs 2KB
MessageV1.cs 2KB
JsonDeserializerTests.cs 2KB
DeltaV1.cs 2KB
SAuthArgsV1.cs 2KB
EEngineName.cs 2KB
FilesResourceV1.cs 1KB
SearchListV1.cs 1KB
SearchV1.cs 1KB
QuestionAnswerPairV1.cs 1KB
LabeledExampleV1.cs 1KB
BaseAnalyzer.cs 1KB
SelectedDocumentV1.cs 1KB
ExampleChatRuntime.cs 1KB
ECharacterAnalyzerResponse.cs 1KB
EMPrefabs.cs 1KB
EnginesListV1.cs 1KB
FilesListV1.cs 1KB
IApiResource.cs 1KB
OpenAiApiException.cs 1KB
EMExampleOpenAiApiRuntimeScene.cs 956B
EMExampleChatRuntimeScene.cs 940B
ChatResourceV1.cs 910B
ExampleOpenAiApiRuntime.cs 901B
UnityWebRequestAwaiter.cs 867B
ApiResult.cs 851B
StringAnalyzer.cs 843B
OpenAiJsonException.cs 821B
UTJsonDeserialization.cs 797B
AModelV1.cs 789B
EChatModelName.cs 683B
ICharacterAnalyzer.cs 649B
UTEngineNames.cs 632B
IJsonable.cs 550B
CompletionRequestModelTests.cs 512B
EJsonType.cs 471B
UnityWebRequestExtensions.cs 457B
JsonDeserializer.cs 337B
JsonObject.cs 244B
UTChatModelNames.cs 212B
package.json 358B
3_ApiCalls.md 7KB
README.md 6KB
1_Overview.md 2KB
CHANGELOG.md 2KB
2_Authentication.md 1KB
License.md 1KB
4_JsonSerialization.md 605B
OpenAiChatCompleterV1.cs.meta 319B
OpenAiCompleterV1.cs.meta 319B
共 269 条
- 1
- 2
- 3
资源评论
Maddie_Mo
- 粉丝: 234
- 资源: 33
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功