openai-client

所属分类:工具库
开发工具:D
文件大小:0KB
下载次数:0
上传日期:2023-07-28 12:15:36
上 传 者sh-1993
说明:  根据OpenAI的OpenAPI规范生成的D编程语言客户端库。,
(A D programming language client library produced from OpenAI s OpenAPI specification.,)

文件列表:
dub.sdl (1136, 2023-11-21)
dub.selections.json (434, 2023-11-21)
json/ (0, 2023-11-21)
json/openapi.json (121959, 2023-11-21)
json/update.sh (277, 2023-11-21)
source/ (0, 2023-11-21)
source/openai/ (0, 2023-11-21)
source/openai/model/ (0, 2023-11-21)
source/openai/model/ChatCompletionFunctionParameters.d (782, 2023-11-21)
source/openai/model/ChatCompletionFunctions.d (982, 2023-11-21)
source/openai/model/ChatCompletionRequestMessage.d (1886, 2023-11-21)
source/openai/model/ChatCompletionResponseMessage.d (1482, 2023-11-21)
source/openai/model/ChatCompletionStreamResponseDelta.d (1528, 2023-11-21)
source/openai/model/CreateChatCompletionRequest.d (5709, 2023-11-21)
source/openai/model/CreateChatCompletionResponse.d (1406, 2023-11-21)
source/openai/model/CreateChatCompletionStreamResponse.d (1053, 2023-11-21)
source/openai/model/CreateCompletionRequest.d (6838, 2023-11-21)
source/openai/model/CreateCompletionResponse.d (1889, 2023-11-21)
source/openai/model/CreateEditRequest.d (1798, 2023-11-21)
source/openai/model/CreateEditResponse.d (1140, 2023-11-21)
source/openai/model/CreateEmbeddingRequest.d (1433, 2023-11-21)
source/openai/model/CreateEmbeddingResponse.d (1055, 2023-11-21)
source/openai/model/CreateFileRequest.d (994, 2023-11-21)
source/openai/model/CreateFineTuneRequest.d (6106, 2023-11-21)
source/openai/model/CreateImageEditRequest.d (1900, 2023-11-21)
source/openai/model/CreateImageRequest.d (1346, 2023-11-21)
source/openai/model/CreateImageVariationRequest.d (1389, 2023-11-21)
source/openai/model/CreateModerationRequest.d (1039, 2023-11-21)
source/openai/model/CreateModerationResponse.d (2036, 2023-11-21)
source/openai/model/CreateTranscriptionRequest.d (1985, 2023-11-21)
source/openai/model/CreateTranscriptionResponse.d (439, 2023-11-21)
source/openai/model/CreateTranslationRequest.d (1673, 2023-11-21)
source/openai/model/CreateTranslationResponse.d (435, 2023-11-21)
source/openai/model/DeleteFileResponse.d (529, 2023-11-21)
source/openai/model/DeleteModelResponse.d (531, 2023-11-21)
source/openai/model/Error.d (560, 2023-11-21)
source/openai/model/ErrorResponse.d (449, 2023-11-21)
source/openai/model/FineTune.d (2110, 2023-11-21)
... ...

# OpenAI API Client A client library for the [D Programming Language](https://dlang.org/) that interfaces with the [OpenAI REST API](https://platform.openai.com/docs/api-reference). This client consists of files that have been generated automatically from OpenAI's [OpenAPI Specification](https://github.com/openai/openai-openapi) using the generation tool [openapi-client](https://code.dlang.org/packages/openapi-client). ## Client Code Organization - **openai.model** :: The package `openai.model` contains commonly used data types for the OpenAI API, which are generated from the `#/components/schemas/` portion of the OpenAI OpenAPI Specification. This includes things like requests, responses, etc. - **openai.service** :: The package `openai.service` contains logic to communicate with REST API endpoints. Generally, the module and class names are produced by concatenating the URL path fragments of the API endpoint, e.g. `/chat/completions` => `chat_completions_service.d` => `class ChatCompletionsService`. - **openai.server** :: The default server URLs are stored here. - **openai.security** :: Credentials needed to access the API, such as API tokens, usernames, and passwords are configured using this module. ## Using the OpenAI Client Below is an example of how to use the OpenAI Client: ```d import vibe.core.log : logDebug; import vibe.data.json : Json, serializeToJson; import openai.service.completions_service : CompletionsService; import openai.model.CreateCompletionRequest : CreateCompletionRequest; import openai.model.CreateCompletionResponse : CreateCompletionResponse; import std.process : environment; // 1. Use your OpenAI API Key as your security credentials. // See https://platform.openai.com/account/api-keys string apiKey = environment["OPENAI_API_KEY"]; Security.configureBearerAuth(apiKey); // 2. Create a new service object corresponding to the URL path of the desired service. auto service = new CompletionsService(); // 3. Invoke a specific action, e.g. creating a completion request. service.createCompletion( // 4. Define any parameters needed for the request. CreateCompletionRequest.builder() .model("text-davinci-003") .prompt(Json("What is the cutest breed of rabbit? ")) .echo(true) .maxTokens(2048) .build(), // 5. Indicate how different response codes should be handled. CompletionsService.CreateCompletionResponseHandler.builder() .handleResponse200((CreateCompletionResponse response) { logDebug("%s", serializeToJson(response).toString()); }) .build()); ``` # Development ## Code Generation The client code is generated from the file `json/openapi.json`. If this file is updated, then the client code can be regenerated using the following command: ```bash dub build --config=generate ``` ## Testing To run integration tests, an OpenAI API key is required. Once obtained, run integration tests with the following commands: ```bash export OPENAI_API_KEY="sk-TS...N4G" dub test --config=integration ```

近期下载者

相关文件


收藏者