Spaces:
Sleeping
Sleeping
adds typed web response
Browse files- responses.py +18 -0
responses.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel, Field
|
| 2 |
+
from typing import List, Dict, Any
|
| 3 |
+
|
| 4 |
+
class TextStreamResponse(BaseModel):
|
| 5 |
+
streamed_chunks: List[str] = Field(default_factory=list, description="List of streamed chunks.")
|
| 6 |
+
streamed_chunks_timings: List[float] = Field(default_factory=list, description="List of streamed chunks timings, in seconds.")
|
| 7 |
+
uid: int = Field(0, description="UID of queried miner")
|
| 8 |
+
completion: str = Field('', description="The final completed string from the stream.")
|
| 9 |
+
timing: float = Field(0, description="Timing information of all request, in seconds.")
|
| 10 |
+
|
| 11 |
+
def to_dict(self):
|
| 12 |
+
return {
|
| 13 |
+
"streamed_chunks": self.streamed_chunks,
|
| 14 |
+
"streamed_chunks_timings": self.streamed_chunks_timings,
|
| 15 |
+
"uid": self.uid,
|
| 16 |
+
"completion": self.completion,
|
| 17 |
+
"timing": self.timing
|
| 18 |
+
}
|