Skip to content

Commit

Permalink
perf: vector over range error
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Aug 28, 2023
1 parent 42fec3a commit c5c3826
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions client/src/pages/api/openapi/plugin/vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ export async function getVector({
...axiosConfig()
}
)
.then((res) => {
.then(async (res) => {
if (!res.data?.data?.[0]?.embedding) {
// @ts-ignore
return Promise.reject(res.data?.error?.message || 'Embedding Error');
}
return {
tokenLen: res.data.usage.total_tokens || 0,
vectors: res.data.data.map((item) => unityDimensional(item.embedding))
vectors: await Promise.all(res.data.data.map((item) => unityDimensional(item.embedding)))
};
});

Expand All @@ -88,6 +88,7 @@ export async function getVector({
}

function unityDimensional(vector: number[]) {
if (vector.length > 1536) return Promise.reject('向量维度不能超过 1536');
let resultVector = vector;
const vectorLen = vector.length;

Expand Down

0 comments on commit c5c3826

Please sign in to comment.