feat: 添加AI推荐脚本并更新提示词
添加AI推荐生成脚本,查询近3天的招标项目并调用AI服务获取推荐结果。同时更新提示词,要求至少推荐10个项目。
This commit is contained in:
@@ -1 +1 @@
|
||||
export const PromptString: string = `先给我说你统计了多少个项目。我只对辽宁、山东、江苏、浙江、福建、广东、广西、河北这些地方的海上风电、海上光伏、漂浮式光伏、滩涂光伏、滩涂风电、渔光互补项目感兴趣。从我提供的这些工程里面找到我感兴趣的工程。如果没有推荐的,也要给出思考过程。`;
|
||||
export const PromptString: string = `先给我说你统计了多少个项目。我只对辽宁、山东、江苏、浙江、福建、广东、广西、河北这些地方的海上风电、海上光伏、漂浮式光伏、滩涂光伏、滩涂风电、渔光互补项目感兴趣。从我提供的这些工程里面找到我感兴趣的工程,无论如何至少推荐10个工程。如果没有推荐的,也要给出思考过程。`;
|
||||
|
||||
78
src/scripts/ai-recommendations.ts
Normal file
78
src/scripts/ai-recommendations.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from '../app.module';
|
||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BidItem } from '../bids/entities/bid-item.entity';
|
||||
import { AiService } from '../ai/ai.service';
|
||||
import { CustomLogger } from '../common/logger/logger.service';
|
||||
|
||||
async function generateAiRecommendations() {
|
||||
const app = await NestFactory.createApplicationContext(AppModule);
|
||||
|
||||
// 设置自定义 logger
|
||||
const logger = await app.resolve(CustomLogger);
|
||||
app.useLogger(logger);
|
||||
logger.setContext('AiRecommendationsScript');
|
||||
|
||||
try {
|
||||
// 获取 BidItem 的 repository 和 AiService
|
||||
const bidItemRepository = app.get<Repository<BidItem>>(getRepositoryToken(BidItem));
|
||||
const aiService = app.get(AiService);
|
||||
|
||||
logger.log('开始查询 bid_items 表...');
|
||||
|
||||
// 计算起始日期:3天前
|
||||
const threeDaysAgo = new Date();
|
||||
threeDaysAgo.setDate(threeDaysAgo.getDate() - 2);
|
||||
threeDaysAgo.setHours(0, 0, 0, 0);
|
||||
|
||||
// 使用本地时间格式化输出,避免时区问题
|
||||
const localDateStr = threeDaysAgo.toLocaleDateString('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit'
|
||||
}).replace(/\//g, '-');
|
||||
logger.log(`查询起始日期: ${localDateStr}`);
|
||||
|
||||
// 查询起始日期3天前,截止日期不限制的所有记录
|
||||
const bidItems = await bidItemRepository
|
||||
.createQueryBuilder('bid')
|
||||
.where('bid.publishDate >= :startDate', { startDate: threeDaysAgo })
|
||||
.orderBy('bid.publishDate', 'DESC')
|
||||
.getMany();
|
||||
|
||||
logger.log(`查询到 ${bidItems.length} 条记录`);
|
||||
|
||||
if (bidItems.length === 0) {
|
||||
logger.log('没有符合条件的记录');
|
||||
await app.close();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// 提取 title
|
||||
const bidData = bidItems.map(item => ({
|
||||
title: item.title
|
||||
}));
|
||||
|
||||
logger.log('开始调用 AI 获取推荐...');
|
||||
|
||||
// 调用 getRecommendations 函数
|
||||
const recommendations = await aiService.getRecommendations(bidData);
|
||||
|
||||
logger.log(`AI 返回了 ${recommendations.length} 条推荐结果`);
|
||||
|
||||
// 调用 saveRecommendations 函数保存结果
|
||||
await aiService.saveRecommendations(recommendations);
|
||||
|
||||
logger.log('AI 推荐结果保存成功');
|
||||
|
||||
await app.close();
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
logger.error('生成 AI 推荐失败:', error);
|
||||
await app.close();
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
generateAiRecommendations();
|
||||
Reference in New Issue
Block a user