/oago

OpenAI API client in Golang, generated from OpenAPI spec

Primary LanguageShell

Go API client for openapi

APIs for sampling from and fine-tuning language models

Overview

This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.

  • API version: 1.2.0
  • Package version: 1.0.0
  • Build package: org.openapitools.codegen.languages.GoClientCodegen

Installation

Install the following dependencies:

go get github.com/stretchr/testify/assert
go get golang.org/x/net/context

Put the package under your project folder and add the following in import:

import openapi "github.com/t0mk/oago"

To use a proxy, set the environment variable HTTP_PROXY:

os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")

Configuration of Server URL

Default configuration comes with Servers field that contains server objects as defined in the OpenAPI specification.

Select Server Configuration

For using other server than the one defined on index 0 set context value sw.ContextServerIndex of type int.

ctx := context.WithValue(context.Background(), openapi.ContextServerIndex, 1)

Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value sw.ContextServerVariables of type map[string]string.

ctx := context.WithValue(context.Background(), openapi.ContextServerVariables, map[string]string{
	"basePath": "v2",
})

Note, enum values are always validated and all unused variables are silently ignored.

URLs Configuration per Operation

Each operation can use different server URL defined using OperationServers map in the Configuration. An operation is uniquely identified by "{classname}Service.{nickname}" string. Similar rules for overriding default operation server index and variables applies by using sw.ContextOperationServerIndices and sw.ContextOperationServerVariables context maps.

ctx := context.WithValue(context.Background(), openapi.ContextOperationServerIndices, map[string]int{
	"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), openapi.ContextOperationServerVariables, map[string]map[string]string{
	"{classname}Service.{nickname}": {
		"port": "8443",
	},
})

Documentation for API Endpoints

All URIs are relative to https://api.openai.com/v1

Class Method HTTP request Description
OpenAIApi CancelFineTune Post /fine-tunes/{fine_tune_id}/cancel Immediately cancel a fine-tune job.
OpenAIApi CreateAnswer Post /answers Answers the specified question using the provided documents and examples. The endpoint first searches over provided documents or files to find relevant context. The relevant context is combined with the provided examples and question to create the prompt for completion.
OpenAIApi CreateChatCompletion Post /chat/completions Creates a completion for the chat message
OpenAIApi CreateClassification Post /classifications Classifies the specified `query` using provided examples. The endpoint first searches over the labeled examples to select the ones most relevant for the particular query. Then, the relevant examples are combined with the query to construct a prompt to produce the final label via the completions endpoint. Labeled examples can be provided via an uploaded `file`, or explicitly listed in the request using the `examples` parameter for quick tests and small scale use cases.
OpenAIApi CreateCompletion Post /completions Creates a completion for the provided prompt and parameters
OpenAIApi CreateEdit Post /edits Creates a new edit for the provided input, instruction, and parameters.
OpenAIApi CreateEmbedding Post /embeddings Creates an embedding vector representing the input text.
OpenAIApi CreateFile Post /files Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact us if you need to increase the storage limit.
OpenAIApi CreateFineTune Post /fine-tunes Creates a job that fine-tunes a specified model from a given dataset. Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete. Learn more about Fine-tuning
OpenAIApi CreateImage Post /images/generations Creates an image given a prompt.
OpenAIApi CreateImageEdit Post /images/edits Creates an edited or extended image given an original image and a prompt.
OpenAIApi CreateImageVariation Post /images/variations Creates a variation of a given image.
OpenAIApi CreateModeration Post /moderations Classifies if text violates OpenAI's Content Policy
OpenAIApi CreateSearch Post /engines/{engine_id}/search The search endpoint computes similarity scores between provided query and documents. Documents can be passed directly to the API if there are no more than 200 of them. To go beyond the 200 document limit, documents can be processed offline and then used for efficient retrieval at query time. When `file` is set, the search endpoint searches over all the documents in the given file and returns up to the `max_rerank` number of documents. These documents will be returned along with their search scores. The similarity score is a positive score that usually ranges from 0 to 300 (but can sometimes go higher), where a score above 200 usually means the document is semantically similar to the query.
OpenAIApi CreateTranscription Post /audio/transcriptions Transcribes audio into the input language.
OpenAIApi CreateTranslation Post /audio/translations Translates audio into into English.
OpenAIApi DeleteFile Delete /files/{file_id} Delete a file.
OpenAIApi DeleteModel Delete /models/{model} Delete a fine-tuned model. You must have the Owner role in your organization.
OpenAIApi DownloadFile Get /files/{file_id}/content Returns the contents of the specified file
OpenAIApi ListEngines Get /engines Lists the currently available (non-finetuned) models, and provides basic information about each one such as the owner and availability.
OpenAIApi ListFiles Get /files Returns a list of files that belong to the user's organization.
OpenAIApi ListFineTuneEvents Get /fine-tunes/{fine_tune_id}/events Get fine-grained status updates for a fine-tune job.
OpenAIApi ListFineTunes Get /fine-tunes List your organization's fine-tuning jobs
OpenAIApi ListModels Get /models Lists the currently available models, and provides basic information about each one such as the owner and availability.
OpenAIApi RetrieveEngine Get /engines/{engine_id} Retrieves a model instance, providing basic information about it such as the owner and availability.
OpenAIApi RetrieveFile Get /files/{file_id} Returns information about a specific file.
OpenAIApi RetrieveFineTune Get /fine-tunes/{fine_tune_id} Gets info about the fine-tune job. Learn more about Fine-tuning
OpenAIApi RetrieveModel Get /models/{model} Retrieves a model instance, providing basic information about the model such as the owner and permissioning.

Documentation For Models

Documentation For Authorization

Endpoints do not require authorization.

Documentation for Utility Methods

Due to the fact that model structure members are all pointers, this package contains a number of utility functions to easily obtain pointers to values of basic types. Each of these functions takes a value of the given basic type and returns a pointer to it:

  • PtrBool
  • PtrInt
  • PtrInt32
  • PtrInt64
  • PtrFloat
  • PtrFloat32
  • PtrFloat64
  • PtrString
  • PtrTime

Author