llm_session.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package model
  2. import (
  3. "time"
  4. "github.com/google/uuid"
  5. "github.com/sashabaranov/go-openai"
  6. "gorm.io/gorm"
  7. )
  8. type LLMCompletionMessages []openai.ChatCompletionMessage
  9. type LLMSession struct {
  10. ID int `json:"id" gorm:"primaryKey"`
  11. SessionID string `json:"session_id" gorm:"uniqueIndex;not null"`
  12. Title string `json:"title"`
  13. Path string `json:"path" gorm:"index"` // 文件路径,可以为空
  14. Messages LLMCompletionMessages `json:"messages" gorm:"serializer:json"`
  15. MessageCount int `json:"message_count"`
  16. IsActive bool `json:"is_active" gorm:"default:true"`
  17. CreatedAt time.Time `json:"created_at"`
  18. UpdatedAt time.Time `json:"updated_at"`
  19. DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
  20. }
  21. func (LLMSession) TableName() string {
  22. return "llm_sessions"
  23. }
  24. func (s *LLMSession) BeforeCreate(tx *gorm.DB) error {
  25. if s.SessionID == "" {
  26. s.SessionID = uuid.New().String()
  27. }
  28. return nil
  29. }