From 6ef65f42c6d0e498618de2fa6ccb6a97b6137510 Mon Sep 17 00:00:00 2001 From: royjhan <65097070+royjhan@users.noreply.github.com> Date: Mon, 15 Jul 2024 15:57:23 -0700 Subject: [PATCH] api/embed (#110) --- src/browser.ts | 14 ++++++++++++++ src/interfaces.ts | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/browser.ts b/src/browser.ts index 181693d..40ba369 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -9,6 +9,8 @@ import type { CopyRequest, CreateRequest, DeleteRequest, + EmbedRequest, + EmbedResponse, EmbeddingsRequest, EmbeddingsResponse, ErrorResponse, @@ -270,6 +272,18 @@ async encodeImage(image: Uint8Array | string): Promise { return (await response.json()) as ShowResponse } + /** + * Embeds text input into vectors. + * @param request {EmbedRequest} - The request object. + * @returns {Promise} - The response object. + */ + async embed(request: EmbedRequest): Promise { + const response = await utils.post(this.fetch, `${this.config.host}/api/embed`, { + ...request, + }) + return (await response.json()) as EmbedResponse + } + /** * Embeds a text prompt into a vector. * @param request {EmbeddingsRequest} - The request object. diff --git a/src/interfaces.ts b/src/interfaces.ts index 0e0fd8d..c05763c 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -110,6 +110,15 @@ export interface ShowRequest { options?: Partial } +export interface EmbedRequest { + model: string + input: string | string[] + truncate?: boolean + keep_alive?: string | number + + options?: Partial +} + export interface EmbeddingsRequest { model: string prompt: string @@ -149,6 +158,11 @@ export interface ChatResponse { eval_duration: number } +export interface EmbedResponse { + model: string + embeddings: number[][] +} + export interface EmbeddingsResponse { embedding: number[] }