aiframe/backend/src/ai/ai.service.ts

30 lines
979 B
TypeScript

import { Injectable } from '@nestjs/common';
import { HttpService } from '@nestjs/axios';
import { ConfigService } from '@nestjs/config';
import { AiConfigService } from './ai-config.service';
@Injectable()
export class AiService {
private readonly defaultModel: string;
constructor(
private readonly httpService: HttpService,
private readonly configService: ConfigService,
private readonly aiConfigService: AiConfigService,
) {
this.defaultModel = this.configService.get<string>('AI_DEFAULT_MODEL', 'gpt-3.5-turbo');
}
async generateCode(prompt: string, workspaceId: number) {
// 获取工作区的AI配置
const aiConfig = await this.aiConfigService.getAiConfigByWorkspace(workspaceId);
// 这里实现调用外部AI服务的逻辑
// 需要根据实际的AI服务API进行实现
return {
success: true,
code: '// 生成的代码示例\nconsole.log("Hello World");',
model: this.defaultModel,
};
}
}