@jadpo/open-ai
OpenAI: the app's models asked through OpenAI's API, as the `ai` capability: typed answers, streamed answers and embeddings.
jadpo package add @jadpo/open-aiAdds the newest version, skipping any that were withdrawn (yanked) and pre-releases such as 2.0.0-beta.1. --to 2.0.0 picks a version. Your app then calls it as OpenAi.v2.
Use it in your app
@jadpo hasn't added a recipe to this package yet. A recipe is a working example of using the package in an app. After installing it, jadpo package show @jadpo/open-ai lists its operations (the calls it makes to an outside API), functions and types, and the guide on installing and using a package shows how to add one to your app.
What this package can do
- Connects to one serviceIt sends requests to
the address its connection gives, and nowhere else. Your app gives it a connection to that service, with your own credentials. - Works with Jadpo 0.6.0, Jadpo's newest releaseIt works with 0.4.0, 0.4.1 and 0.5.0 too. Each time a new Jadpo release comes out, jadpo.dev checks every package's newest version with it.0.4.0 · 0.4.1 · 0.5.0 · 0.6.0
jadpo.dev works out what this package can do from its code each time it checks a version, such as which services it calls and what personal data it sends, so the list doesn't depend on what its author says.
What it offersgenerated from the package's code
Operations
The calls this package makes to the outside API.
chat_completions.create
request POST /chat/completions input ChatCompletionRequest output ChatCompletion confirmed recordings/chat_completions.create.json
chat_completions.stream
request POST /chat/completions input StreamedChatCompletionRequest output ChatCompletionChunk confirmed recordings/chat_completions.stream.json
embeddings.create
request POST /embeddings input EmbeddingRequest output CreateEmbeddingResponse confirmed recordings/embeddings.create.json
Types
The shapes of the values it takes and gives back.
ChatCompletion= Object
A chat completion: the model's answer, and the tokens it took.
choices: List<ChatCompletionChoice> id: Text model: Text usage: CompletionUsage?
ChatCompletionChoice= Object
One answer of a chat completion, and why the model stopped: `stop`, `length`, `tool_calls`, `content_filter` or `function_call`.
finish_reason: Text?
index: Int { min: 0, max: 1000 }
message: ChatCompletionReplyChatCompletionChunk= Object
One chunk of a streamed chat completion, a server-sent event's data.
choices: List<ChatCompletionChunkChoice> id: Text model: Text usage: CompletionUsage?
ChatCompletionChunkChoice= Object
One answer's part in a chunk, and why the model stopped, in the last.
delta: ChatCompletionDelta
finish_reason: Text?
index: Int { min: 0, max: 1000 }ChatCompletionDelta= Object
What a chunk adds to the model's message: its next text, or its refusal.
content: Text? refusal: Text? role: Text?
ChatCompletionMessage= Object
One message of the conversation: who wrote it and what it says.
content: Text
role: Text { max_length: 20 }ChatCompletionReply= Object
The model's message: its text, or the refusal it gave instead.
content: Text? refusal: Text? role: Text
ChatCompletionRequest= Object
What asking a model for a chat completion takes: the model, the conversation and the most tokens it may answer with.
max_completion_tokens: Int { min: 1, max: 1000000 }
messages: List<ChatCompletionMessage> { min_length: 1 }
model: Text { max_length: 200 }CompletionUsage= Object
The tokens a chat completion took.
completion_tokens: TokenCount prompt_tokens: TokenCount prompt_tokens_details: PromptTokensDetails? total_tokens: TokenCount
CreateEmbeddingResponse= Object
The embeddings of the texts sent, each with its place among them.
data: List<EmbeddingData> model: Text usage: EmbeddingUsage
EmbeddingData= Object
One text's embedding, and its place among the texts sent.
embedding: EmbeddingVector
index: Int { min: 0, max: 1000000 }EmbeddingRequest= Object
What asking for embeddings takes: the model, the texts, and how many dimensions each vector has, which `text-embedding-3` and later models shorten to.
dimensions: Int { min: 1, max: 16000 }?
input: List<Text> { min_length: 1, max_length: 2048 }
model: Text { max_length: 200 }EmbeddingUsage= Object
The tokens embedding the texts took.
prompt_tokens: TokenCount total_tokens: TokenCount
EmbeddingVector= Vector
An embedding as OpenAI sends it: a list of numbers of the model's length, read as it comes; the app's own vector type checks its length and direction.
distance: euclidean
PromptTokensDetails= Object
Of a prompt's tokens, those read from OpenAI's prompt cache.
cached_tokens: TokenCount?
StreamedChatCompletionRequest= Object
What asking a model for a streamed chat completion takes: a chat completion's request, with `stream` set so its answer comes as a stream of chunks.
max_completion_tokens: Int { min: 1, max: 1000000 }
messages: List<ChatCompletionMessage> { min_length: 1 }
model: Text { max_length: 200 }
stream: Bool