|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import base64 |
3 | 4 | from enum import Enum |
4 | | -from typing import Iterator, Union, BinaryIO, Optional, List |
5 | | -import threading |
| 5 | +from typing import BinaryIO, Iterator, List, Optional, Union |
6 | 6 |
|
7 | 7 | from pydantic import BaseModel, ConfigDict |
8 | 8 |
|
9 | 9 | from together.together_response import TogetherResponse |
10 | | -import base64 |
11 | 10 |
|
12 | 11 |
|
13 | 12 | class AudioResponseFormat(str, Enum): |
@@ -79,23 +78,19 @@ class AudioSpeechStreamEventResponse(BaseModel): |
79 | 78 |
|
80 | 79 |
|
81 | 80 | class AudioSpeechStreamResponse(BaseModel): |
82 | | - |
83 | 81 | response: TogetherResponse | Iterator[TogetherResponse] |
84 | 82 |
|
85 | 83 | model_config = ConfigDict(arbitrary_types_allowed=True) |
86 | 84 |
|
87 | 85 | def stream_to_file(self, file_path: str) -> None: |
88 | | - |
89 | 86 | if isinstance(self.response, TogetherResponse): |
90 | 87 | # save response to file |
91 | 88 | with open(file_path, "wb") as f: |
92 | 89 | f.write(self.response.data) |
93 | 90 |
|
94 | 91 | elif isinstance(self.response, Iterator): |
95 | | - |
96 | 92 | with open(file_path, "wb") as f: |
97 | 93 | for chunk in self.response: |
98 | | - |
99 | 94 | # Try to parse as stream chunk |
100 | 95 | stream_event_response = AudioSpeechStreamEventResponse( |
101 | 96 | response={"data": chunk.data} |
@@ -154,15 +149,9 @@ class AudioTranslationRequest(BaseModel): |
154 | 149 |
|
155 | 150 | class AudioTranscriptionSegment(BaseModel): |
156 | 151 | id: int |
157 | | - seek: Optional[int] = None |
158 | 152 | start: float |
159 | 153 | end: float |
160 | 154 | text: str |
161 | | - tokens: Optional[List[int]] = None |
162 | | - temperature: Optional[float] = None |
163 | | - avg_logprob: Optional[float] = None |
164 | | - compression_ratio: Optional[float] = None |
165 | | - no_speech_prob: Optional[float] = None |
166 | 155 |
|
167 | 156 |
|
168 | 157 | class AudioTranscriptionWord(BaseModel): |
|
0 commit comments