Fix issue with auto-generated model ID during model creation
This commit is contained in:
+41
-4
@@ -659,22 +659,59 @@ attachment
|
|||||||
|
|
||||||
#### POST `/models` - 创建模型
|
#### POST `/models` - 创建模型
|
||||||
|
|
||||||
请求体:
|
创建对话模型(KnowledgeQA)请求体:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"name": "模型名称",
|
"name": "模型名称",
|
||||||
"type": "LLM",
|
"type": "KnowledgeQA",
|
||||||
"source": "OPENAI",
|
"source": "remote", # remote / local
|
||||||
"description": "模型描述",
|
"description": "模型描述",
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"model": "gpt-4",
|
"model": "gpt-4",
|
||||||
"api_key": "sk-xxxxx",
|
"api_key": "sk-xxxxx",
|
||||||
"base_url": "https://api.openai.com"
|
"base_url": "xxx"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
创建嵌入模型(Embedding)请求体:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"name": "模型名称",
|
||||||
|
"type": "Embedding",
|
||||||
|
"source": "remote", # remote / local
|
||||||
|
"description": "模型描述",
|
||||||
|
"parameters": {
|
||||||
|
"model": "bge-m3",
|
||||||
|
"api_key": "sk-xxxxx",
|
||||||
|
"base_url": "xxx",
|
||||||
|
"embedding_parameters": {
|
||||||
|
"dimension": 768,
|
||||||
|
"truncate_prompt_tokens": 512
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
创建排序模型(Rerank)请求体:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"name": "模型名称",
|
||||||
|
"type": "Rerank",
|
||||||
|
"source": "remote", # remote / local
|
||||||
|
"description": "模型描述",
|
||||||
|
"parameters": {
|
||||||
|
"model": "gte-reranker",
|
||||||
|
"api_key": "sk-xxxxx",
|
||||||
|
"base_url": "xxx"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
响应:
|
响应:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -89,3 +90,15 @@ func (c *ModelParameters) Scan(value interface{}) error {
|
|||||||
}
|
}
|
||||||
return json.Unmarshal(b, c)
|
return json.Unmarshal(b, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BeforeCreate is a GORM hook that runs before creating a new model record
|
||||||
|
// Automatically generates a UUID for new models
|
||||||
|
// Parameters:
|
||||||
|
// - tx: GORM database transaction
|
||||||
|
//
|
||||||
|
// Returns:
|
||||||
|
// - error: Any error encountered during the hook execution
|
||||||
|
func (m *Model) BeforeCreate(tx *gorm.DB) (err error) {
|
||||||
|
m.ID = uuid.New().String()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user