Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the ext::ai embeddings API #980

Closed
scotttrinh opened this issue Apr 25, 2024 · 1 comment
Closed

Add support for the ext::ai embeddings API #980

scotttrinh opened this issue Apr 25, 2024 · 1 comment
Assignees

Comments

@scotttrinh
Copy link
Collaborator

It should decode the embeddings from the extension response so that it can be provided directly to the ext::ai::search method.

@scotttrinh scotttrinh self-assigned this Apr 25, 2024
@scotttrinh
Copy link
Collaborator Author

Done!

async generateEmbeddings(inputs: string[], model: string): Promise<number[]> {
const response = await (
await this.authenticatedFetch
)("embeddings", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
model,
input: inputs,
}),
});
if (!response.ok) {
const bodyText = await response.text();
throw new Error(bodyText);
}
const data: { data: { embedding: number[] }[] } = await response.json();
return data.data[0].embedding;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant