@@ -2,6 +2,7 @@ package model
22
33import (
44 "one-api/common/logger"
5+ "one-api/common/utils"
56)
67
78type ModelInfo struct {
@@ -19,6 +20,48 @@ type ModelInfo struct {
1920 UpdatedAt int64 `json:"updated_at" gorm:"autoUpdateTime"`
2021}
2122
23+ type ModelInfoResponse struct {
24+ Model string `json:"model"`
25+ Name string `json:"name"`
26+ Description string `json:"description"`
27+ ContextLength int `json:"context_length"`
28+ MaxTokens int `json:"max_tokens"`
29+ InputModalities []string `json:"input_modalities"`
30+ OutputModalities []string `json:"output_modalities"`
31+ Tags []string `json:"tags"`
32+ SupportUrl []string `json:"support_url"`
33+ CreatedAt int64 `json:"created_at"`
34+ UpdatedAt int64 `json:"updated_at"`
35+ }
36+
37+ func (m * ModelInfo ) ToResponse () * ModelInfoResponse {
38+ res := & ModelInfoResponse {
39+ Model : m .Model ,
40+ Name : m .Name ,
41+ Description : m .Description ,
42+ ContextLength : m .ContextLength ,
43+ MaxTokens : m .MaxTokens ,
44+ CreatedAt : m .CreatedAt ,
45+ UpdatedAt : m .UpdatedAt ,
46+ }
47+
48+ res .InputModalities , _ = utils.UnmarshalString [[]string ](m .InputModalities )
49+ res .OutputModalities , _ = utils.UnmarshalString [[]string ](m .OutputModalities )
50+ res .Tags , _ = utils.UnmarshalString [[]string ](m .Tags )
51+
52+ var err error
53+ res .SupportUrl , err = utils.UnmarshalString [[]string ](m .SupportUrl )
54+ if err != nil {
55+ if m .SupportUrl != "" {
56+ res .SupportUrl = []string {m .SupportUrl }
57+ } else {
58+ res .SupportUrl = []string {}
59+ }
60+ }
61+
62+ return res
63+ }
64+
2265func (m * ModelInfo ) TableName () string {
2366 return "model_info"
2467}
0 commit comments