usage_log_helpers.go 1005 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package service
  2. import "strings"
  3. func optionalTrimmedStringPtr(raw string) *string {
  4. trimmed := strings.TrimSpace(raw)
  5. if trimmed == "" {
  6. return nil
  7. }
  8. return &trimmed
  9. }
  10. func optionalStringValue(value *string) string {
  11. if value == nil {
  12. return ""
  13. }
  14. return strings.TrimSpace(*value)
  15. }
  16. // coalesceRequestedReasoningEffort prefers the client-requested value and falls
  17. // back to the effective/forwarded effort for historical or unmapped rows.
  18. func coalesceRequestedReasoningEffort(requested, forwarded *string) *string {
  19. if trimmed := optionalStringValue(requested); trimmed != "" {
  20. return &trimmed
  21. }
  22. if trimmed := optionalStringValue(forwarded); trimmed != "" {
  23. return &trimmed
  24. }
  25. return nil
  26. }
  27. func forwardResultBillingModel(requestedModel, upstreamModel string) string {
  28. if trimmed := strings.TrimSpace(requestedModel); trimmed != "" {
  29. return trimmed
  30. }
  31. return strings.TrimSpace(upstreamModel)
  32. }
  33. func optionalInt64Ptr(v int64) *int64 {
  34. if v == 0 {
  35. return nil
  36. }
  37. return &v
  38. }