|
@@ -2,8 +2,11 @@ package ticket
|
|
|
|
|
|
import (
|
|
|
_ "embed"
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
+ "github.com/google/uuid"
|
|
|
"github.com/lithammer/shortuuid/v4"
|
|
|
+ "github.com/sashabaranov/go-openai"
|
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
|
"time"
|
|
|
)
|
|
@@ -28,6 +31,29 @@ func (t *Ticket) Marshal() ([]byte, error) {
|
|
|
return protojson.Marshal(t)
|
|
|
}
|
|
|
|
|
|
+func (t *Ticket) AddGPTResponseMessage(src *openai.ChatCompletionChoice) (*Message, error) {
|
|
|
+ var (
|
|
|
+ message = &Message{
|
|
|
+ Id: uuid.NewString(),
|
|
|
+ TicketId: t.Id,
|
|
|
+ Provider: MessageProvider_GptMessageProvider,
|
|
|
+ Body: src.Message.Content,
|
|
|
+ Date: time.Now().UnixMilli(),
|
|
|
+ }
|
|
|
+ buf []byte
|
|
|
+ err error
|
|
|
+ )
|
|
|
+
|
|
|
+ if buf, err = json.Marshal(src); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ message.Raw = string(buf)
|
|
|
+ t.Thread = append(t.Thread, message)
|
|
|
+
|
|
|
+ return message, nil
|
|
|
+}
|
|
|
+
|
|
|
//goland:noinspection GoUnusedExportedFunction
|
|
|
func Unmarshal(d []byte) (*Ticket, error) {
|
|
|
t := &Ticket{}
|