request_meta.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package types
  2. type FileType string
  3. const (
  4. FileTypeImage FileType = "image" // Image file type
  5. FileTypeAudio FileType = "audio" // Audio file type
  6. FileTypeVideo FileType = "video" // Video file type
  7. FileTypeFile FileType = "file" // Generic file type
  8. )
  9. type TokenType string
  10. const (
  11. TokenTypeTextNumber TokenType = "text_number" // Text or number tokens
  12. TokenTypeTokenizer TokenType = "tokenizer" // Tokenizer tokens
  13. TokenTypeImage TokenType = "image" // Image tokens
  14. )
  15. type TokenCountMeta struct {
  16. TokenType TokenType `json:"token_type,omitempty"` // Type of tokens used in the request
  17. CombineText string `json:"combine_text,omitempty"` // Combined text from all messages
  18. ToolsCount int `json:"tools_count,omitempty"` // Number of tools used
  19. NameCount int `json:"name_count,omitempty"` // Number of names in the request
  20. MessagesCount int `json:"messages_count,omitempty"` // Number of messages in the request
  21. Files []*FileMeta `json:"files,omitempty"` // List of files, each with type and content
  22. MaxTokens int `json:"max_tokens,omitempty"` // Maximum tokens allowed in the request
  23. ImagePriceRatio float64 `json:"image_ratio,omitempty"` // Ratio for image size, if applicable
  24. //IsStreaming bool `json:"is_streaming,omitempty"` // Indicates if the request is streaming
  25. }
  26. type FileMeta struct {
  27. FileType
  28. Source FileSource // 统一的文件来源(URL 或 base64)
  29. Detail string // 图片细节级别(low/high/auto)
  30. }
  31. // NewFileMeta 创建新的 FileMeta
  32. func NewFileMeta(fileType FileType, source FileSource) *FileMeta {
  33. return &FileMeta{
  34. FileType: fileType,
  35. Source: source,
  36. }
  37. }
  38. // NewImageFileMeta 创建图片类型的 FileMeta
  39. func NewImageFileMeta(source FileSource, detail string) *FileMeta {
  40. return &FileMeta{
  41. FileType: FileTypeImage,
  42. Source: source,
  43. Detail: detail,
  44. }
  45. }
  46. // GetIdentifier 获取文件标识符(用于日志)
  47. func (f *FileMeta) GetIdentifier() string {
  48. if f.Source != nil {
  49. return f.Source.GetIdentifier()
  50. }
  51. return "unknown"
  52. }
  53. // IsURL 判断是否是 URL 来源
  54. func (f *FileMeta) IsURL() bool {
  55. return f.Source != nil && f.Source.IsURL()
  56. }
  57. // GetRawData 获取原始数据(兼容旧代码)
  58. // Deprecated: 请使用 Source.GetRawData()
  59. func (f *FileMeta) GetRawData() string {
  60. if f.Source != nil {
  61. return f.Source.GetRawData()
  62. }
  63. return ""
  64. }
  65. type RequestMeta struct {
  66. OriginalModelName string `json:"original_model_name"`
  67. UserUsingGroup string `json:"user_using_group"`
  68. PromptTokens int `json:"prompt_tokens"`
  69. PreConsumedQuota int `json:"pre_consumed_quota"`
  70. }