realtime.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package dto
  2. const (
  3. RealtimeEventTypeError = "error"
  4. RealtimeEventTypeSessionUpdate = "session.update"
  5. RealtimeEventTypeConversationCreate = "conversation.item.create"
  6. RealtimeEventTypeResponseCreate = "response.create"
  7. )
  8. const (
  9. RealtimeEventTypeResponseDone = "response.done"
  10. )
  11. type RealtimeEvent struct {
  12. EventId string `json:"event_id"`
  13. Type string `json:"type"`
  14. //PreviousItemId string `json:"previous_item_id"`
  15. Session *RealtimeSession `json:"session,omitempty"`
  16. Item *RealtimeItem `json:"item,omitempty"`
  17. Error *OpenAIError `json:"error,omitempty"`
  18. Response *RealtimeResponse `json:"response,omitempty"`
  19. }
  20. type RealtimeResponse struct {
  21. Usage *RealtimeUsage `json:"usage"`
  22. }
  23. type RealtimeUsage struct {
  24. TotalTokens int `json:"total_tokens"`
  25. InputTokens int `json:"input_tokens"`
  26. OutputTokens int `json:"output_tokens"`
  27. InputTokenDetails InputTokenDetails `json:"input_token_details"`
  28. OutputTokenDetails OutputTokenDetails `json:"output_token_details"`
  29. }
  30. type InputTokenDetails struct {
  31. CachedTokens int `json:"cached_tokens"`
  32. TextTokens int `json:"text_tokens"`
  33. AudioTokens int `json:"audio_tokens"`
  34. }
  35. type OutputTokenDetails struct {
  36. TextTokens int `json:"text_tokens"`
  37. AudioTokens int `json:"audio_tokens"`
  38. }
  39. type RealtimeSession struct {
  40. Modalities []string `json:"modalities"`
  41. Instructions string `json:"instructions"`
  42. Voice string `json:"voice"`
  43. InputAudioFormat string `json:"input_audio_format"`
  44. OutputAudioFormat string `json:"output_audio_format"`
  45. InputAudioTranscription InputAudioTranscription `json:"input_audio_transcription"`
  46. TurnDetection interface{} `json:"turn_detection"`
  47. Tools []RealTimeTool `json:"tools"`
  48. ToolChoice string `json:"tool_choice"`
  49. Temperature float64 `json:"temperature"`
  50. //MaxResponseOutputTokens int `json:"max_response_output_tokens"`
  51. }
  52. type InputAudioTranscription struct {
  53. Model string `json:"model"`
  54. }
  55. type RealTimeTool struct {
  56. Type string `json:"type"`
  57. Name string `json:"name"`
  58. Description string `json:"description"`
  59. Parameters any `json:"parameters"`
  60. }
  61. type RealtimeItem struct {
  62. Id string `json:"id"`
  63. Type string `json:"type"`
  64. Status string `json:"status"`
  65. Role string `json:"role"`
  66. Content []RealtimeContent `json:"content"`
  67. Name *string `json:"name,omitempty"`
  68. ToolCalls any `json:"tool_calls,omitempty"`
  69. CallId string `json:"call_id,omitempty"`
  70. }
  71. type RealtimeContent struct {
  72. Type string `json:"type"`
  73. Text string `json:"text,omitempty"`
  74. Audio string `json:"audio,omitempty"` // Base64-encoded audio bytes.
  75. Transcript string `json:"transcript,omitempty"`
  76. }