2
0
royjhan 1 жил өмнө
parent
commit
6ef65f42c6
2 өөрчлөгдсөн 28 нэмэгдсэн , 0 устгасан
  1. 14 0
      src/browser.ts
  2. 14 0
      src/interfaces.ts

+ 14 - 0
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<string> {
     return (await response.json()) as ShowResponse
   }
 
+  /**
+   * Embeds text input into vectors.
+   * @param request {EmbedRequest} - The request object.
+   * @returns {Promise<EmbedResponse>} - The response object.
+   */
+    async embed(request: EmbedRequest): Promise<EmbedResponse> {
+      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.

+ 14 - 0
src/interfaces.ts

@@ -110,6 +110,15 @@ export interface ShowRequest {
   options?: Partial<Options>
 }
 
+export interface EmbedRequest {
+  model: string
+  input: string | string[]
+  truncate?: boolean
+  keep_alive?: string | number
+
+  options?: Partial<Options>
+}
+
 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[]
 }