pref: change the database type to SQLite
This commit is contained in:
@@ -80,7 +80,7 @@ ${Object.entries(context)
|
||||
|
||||
return _streamText({
|
||||
model,
|
||||
tools,
|
||||
tools: tools(),
|
||||
system: systemPrompt,
|
||||
maxOutputTokens: maxTokens || MAX_TOKENS,
|
||||
messages: convertToModelMessages(messages),
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import type { Tool, ToolSet } from 'ai';
|
||||
import { serperTool } from './serper';
|
||||
import { weatherTool } from './weather';
|
||||
|
||||
export const tools = {
|
||||
serper: serperTool,
|
||||
weather: weatherTool,
|
||||
};
|
||||
export const tools: () => ToolSet = () => {
|
||||
const tools: Record<string, Tool> = {};
|
||||
|
||||
export { serperTool, weatherTool };
|
||||
if (process.env.SERPER_API_KEY) {
|
||||
tools.serper = serperTool;
|
||||
}
|
||||
|
||||
if (process.env.WEATHER_API_KEY) {
|
||||
tools.weather = weatherTool;
|
||||
}
|
||||
|
||||
return tools;
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
// 创建PrismaClient实例
|
||||
@@ -7,13 +8,18 @@ declare global {
|
||||
var __db: PrismaClient | undefined;
|
||||
}
|
||||
|
||||
const adapter = new PrismaBetterSQLite3({
|
||||
url: 'file:data/upage.db',
|
||||
});
|
||||
|
||||
// 在开发环境中使用全局变量,避免热重载时创建多个实例
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
prisma = new PrismaClient();
|
||||
prisma = new PrismaClient({ adapter });
|
||||
} else {
|
||||
if (!global.__db) {
|
||||
global.__db = new PrismaClient({
|
||||
log: ['query', 'error', 'warn'],
|
||||
adapter,
|
||||
});
|
||||
}
|
||||
prisma = global.__db;
|
||||
|
||||
Reference in New Issue
Block a user