2023-05-17 02:42:52 +00:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-07-15 04:30:06 +00:00
|
|
|
|
2023-05-17 02:42:52 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
// https://platform.openai.com/docs/api-reference/models/list
|
|
|
|
|
|
|
|
type OpenAIModelPermission struct {
|
|
|
|
Id string `json:"id"`
|
|
|
|
Object string `json:"object"`
|
|
|
|
Created int `json:"created"`
|
|
|
|
AllowCreateEngine bool `json:"allow_create_engine"`
|
|
|
|
AllowSampling bool `json:"allow_sampling"`
|
|
|
|
AllowLogprobs bool `json:"allow_logprobs"`
|
|
|
|
AllowSearchIndices bool `json:"allow_search_indices"`
|
|
|
|
AllowView bool `json:"allow_view"`
|
|
|
|
AllowFineTuning bool `json:"allow_fine_tuning"`
|
|
|
|
Organization string `json:"organization"`
|
|
|
|
Group *string `json:"group"`
|
|
|
|
IsBlocking bool `json:"is_blocking"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type OpenAIModels struct {
|
2023-05-31 06:43:29 +00:00
|
|
|
Id string `json:"id"`
|
|
|
|
Object string `json:"object"`
|
|
|
|
Created int `json:"created"`
|
|
|
|
OwnedBy string `json:"owned_by"`
|
|
|
|
Permission []OpenAIModelPermission `json:"permission"`
|
|
|
|
Root string `json:"root"`
|
|
|
|
Parent *string `json:"parent"`
|
2023-05-17 02:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var openAIModels []OpenAIModels
|
|
|
|
var openAIModelsMap map[string]OpenAIModels
|
|
|
|
|
|
|
|
func init() {
|
2023-05-31 06:43:29 +00:00
|
|
|
var permission []OpenAIModelPermission
|
|
|
|
permission = append(permission, OpenAIModelPermission{
|
2023-05-17 02:42:52 +00:00
|
|
|
Id: "modelperm-LwHkVFn8AcMItP432fKKDIKJ",
|
|
|
|
Object: "model_permission",
|
|
|
|
Created: 1626777600,
|
|
|
|
AllowCreateEngine: true,
|
|
|
|
AllowSampling: true,
|
|
|
|
AllowLogprobs: true,
|
|
|
|
AllowSearchIndices: false,
|
|
|
|
AllowView: true,
|
|
|
|
AllowFineTuning: false,
|
|
|
|
Organization: "*",
|
|
|
|
Group: nil,
|
|
|
|
IsBlocking: false,
|
2023-05-31 06:43:29 +00:00
|
|
|
})
|
2023-05-17 02:42:52 +00:00
|
|
|
// https://platform.openai.com/docs/models/model-endpoint-compatibility
|
|
|
|
openAIModels = []OpenAIModels{
|
2023-07-15 04:30:06 +00:00
|
|
|
{
|
|
|
|
Id: "dall-e",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "dall-e",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
2023-05-17 02:42:52 +00:00
|
|
|
{
|
|
|
|
Id: "gpt-3.5-turbo",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "gpt-3.5-turbo",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: "gpt-3.5-turbo-0301",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "gpt-3.5-turbo-0301",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
2023-06-14 01:12:14 +00:00
|
|
|
{
|
|
|
|
Id: "gpt-3.5-turbo-0613",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "gpt-3.5-turbo-0613",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: "gpt-3.5-turbo-16k",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "gpt-3.5-turbo-16k",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: "gpt-3.5-turbo-16k-0613",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "gpt-3.5-turbo-16k-0613",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
2023-05-17 02:42:52 +00:00
|
|
|
{
|
|
|
|
Id: "gpt-4",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "gpt-4",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: "gpt-4-0314",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "gpt-4-0314",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
2023-06-14 01:12:14 +00:00
|
|
|
{
|
|
|
|
Id: "gpt-4-0613",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "gpt-4-0613",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
2023-05-17 02:42:52 +00:00
|
|
|
{
|
|
|
|
Id: "gpt-4-32k",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "gpt-4-32k",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: "gpt-4-32k-0314",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "gpt-4-32k-0314",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
2023-06-14 01:12:14 +00:00
|
|
|
{
|
|
|
|
Id: "gpt-4-32k-0613",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "gpt-4-32k-0613",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
2023-05-17 02:42:52 +00:00
|
|
|
{
|
|
|
|
Id: "text-embedding-ada-002",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "text-embedding-ada-002",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
2023-06-08 06:54:02 +00:00
|
|
|
{
|
|
|
|
Id: "text-davinci-003",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "text-davinci-003",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: "text-davinci-002",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "text-davinci-002",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: "text-curie-001",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "text-curie-001",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: "text-babbage-001",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "text-babbage-001",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: "text-ada-001",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "text-ada-001",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
2023-06-11 01:37:36 +00:00
|
|
|
{
|
|
|
|
Id: "text-moderation-latest",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "text-moderation-latest",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: "text-moderation-stable",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "text-moderation-stable",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
2023-06-25 03:46:23 +00:00
|
|
|
{
|
|
|
|
Id: "text-davinci-edit-001",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "text-davinci-edit-001",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: "code-davinci-edit-001",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "openai",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "code-davinci-edit-001",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
2023-07-15 09:07:05 +00:00
|
|
|
{
|
|
|
|
Id: "ChatGLM",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "thudm",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "ChatGLM",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: "ChatGLM2",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "thudm",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "ChatGLM2",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
2023-07-22 08:18:03 +00:00
|
|
|
{
|
|
|
|
Id: "claude-instant-1",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "anturopic",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "claude-instant-1",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: "claude-2",
|
|
|
|
Object: "model",
|
|
|
|
Created: 1677649963,
|
|
|
|
OwnedBy: "anturopic",
|
|
|
|
Permission: permission,
|
|
|
|
Root: "claude-2",
|
|
|
|
Parent: nil,
|
|
|
|
},
|
2023-05-17 02:42:52 +00:00
|
|
|
}
|
|
|
|
openAIModelsMap = make(map[string]OpenAIModels)
|
|
|
|
for _, model := range openAIModels {
|
|
|
|
openAIModelsMap[model.Id] = model
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ListModels(c *gin.Context) {
|
2023-05-31 06:43:29 +00:00
|
|
|
c.JSON(200, gin.H{
|
|
|
|
"object": "list",
|
|
|
|
"data": openAIModels,
|
|
|
|
})
|
2023-05-17 02:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func RetrieveModel(c *gin.Context) {
|
|
|
|
modelId := c.Param("model")
|
|
|
|
if model, ok := openAIModelsMap[modelId]; ok {
|
|
|
|
c.JSON(200, model)
|
|
|
|
} else {
|
|
|
|
openAIError := OpenAIError{
|
|
|
|
Message: fmt.Sprintf("The model '%s' does not exist", modelId),
|
|
|
|
Type: "invalid_request_error",
|
|
|
|
Param: "model",
|
|
|
|
Code: "model_not_found",
|
|
|
|
}
|
|
|
|
c.JSON(200, gin.H{
|
|
|
|
"error": openAIError,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|