2
0

request_meta.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. MimeType string
  29. Source *FileSource // 统一的文件来源(URL 或 base64)
  30. Detail string // 图片细节级别(low/high/auto)
  31. }
  32. // NewFileMeta 创建新的 FileMeta
  33. func NewFileMeta(fileType FileType, source *FileSource) *FileMeta {
  34. return &FileMeta{
  35. FileType: fileType,
  36. Source: source,
  37. }
  38. }
  39. // NewImageFileMeta 创建图片类型的 FileMeta
  40. func NewImageFileMeta(source *FileSource, detail string) *FileMeta {
  41. return &FileMeta{
  42. FileType: FileTypeImage,
  43. Source: source,
  44. Detail: detail,
  45. }
  46. }
  47. // GetIdentifier 获取文件标识符(用于日志)
  48. func (f *FileMeta) GetIdentifier() string {
  49. if f.Source != nil {
  50. return f.Source.GetIdentifier()
  51. }
  52. return "unknown"
  53. }
  54. // IsURL 判断是否是 URL 来源
  55. func (f *FileMeta) IsURL() bool {
  56. return f.Source != nil && f.Source.IsURL()
  57. }
  58. // GetRawData 获取原始数据(兼容旧代码)
  59. // Deprecated: 请使用 Source.GetRawData()
  60. func (f *FileMeta) GetRawData() string {
  61. if f.Source != nil {
  62. return f.Source.GetRawData()
  63. }
  64. return ""
  65. }
  66. type RequestMeta struct {
  67. OriginalModelName string `json:"original_model_name"`
  68. UserUsingGroup string `json:"user_using_group"`
  69. PromptTokens int `json:"prompt_tokens"`
  70. PreConsumedQuota int `json:"pre_consumed_quota"`
  71. }