OpenAIService

io.cequence.openaiscala.service.OpenAIService

Central service to access all public OpenAI WS endpoints as defined at the API ref. page

The following services are supported:

  • '''Models''': listModels, and retrieveModel
  • '''Completions''': createCompletion
  • '''Chat Completions''': createChatCompletion, and createChatFunCompletion
  • '''Edits''': createEdit (deprecated)
  • '''Images''': createImage, createImageEdit, createImageVariation
  • '''Embeddings''': createEmbeddings
  • '''Audio''': createAudioTranscription, and createAudioTranslation
  • '''Files''': listFiles, uploadFile, deleteFile, retrieveFile, and retrieveFileContent
  • '''Fine-tunes''': createFineTune, listFineTunes, retrieveFineTune, cancelFineTune, listFineTuneEvents, and deleteFineTuneModel
  • '''Moderations''': createModeration

Attributes

Since:

Jan 2023

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Concise view

Type members

Inherited classlikes

Attributes

Inherited from:
OpenAIServiceConsts
Graph
Supertypes
class Object
trait Matchable
class Any

Value members

Abstract methods

def cancelFineTune(fineTuneId: String): Future[Option[FineTuneJob]]

Immediately cancel a fine-tune job.

Immediately cancel a fine-tune job.

Attributes

fineTuneId

The ID of the fine-tune job to cancel

Returns:

fine tune info or None if not found

See also:
def createAudioTranscription(file: File, prompt: Option[String], settings: CreateTranscriptionSettings): Future[TranscriptResponse]

Transcribes audio into the input language.

Transcribes audio into the input language.

Attributes

file

The audio file to transcribe, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm.

prompt

An optional text to guide the model's style or continue a previous audio segment. The prompt should match the audio language.

Returns:

transcription text

See also:
def createAudioTranslation(file: File, prompt: Option[String], settings: CreateTranslationSettings): Future[TranscriptResponse]

Translates audio into into English.

Translates audio into into English.

Attributes

file

The audio file to translate, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm.

prompt

An optional text to guide the model's style or continue a previous audio segment. The prompt should match the audio language.

Returns:

translation text

See also:
def createChatFunCompletion(messages: Seq[FunMessageSpec], functions: Seq[FunctionSpec], responseFunctionName: Option[String], settings: CreateChatCompletionSettings): Future[ChatFunCompletionResponse]

Creates a model response for the given chat conversation expecting a function call.

Creates a model response for the given chat conversation expecting a function call.

Attributes

functions

A list of functions the model may generate JSON inputs for.

messages

A list of messages comprising the conversation so far.

responseFunctionName

If specified it forces the model to respond with a call to that function (must be listed in functions). Otherwise, the default "auto" mode is used where the model can pick between an end-user or calling a function.

Returns:

chat completion response

See also:
def createFineTune(training_file: String, validation_file: Option[String], settings: CreateFineTuneSettings): Future[FineTuneJob]

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.

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.

Attributes

training_file

The ID of an uploaded file that contains training data. See uploadFile for how to upload a file. Your dataset must be formatted as a JSONL file, where each training example is a JSON object with the keys "prompt" and "completion". Additionally, you must upload your file with the purpose fine-tune.

validation_file

The ID of an uploaded file that contains validation data. If you provide this file, the data is used to generate validation metrics periodically during fine-tuning. These metrics can be viewed in the fine-tuning results file. Your train and validation data should be mutually exclusive. Your dataset must be formatted as a JSONL file, where each validation example is a JSON object with the keys "prompt" and "completion". Additionally, you must upload your file with the purpose fine-tune.

Returns:

fine tune response

See also:
def createImage(prompt: String, settings: CreateImageSettings): Future[ImageInfo]

Creates an image given a prompt.

Creates an image given a prompt.

Attributes

prompt

A text description of the desired image(s). The maximum length is 1000 characters.

Returns:

image response (might contain multiple data items - one per image)

See also:
def createImageEdit(prompt: String, image: File, mask: Option[File], settings: CreateImageSettings): Future[ImageInfo]

Creates an edited or extended image given an original image and a prompt.

Creates an edited or extended image given an original image and a prompt.

Attributes

image

The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask.

mask

An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where image should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as image.

prompt

A text description of the desired image(s). The maximum length is 1000 characters.

Returns:

image response (might contain multiple data items - one per image)

See also:
def createImageVariation(image: File, settings: CreateImageSettings): Future[ImageInfo]

Creates a variation of a given image.

Creates a variation of a given image.

Attributes

image

The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.

Returns:

image response (might contain multiple data items - one per image)

See also:
def createModeration(input: String, settings: CreateModerationSettings): Future[ModerationResponse]

Classifies if text violates OpenAI's Content Policy.

Classifies if text violates OpenAI's Content Policy.

Attributes

input

The input text to classify

Returns:

moderation results

See also:
def deleteFile(fileId: String): Future[DeleteResponse]

Delete a file.

Delete a file.

Attributes

fileId

The ID of the file to use for this request

Returns:

enum indicating whether the file was deleted

See also:
def deleteFineTuneModel(modelId: String): Future[DeleteResponse]

