Skip to content

Commit

Permalink
api/embed (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
royjhan authored Jul 15, 2024
1 parent df56393 commit 6ef65f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type {
CopyRequest,
CreateRequest,
DeleteRequest,
EmbedRequest,
EmbedResponse,
EmbeddingsRequest,
EmbeddingsResponse,
ErrorResponse,
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -149,6 +158,11 @@ export interface ChatResponse {
eval_duration: number
}

export interface EmbedResponse {
model: string
embeddings: number[][]
}

export interface EmbeddingsResponse {
embedding: number[]
}
Expand Down

0 comments on commit 6ef65f4

Please sign in to comment.