4.6.7-alpha commit (#743)

Co-authored-by: Archer <545436317@qq.com>
Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
This commit is contained in:
Archer
2024-01-19 11:17:28 +08:00
committed by GitHub
parent 8ee7407c4c
commit c031e6dcc9
324 changed files with 8509 additions and 4757 deletions

View File

@@ -18,10 +18,9 @@ export async function getVectorsByText({
}
try {
// 获取 chatAPI
const ai = getAIApi();
// 把输入的内容转成向量
// input text to vector
const result = await ai.embeddings
.create({
model,
@@ -38,7 +37,7 @@ export async function getVectorsByText({
}
return {
tokens: res.usage.total_tokens || 0,
charsLength: input.length,
vectors: await Promise.all(res.data.map((item) => unityDimensional(item.embedding)))
};
});
@@ -53,7 +52,9 @@ export async function getVectorsByText({
function unityDimensional(vector: number[]) {
if (vector.length > 1536) {
console.log(`当前向量维度为: ${vector.length}, 向量维度不能超过 1536, 已自动截取前 1536 维度`);
console.log(
`The current vector dimension is ${vector.length}, and the vector dimension cannot exceed 1536. The first 1536 dimensions are automatically captured`
);
return vector.slice(0, 1536);
}
let resultVector = vector;