Delete a fine-tuned model. You must have the Owner role in your organization.

Delete a fine-tuned model. You must have the Owner role in your organization.

Attributes

modelId

The ID of the file to use for this request

Returns:

enum indicating whether the model was deleted

See also:
def listFiles: Future[Seq[FileInfo]]

Returns a list of files that belong to the user's organization.

Returns a list of files that belong to the user's organization.

Attributes

Returns:

file infos

See also:
def listFineTuneEvents(fineTuneId: String, after: Option[String], limit: Option[Int]): Future[Option[Seq[FineTuneEvent]]]

Get fine-grained status updates for a fine-tune job.

Get fine-grained status updates for a fine-tune job.

Attributes

fineTuneId

The ID of the fine-tune job to get events for.

Returns:

fine tune events or None if not found

See also:
def listFineTunes(after: Option[String], limit: Option[Int]): Future[Seq[FineTuneJob]]

List your organization's fine-tuning jobs.

List your organization's fine-tuning jobs.

Attributes

after

Identifier for the last job from the previous pagination request.

limit

Number of fine-tuning jobs to retrieve.

Returns:

fine tunes

See also:
def retrieveFile(fileId: String): Future[Option[FileInfo]]

Returns information about a specific file.

Returns information about a specific file.

Attributes

fileId

The ID of the file to use for this request

Returns:

file info or None if not found

See also:
def retrieveFileContent(fileId: String): Future[Option[String]]

Returns the contents of the specified file.

Returns the contents of the specified file.

Attributes

fileId

The ID of the file to use for this request

Returns:

file content or None if not found

See also:
def retrieveFineTune(fineTuneId: String): Future[Option[FineTuneJob]]

Gets info about the fine-tune job.

Gets info about the fine-tune job.

Attributes

fineTuneId

The ID of the fine-tune job

Returns:

fine tune info

See also:
def retrieveModel(modelId: String): Future[Option[ModelInfo]]

Retrieves a model instance, providing basic information about the model such as the owner and permissions.

Retrieves a model instance, providing basic information about the model such as the owner and permissions.

Attributes

modelId

The ID of the model to use for this request

Returns:

model or None if not found

See also:
def uploadFile(file: File, displayFileName: Option[String], settings: UploadFileSettings): Future[FileInfo]

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.

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.

Attributes

displayFileName

(Explicit) display file name; if not specified a full path is used instead.

file

Name of the JSON Lines file to be uploaded. If the purpose is set to "fine-tune", each line is a JSON record with "prompt" and "completion" fields representing your training examples.

Returns:

file info

See also:

Deprecated methods

@Deprecated
def createEdit(input: String, instruction: String, settings: CreateEditSettings): Future[TextEditResponse]

Creates a new edit for the provided input, instruction, and parameters.

Creates a new edit for the provided input, instruction, and parameters.

Attributes

input

The input text to use as a starting point for the edit.

instruction

The instruction that tells the model how to edit the prompt.

Returns:

text edit response

See also:
Deprecated
true

Inherited methods

def close(): Unit

Closes the underlying ws client, and releases all its resources.

Closes the underlying ws client, and releases all its resources.

Attributes

Inherited from:
OpenAICoreService

Creates a model response for the given chat conversation.

Creates a model response for the given chat conversation.

Attributes

messages

A list of messages comprising the conversation so far.

Returns:

chat completion response

See also:
Inherited from:
OpenAICoreService
def createCompletion(prompt: String, settings: CreateCompletionSettings): Future[TextCompletionResponse]

Creates a completion for the provided prompt and parameters.

Creates a completion for the provided prompt and parameters.

Attributes

prompt

The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays. Note that <|endoftext|> is the document separator that the model sees during training, so if a prompt is not specified the model will generate as if from the beginning of a new document.

Returns:

text completion response

See also:
Inherited from:
OpenAICoreService
def createEmbeddings(input: Seq[String], settings: CreateEmbeddingsSettings): Future[EmbeddingResponse]

Creates an embedding vector representing the input text.

Creates an embedding vector representing the input text.

Attributes

input

Input text to get embeddings for, encoded as a string or array of tokens. To get embeddings for multiple inputs in a single request, pass an array of strings or array of token arrays. Each input must not exceed 8192 tokens in length.

Returns:

list of embeddings inside an envelope

See also:
Inherited from:
OpenAICoreService
def listModels: Future[Seq[ModelInfo]]

Lists the currently available models, and provides basic information about each one such as the owner and availability.

Lists the currently available models, and provides basic information about each one such as the owner and availability.

Attributes

Returns:

models

See also:
Inherited from:
OpenAICoreService

Inherited fields

protected val configFileName: String

Attributes

Inherited from:
OpenAIServiceConsts
protected val configPrefix: String

Attributes

Inherited from:
OpenAIServiceConsts
protected val defaultCoreUrl: String

Attributes

Inherited from:
OpenAIServiceConsts
protected val defaultReadoutTimeout: Int

Attributes

Inherited from:
OpenAIServiceConsts
protected val defaultRequestTimeout: Int

Attributes

Inherited from:
OpenAIServiceConsts