feat: introducing streams management pages #166

This commit is contained in:
0xJacky 2023-12-15 21:43:13 +08:00
parent 9c16b55dde
commit 2649b710bb
No known key found for this signature in database
GPG key ID: B6E4A6E4A561BAF0
32 changed files with 3170 additions and 606 deletions

View file

@ -1,35 +1,35 @@
package model
import (
"database/sql/driver"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"github.com/sashabaranov/go-openai"
"database/sql/driver"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"github.com/sashabaranov/go-openai"
)
type JSON []openai.ChatCompletionMessage
type ChatGPTCompletionMessages []openai.ChatCompletionMessage
// Scan scan value into Jsonb, implements sql.Scanner interface
func (j *JSON) Scan(value interface{}) error {
bytes, ok := value.([]byte)
if !ok {
return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", value))
}
// Scan value into Jsonb, implements sql.Scanner interface
func (j *ChatGPTCompletionMessages) Scan(value interface{}) error {
bytes, ok := value.([]byte)
if !ok {
return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", value))
}
result := make([]openai.ChatCompletionMessage, 0)
err := json.Unmarshal(bytes, &result)
*j = result
result := make([]openai.ChatCompletionMessage, 0)
err := json.Unmarshal(bytes, &result)
*j = result
return err
return err
}
// Value return json value, implement driver.Valuer interface
func (j *JSON) Value() (driver.Value, error) {
return json.Marshal(*j)
func (j *ChatGPTCompletionMessages) Value() (driver.Value, error) {
return json.Marshal(*j)
}
type ChatGPTLog struct {
Name string `json:"name"`
Content JSON `json:"content" gorm:"serializer:json"`
Name string `json:"name"`
Content ChatGPTCompletionMessages `json:"content" gorm:"serializer:json"`
}

View file

@ -32,6 +32,7 @@ func GenerateAllModel() []any {
Cert{},
ChatGPTLog{},
Site{},
Stream{},
DnsCredential{},
Environment{},
Notification{},

8
model/stream.go Normal file
View file

@ -0,0 +1,8 @@
package model
type Stream struct {
Model
Path string `json:"path"`
Advanced bool `json:"advanced"`
ChatGPTMessages ChatGPTCompletionMessages `json:"chatgpt_messages" gorm:"serializer:json"`
}