Spaces:
Running
Running
Commit History
-
import requests
Verified signatureimport json import time from typing import Dict, Any, Optional, Iterator, List, Union from dataclasses import dataclass, field from urllib.parse import urlencode, quote @dataclass class Message: """Represents a chat message""" role: str content: Union[str, List[Dict[str, Any]]] @dataclass class ChatCompletionChunk: """Represents a streaming chunk from the API""" id: str object: str created: int model: str choices: List[Dict[str, Any]] system_fingerprint: Optional[str] = None prompt_filter_results: Optional[List[Dict[str, Any]]] = None def get_content(self) -> str: """Extract content from the first choice delta""" if self.choices and len(self.choices) > 0: delta = self.choices[0].get('delta', {}) return delta.get('content', '') return '' def is_finished(self) -> bool: """Check if this chunk indicates completion""" if self.choices and len(self.choices) > 0: …d5248c9