parent
e3b923668d
commit
4ea6492177
1 changed files with 17 additions and 0 deletions
|
|
@ -1,6 +1,21 @@
|
|||
import { z } from "zod";
|
||||
|
||||
import { Chunk, LLMOptions } from "../../index.js";
|
||||
import OpenAI from "./OpenAI.js";
|
||||
|
||||
/**used to check a valid response from voyage is received
|
||||
* reference: https://docs.voyageai.com/reference/reranker-api
|
||||
*/
|
||||
const VoyageRerankSuccessResponseSchema = z.object({
|
||||
data: z.array(
|
||||
z.object({
|
||||
index: z.number(),
|
||||
relevance_score: z.number(),
|
||||
document: z.string(),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
class Voyage extends OpenAI {
|
||||
static providerName = "voyage";
|
||||
static defaultOptions: Partial<LLMOptions> | undefined = {
|
||||
|
|
@ -36,6 +51,8 @@ class Voyage extends OpenAI {
|
|||
data: Array<{ index: number; relevance_score: number }>;
|
||||
};
|
||||
|
||||
VoyageRerankSuccessResponseSchema.parse(data);
|
||||
|
||||
const results = data.data.sort((a, b) => a.index - b.index);
|
||||
return results.map((result) => result.relevance_score);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue