mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-06-06 16:14:49 +08:00
add LlmModelUsageRecord table
This commit is contained in:
61
packages/sqlite-plugin/src/entity/LlmModelUsageRecord.ts
Normal file
61
packages/sqlite-plugin/src/entity/LlmModelUsageRecord.ts
Normal 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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user