mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-05-14 20:08:33 +08:00
- 扩展 ErrorLog 数据模型,增加 model_name, error_type, error_code 字段,以记录更详细的错误信息。 - 在 GeminiChatService 和 OpenAIChatService 中添加了 try-except 块,用于捕获 API 调用(包括普通和流式调用)时发生的异常。 - 实现从异常消息中通过正则表达式提取 HTTP 状态码的功能。 - 调用 add_error_log 服务将详细的错误信息(包括模型、错误类型、代码、请求体)持久化到数据库。 - 更新了 error_logs 前端页面,增加显示模型名称列及详情。 - 优化数据库连接池配置 (pool_recycle=3600),提高连接稳定性。
44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
"""
|
|
数据库模型模块
|
|
"""
|
|
import datetime
|
|
from sqlalchemy import Column, Integer, String, Text, DateTime, JSON
|
|
|
|
from app.database.connection import Base
|
|
|
|
|
|
class Settings(Base):
|
|
"""
|
|
设置表,对应.env中的配置项
|
|
"""
|
|
__tablename__ = "t_settings"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
key = Column(String(100), nullable=False, unique=True, comment="配置项键名")
|
|
value = Column(Text, nullable=True, comment="配置项值")
|
|
description = Column(String(255), nullable=True, comment="配置项描述")
|
|
created_at = Column(DateTime, default=datetime.datetime.now, comment="创建时间")
|
|
updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment="更新时间")
|
|
|
|
def __repr__(self):
|
|
return f"<Settings(key='{self.key}', value='{self.value}')>"
|
|
|
|
|
|
class ErrorLog(Base):
|
|
"""
|
|
错误日志表
|
|
"""
|
|
__tablename__ = "t_error_logs"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
gemini_key = Column(String(100), nullable=True, comment="Gemini API密钥")
|
|
model_name = Column(String(100), nullable=True, comment="模型名称")
|
|
error_type = Column(String(50), nullable=True, comment="错误类型")
|
|
error_log = Column(Text, nullable=True, comment="错误日志")
|
|
error_code = Column(Integer, nullable=True, comment="错误代码")
|
|
request_msg = Column(JSON, nullable=True, comment="请求消息")
|
|
request_time = Column(DateTime, default=datetime.datetime.now, comment="请求时间")
|
|
|
|
def __repr__(self):
|
|
return f"<ErrorLog(id='{self.id}', gemini_key='{self.gemini_key}')>"
|