mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-17 16:05:32 +01:00
* 🚀 feat: Introduce data schemas and refactor models to use @librechat/data-schemas * 🚀 feat: Add installation step for Data Schemas Package in backend review workflow * chore: Add `data-schemas` package to update/rebuild packages scripts * chore: Update Dockerfile to include data-schemas package build process * fix: add missing @rollup/plugin-typescript package * chore: Add GitHub Actions workflow for publishing data-schemas package --------- Co-authored-by: Danny Avila <danny@librechat.ai>
60 lines
1.2 KiB
TypeScript
60 lines
1.2 KiB
TypeScript
import mongoose, { Schema, Document, Types } from 'mongoose';
|
|
|
|
// @ts-ignore
|
|
export interface ITransaction extends Document {
|
|
user: Types.ObjectId;
|
|
conversationId?: string;
|
|
tokenType: 'prompt' | 'completion' | 'credits';
|
|
model?: string;
|
|
context?: string;
|
|
valueKey?: string;
|
|
rate?: number;
|
|
rawAmount?: number;
|
|
tokenValue?: number;
|
|
inputTokens?: number;
|
|
writeTokens?: number;
|
|
readTokens?: number;
|
|
createdAt?: Date;
|
|
updatedAt?: Date;
|
|
}
|
|
|
|
const transactionSchema: Schema<ITransaction> = new Schema(
|
|
{
|
|
user: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: 'User',
|
|
index: true,
|
|
required: true,
|
|
},
|
|
conversationId: {
|
|
type: String,
|
|
ref: 'Conversation',
|
|
index: true,
|
|
},
|
|
tokenType: {
|
|
type: String,
|
|
enum: ['prompt', 'completion', 'credits'],
|
|
required: true,
|
|
},
|
|
model: {
|
|
type: String,
|
|
},
|
|
context: {
|
|
type: String,
|
|
},
|
|
valueKey: {
|
|
type: String,
|
|
},
|
|
rate: Number,
|
|
rawAmount: Number,
|
|
tokenValue: Number,
|
|
inputTokens: { type: Number },
|
|
writeTokens: { type: Number },
|
|
readTokens: { type: Number },
|
|
},
|
|
{
|
|
timestamps: true,
|
|
},
|
|
);
|
|
|
|
export default transactionSchema;
|