usage_detail.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. field.String("model").Optional().Default("GPT-4o mini").
  53. Comment("模型").
  54. Annotations(entsql.WithComments(true)),
  55. field.Float("credits").Optional().Comment("coins | 积分消耗数"),
  56. }
  57. }
  58. func (UsageDetail) Mixin() []ent.Mixin {
  59. return []ent.Mixin{
  60. mixins.IDMixin{},
  61. mixins.StatusMixin{},
  62. }
  63. }
  64. func (UsageDetail) Indexes() []ent.Index {
  65. return []ent.Index{
  66. index.Fields("bot_id"),
  67. index.Fields("organization_id"),
  68. }
  69. }
  70. func (UsageDetail) Edges() []ent.Edge { return []ent.Edge{} }
  71. func (UsageDetail) Annotations() []schema.Annotation {
  72. return []schema.Annotation{
  73. entsql.WithComments(true),
  74. entsql.Annotation{Table: "usage_detail"},
  75. }
  76. }