forked from hangshuo652/aurak
Initial commit: AuraK人才测评系统基础框架
## 已实现功能 - 题库管理后端API完整实现 - 模板管理页面(Settings-测评模板) - 评估统计页面 - 人才测评页面(AssessmentView) - QuestionBank前端服务层 ## 技术栈 - 后端: Node.js + NestJS + TypeORM - 前端: React + TypeScript - 容器化: Docker Compose ## 已知待完善 - 题库列表页缺少删除按钮 - 题库详情页未实现(题目管理/AI生成/审核)
This commit is contained in:
@@ -128,14 +128,23 @@ export class EmbeddingService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process single batch embedding
|
||||
*/
|
||||
/**
|
||||
* Process single batch embedding
|
||||
*/
|
||||
private async getEmbeddingsForBatch(
|
||||
texts: string[],
|
||||
modelConfig: any,
|
||||
maxBatchSize: number,
|
||||
): Promise<number[][]> {
|
||||
// Detect Ollama by port 11434 or /api/embeddings path
|
||||
const isOllama =
|
||||
modelConfig.baseUrl.includes(':11434') ||
|
||||
modelConfig.baseUrl.includes('/api/embeddings');
|
||||
|
||||
if (isOllama) {
|
||||
return await this.getOllamaEmbeddings(texts, modelConfig);
|
||||
}
|
||||
|
||||
const apiUrl = modelConfig.baseUrl.endsWith('/embeddings')
|
||||
? modelConfig.baseUrl
|
||||
: `${modelConfig.baseUrl}/embeddings`;
|
||||
@@ -283,4 +292,59 @@ export class EmbeddingService {
|
||||
// Use default dimensions from environment variable
|
||||
return this.defaultDimensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get embeddings from local Ollama
|
||||
*/
|
||||
private async getOllamaEmbeddings(
|
||||
texts: string[],
|
||||
modelConfig: any,
|
||||
): Promise<number[][]> {
|
||||
const baseUrl = modelConfig.baseUrl || 'http://localhost:11434';
|
||||
const modelName = modelConfig.modelId || 'nomic-embed-text';
|
||||
|
||||
this.logger.log(
|
||||
`[Ollama] Generating embeddings for ${texts.length} texts using ${modelName}`,
|
||||
);
|
||||
|
||||
const embeddings: number[][] = [];
|
||||
|
||||
for (let i = 0; i < texts.length; i++) {
|
||||
try {
|
||||
const url = baseUrl.endsWith('/api/embeddings')
|
||||
? baseUrl
|
||||
: `${baseUrl}/api/embeddings`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: modelName,
|
||||
prompt: texts[i],
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
throw new Error(`Ollama API error: ${response.status} - ${errorText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
embeddings.push(data.embedding);
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
`Ollama embedding error for text ${i}: ${error.message}`,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.log(
|
||||
`[Ollama] Got ${embeddings.length} embeddings, dimensions: ${embeddings[0]?.length || 0}`,
|
||||
);
|
||||
|
||||
return embeddings;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user