usage_detail.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package schema
  2. import (
  3. "entgo.io/ent"
  4. "entgo.io/ent/dialect/entsql"
  5. "entgo.io/ent/schema"
  6. "entgo.io/ent/schema/field"
  7. "entgo.io/ent/schema/index"
  8. "github.com/suyuan32/simple-admin-common/orm/ent/mixins"
  9. "wechat-api/ent/custom_types"
  10. )
  11. type UsageDetail struct {
  12. ent.Schema
  13. }
  14. func (UsageDetail) Fields() []ent.Field {
  15. return []ent.Field{
  16. field.Int("type").Optional().Default(1).
  17. Annotations(entsql.WithComments(true)).
  18. Comment("1 微信 2 名片"),
  19. field.String("bot_id").Default("").
  20. Annotations(entsql.WithComments(true)).
  21. Comment("微信或名片id"),
  22. field.String("receiver_id").Default("").
  23. Annotations(entsql.WithComments(true)).
  24. Comment("微信id或open_id"),
  25. field.Int("app").Optional().Default(1).
  26. Annotations(entsql.WithComments(true)).
  27. Comment("1 cow-basic 2 cow-agent 3 cow-sop 4 mp-card 5 mp-employee"),
  28. field.Uint64("session_id").Optional().Default(1).
  29. Comment("名片会话id").
  30. Annotations(entsql.WithComments(true)),
  31. field.String("request").Default("").
  32. Annotations(entsql.WithComments(true)).
  33. Comment("请求内容"),
  34. field.String("response").Default("").
  35. Annotations(entsql.WithComments(true)).
  36. Comment("响应内容"),
  37. field.JSON("original_data", custom_types.OriginalData{}).
  38. Annotations(entsql.WithComments(true)).
  39. Comment("原始数据"),
  40. field.Uint64("total_tokens").Optional().Default(0).
  41. Annotations(entsql.WithComments(true)).
  42. Comment("使用token总数"),
  43. field.Uint64("prompt_tokens").Optional().Default(0).
  44. Annotations(entsql.WithComments(true)).
  45. Comment("请求token数"),
  46. field.Uint64("completion_tokens").Optional().Default(0).
  47. Annotations(entsql.WithComments(true)).
  48. Comment("响应token数"),
  49. field.Uint64("organization_id").Optional().Default(1).
  50. Comment("机构 ID").
  51. Annotations(entsql.WithComments(true)),
  52. }
  53. }
  54. func (UsageDetail) Mixin() []ent.Mixin {
  55. return []ent.Mixin{
  56. mixins.IDMixin{},
  57. mixins.StatusMixin{},
  58. }
  59. }
  60. func (UsageDetail) Indexes() []ent.Index {
  61. return []ent.Index{
  62. index.Fields("bot_id"),
  63. index.Fields("organization_id"),
  64. }
  65. }
  66. func (UsageDetail) Edges() []ent.Edge { return []ent.Edge{} }
  67. func (UsageDetail) Annotations() []schema.Annotation {
  68. return []schema.Annotation{
  69. entsql.WithComments(true),
  70. entsql.Annotation{Table: "usage_detail"},
  71. }
  72. }