add LlmModelUsageRecord table

This commit is contained in:
geekgeekrun
2025-04-16 03:00:32 +08:00
parent 94e237fee8
commit e838f48b89
8 changed files with 155 additions and 4 deletions

View File

@@ -0,0 +1,61 @@
import { requireTypeorm } from "../utils/module-loader";
const { Entity, PrimaryGeneratedColumn, Column } = requireTypeorm()
@Entity()
export class LlmModelUsageRecord {
@PrimaryGeneratedColumn()
id: number;
@Column()
providerCompleteApiUrl: string
@Column()
model: string
@Column()
providerApiSecretMd5: string
@Column({
nullable: true
})
completionTokens?: number;
@Column({
nullable: true
})
promptTokens?: number;
@Column({
nullable: true
})
promptCacheHitTokens?: number
@Column({
nullable: true
})
promptCacheMissTokens?: number
@Column({
nullable: true
})
totalTokens?: number;
@Column()
requestStartTime: Date
@Column({
nullable: true
})
requestEndTime?: Date
@Column()
hasError: boolean
@Column()
errorMessage: string
@Column({
nullable: true
})
requestScene?: number
}

View File

@@ -10,6 +10,7 @@ import { CompanyInfoChangeLog } from "./entity/CompanyInfoChangeLog";
import { JobInfoChangeLog } from "./entity/JobInfoChangeLog";
import { MarkAsNotSuitLog } from "./entity/MarkAsNotSuitLog";
import { ChatMessageRecord } from "./entity/ChatMessageRecord";
import { LlmModelUsageRecord } from "./entity/LlmModelUsageRecord";
function getBossInfoIfIsEqual (savedOne, currentOne) {
if (savedOne === currentOne) {
@@ -307,3 +308,21 @@ export async function saveChatMessageRecord(
//#endregion
return
}
export async function saveGptCompletionRequestRecord(
ds: DataSource,
records: LlmModelUsageRecord[]
) {
//#region mark-as-not-suit-log
const list = records.map(it => {
const o = new LlmModelUsageRecord()
for (const k of Object.keys(it)) {
o[k] = it[k]
}
return o
})
const chatMessageRecordRepository = ds.getRepository(LlmModelUsageRecord);
await chatMessageRecordRepository.save(list);
//#endregion
return
}

View File

@@ -19,6 +19,7 @@ import { VJobLibrary } from "./entity/VJobLibrary";
import { VCompanyLibrary } from "./entity/VCompanyLibrary"
import { VMarkAsNotSuitLog } from "./entity/VMarkAsNotSuitLog"
import { ChatMessageRecord } from './entity/ChatMessageRecord'
import { LlmModelUsageRecord } from './entity/LlmModelUsageRecord'
import sqlite3 from 'sqlite3';
import { saveChatStartupRecord, saveJobInfoFromRecommendPage, saveMarkAsNotSuitRecord } from "./handlers";
@@ -53,6 +54,7 @@ export function initDb(dbFilePath) {
MarkAsNotSuitLog,
VMarkAsNotSuitLog,
ChatMessageRecord,
LlmModelUsageRecord,
],
migrations: [
UpdateChatStartupLogTable1729182577167,