mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-12 18:11:34 +08:00
finish ai key api
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package access_log
|
||||
|
||||
import "time"
|
||||
|
||||
type Log struct {
|
||||
Id int64 `gorm:"column:id;type:BIGINT(20);AUTO_INCREMENT;NOT NULL;comment:id;primary_key;comment:主键ID;"`
|
||||
UUID string `gorm:"type:varchar(36);not null;column:uuid;uniqueIndex:uuid;comment:UUID;"`
|
||||
Cluster string `gorm:"column:cluster;type:varchar(36);NOT NULL;comment:集群ID"`
|
||||
Node string `gorm:"column:node;type:varchar(36);NOT NULL;comment:节点ID"`
|
||||
Service string `gorm:"column:service;type:varchar(36);NOT NULL;comment:服务ID"`
|
||||
API string `gorm:"column:api;type:varchar(36);NOT NULL;comment:API ID"`
|
||||
Application string `gorm:"column:application;type:varchar(36);NOT NULL;comment:应用ID"`
|
||||
Auth string `gorm:"column:auth;type:varchar(36);NOT NULL;comment:认证ID"`
|
||||
Type string `gorm:"column:type;type:varchar(36);NOT NULL;comment:日志类型;index:idx_type"`
|
||||
Target string `gorm:"column:target;type:varchar(36);NOT NULL;comment:目标ID"`
|
||||
IP string `gorm:"column:ip;type:varchar(36);NOT NULL;comment:IP"`
|
||||
RequestPath string `gorm:"column:request_path;type:varchar(255);NOT NULL;comment:请求路径"`
|
||||
Method string `gorm:"column:method;type:varchar(36);NOT NULL;comment:请求方法"`
|
||||
ResponseTime float64 `gorm:"column:response_time;type:float;NOT NULL;comment:响应时间"`
|
||||
StatusCode int64 `gorm:"column:status_code;type:BIGINT(20);NOT NULL;comment:响应状态码"`
|
||||
ReportTime time.Time `gorm:"column:report_time;type:timestamp;NOT NULL;comment:上报时间;index:idx_report_time"`
|
||||
}
|
||||
|
||||
func (c *Log) IdValue() int64 {
|
||||
return c.Id
|
||||
}
|
||||
|
||||
func (c *Log) TableName() string {
|
||||
return "access_log"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package access_log
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/eolinker/go-common/autowire"
|
||||
"github.com/eolinker/go-common/store"
|
||||
)
|
||||
|
||||
type ILogStore interface {
|
||||
store.ISearchStore[Log]
|
||||
}
|
||||
|
||||
type imlLogStore struct {
|
||||
store.SearchStore[Log]
|
||||
}
|
||||
|
||||
func init() {
|
||||
autowire.Auto[ILogStore](func() reflect.Value {
|
||||
return reflect.ValueOf(new(imlLogStore))
|
||||
})
|
||||
}
|
||||
+47
-1
@@ -8,7 +8,8 @@ type Provider struct {
|
||||
Name string `gorm:"type:varchar(100);not null;column:name;comment:name"`
|
||||
DefaultLLM string `gorm:"type:varchar(255);not null;column:default_llm;comment:默认模型ID"`
|
||||
Config string `gorm:"type:text;not null;column:config;comment:配置信息"`
|
||||
Status bool `gorm:"type:tinyint(1);not null;column:status;comment:状态"`
|
||||
Status int `gorm:"type:tinyint(1);not null;column:status;comment:状态,0:停用;1:启用,2:异常"`
|
||||
Priority int `gorm:"type:int;not null;column:priority;comment:优先级,值越小优先级越高"`
|
||||
Creator string `gorm:"size:36;not null;column:creator;comment:创建人;index:creator" aovalue:"creator"` // 创建人
|
||||
Updater string `gorm:"size:36;not null;column:updater;comment:更新人;index:updater" aovalue:"updater"` // 更新人
|
||||
CreateAt time.Time `gorm:"type:timestamp;NOT NULL;DEFAULT:CURRENT_TIMESTAMP;column:create_at;comment:创建时间"`
|
||||
@@ -22,3 +23,48 @@ func (i *Provider) TableName() string {
|
||||
func (i *Provider) IdValue() int64 {
|
||||
return i.Id
|
||||
}
|
||||
|
||||
type LogMetrics struct {
|
||||
Id int64 `gorm:"column:id;type:BIGINT(20);AUTO_INCREMENT;NOT NULL;comment:id;primary_key;comment:主键ID;"`
|
||||
UUID string `gorm:"type:varchar(36);not null;column:uuid;uniqueIndex:uuid;comment:UUID;"`
|
||||
Provider string `gorm:"type:varchar(36);not null;column:provider;comment:供应商ID"`
|
||||
Model string `gorm:"type:varchar(36);not null;column:model;comment:模型ID"`
|
||||
InputToken int `gorm:"type:int;not null;column:input_token;comment:输入token"`
|
||||
OutputToken int `gorm:"type:int;not null;column:output_token;comment:输出token"`
|
||||
TotalToken int `gorm:"type:int;not null;column:total_token;comment:总token"`
|
||||
Cost float64 `gorm:"type:int;not null;column:cost;comment:费用"`
|
||||
Per float64 `gorm:"type:int;not null;column:per;comment:每个token的价格"`
|
||||
}
|
||||
|
||||
func (i *LogMetrics) TableName() string {
|
||||
return "ai_log_metrics"
|
||||
}
|
||||
|
||||
func (i *LogMetrics) IdValue() int64 {
|
||||
return i.Id
|
||||
}
|
||||
|
||||
type Key struct {
|
||||
Id int64 `gorm:"column:id;type:BIGINT(20);AUTO_INCREMENT;NOT NULL;comment:id;primary_key;comment:主键ID;"`
|
||||
Uuid string `gorm:"type:varchar(36);not null;column:uuid;uniqueIndex:uuid;comment:UUID;"`
|
||||
Name string `gorm:"type:varchar(100);not null;column:name;comment:名称"`
|
||||
Config string `gorm:"type:text;not null;column:config;comment:配置"`
|
||||
Provider string `gorm:"type:varchar(36);not null;column:provider;comment:供应商ID"`
|
||||
Status int `gorm:"type:tinyint(1);not null;column:status;comment:状态,0:停用;1:启用,2:错误;3:超额;4:过期"`
|
||||
ExpireTime int `gorm:"type:int;not null;column:expire_time;comment:过期时间"`
|
||||
UseToken int `gorm:"type:int;not null;column:use_token;comment:使用token数"`
|
||||
Sort int `gorm:"type:int;not null;column:sort;comment:排序"`
|
||||
Creator string `gorm:"size:36;not null;column:creator;comment:创建人;index:creator" aovalue:"creator"` // 创建人
|
||||
Updater string `gorm:"size:36;not null;column:updater;comment:更新人;index:updater" aovalue:"updater"` // 更新人
|
||||
CreateAt time.Time `gorm:"type:timestamp;NOT NULL;DEFAULT:CURRENT_TIMESTAMP;column:create_at;comment:创建时间"`
|
||||
UpdateAt time.Time `gorm:"type:timestamp;NOT NULL;DEFAULT:CURRENT_TIMESTAMP;column:update_at;comment:更新时间"`
|
||||
Default bool `gorm:"type:tinyint(1);not null;column:default;comment:是否默认"`
|
||||
}
|
||||
|
||||
func (i *Key) TableName() string {
|
||||
return "ai_key"
|
||||
}
|
||||
|
||||
func (i *Key) IdValue() int64 {
|
||||
return i.Id
|
||||
}
|
||||
|
||||
+26
-1
@@ -1,9 +1,10 @@
|
||||
package ai
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/eolinker/go-common/autowire"
|
||||
"github.com/eolinker/go-common/store"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type IProviderStore interface {
|
||||
@@ -14,8 +15,32 @@ type imlProviderStore struct {
|
||||
store.SearchStore[Provider]
|
||||
}
|
||||
|
||||
type ILogMetricsStore interface {
|
||||
store.ISearchStore[LogMetrics]
|
||||
}
|
||||
|
||||
type imlLogMetricsStore struct {
|
||||
store.SearchStore[LogMetrics]
|
||||
}
|
||||
|
||||
type IKeyStore interface {
|
||||
store.ISearchStore[Key]
|
||||
}
|
||||
|
||||
type imlKeyStore struct {
|
||||
store.SearchStore[Key]
|
||||
}
|
||||
|
||||
func init() {
|
||||
autowire.Auto[IProviderStore](func() reflect.Value {
|
||||
return reflect.ValueOf(new(imlProviderStore))
|
||||
})
|
||||
|
||||
autowire.Auto[ILogMetricsStore](func() reflect.Value {
|
||||
return reflect.ValueOf(new(imlLogMetricsStore))
|
||||
})
|
||||
|
||||
autowire.Auto[IKeyStore](func() reflect.Value {
|
||||
return reflect.ValueOf(new(imlKeyStore))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ type AiAPIInfo struct {
|
||||
Timeout int `gorm:"type:int(11);not null;column:timeout;comment:超时时间"`
|
||||
Retry int `gorm:"type:int(11);not null;column:retry;comment:重试次数"`
|
||||
Model string `gorm:"size:255;not null;column:model;comment:模型"`
|
||||
Provider string `gorm:"size:36;not null;column:provider;comment:提供者;index:provider"`
|
||||
Creator string `gorm:"size:36;not null;column:creator;comment:创建人;index:creator" aovalue:"creator"`
|
||||
CreateAt time.Time `gorm:"type:timestamp;NOT NULL;DEFAULT:CURRENT_TIMESTAMP;column:create_at;comment:创建时间"`
|
||||
Updater string `gorm:"size:36;not null;column:updater;comment:更新人;index:updater" aovalue:"updater"`
|
||||
|
||||
Reference in New Issue
Block a user