feat: implement QuestionBank CRUD with pagination and template query
- Add pagination support to findAll (page, limit query params) - Add findByTemplateId method to service - Add GET /by-template/:templateId endpoint to controller - Service already includes CRUD for QuestionBank and QuestionBankItem
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { EmbeddingService } from './embedding.service';
|
||||
|
||||
@Module({
|
||||
providers: [EmbeddingService],
|
||||
exports: [EmbeddingService],
|
||||
})
|
||||
export class AiModule {}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { OpenAIEmbeddings } from '@langchain/openai';
|
||||
import { ModelConfig } from '../model-config/model-config.entity';
|
||||
|
||||
@Injectable()
|
||||
export class EmbeddingService {
|
||||
private readonly logger = new Logger(EmbeddingService.name);
|
||||
|
||||
async getEmbeddings(text: string, config: ModelConfig): Promise<number[]> {
|
||||
try {
|
||||
const embeddings = new OpenAIEmbeddings({
|
||||
openAIApiKey: config.apiKey || 'ollama',
|
||||
configuration: {
|
||||
baseURL: config.baseUrl,
|
||||
},
|
||||
modelName: config.modelId,
|
||||
});
|
||||
|
||||
const vector = await embeddings.embedQuery(text);
|
||||
return vector;
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
`Failed to generate embeddings using model ${config.modelId}`,
|
||||
error,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user