Spaces:
Running
Running
Upload 4 files
Browse files
app.py
CHANGED
@@ -84,44 +84,33 @@ class GeneratedText:
|
|
84 |
text: str
|
85 |
finish_reason: Optional[str] = None
|
86 |
|
|
|
87 |
class ResponseWrapper:
|
88 |
def __init__(self, data: Dict[Any, Any]):
|
89 |
self._data = data
|
90 |
-
logger.debug("Initializing ResponseWrapper with data: %s", self._data)
|
91 |
self._text = self._extract_text()
|
92 |
self._finish_reason = self._extract_finish_reason()
|
93 |
-
logger.debug("Text extracted: %s", self._text)
|
94 |
-
logger.debug("Finish reason extracted: %s", self._finish_reason)
|
95 |
|
96 |
def _extract_text(self) -> str:
|
97 |
try:
|
98 |
-
|
99 |
-
|
100 |
-
return text
|
101 |
-
except (KeyError, IndexError) as e:
|
102 |
-
logger.error("Failed to extract text: %s", e)
|
103 |
return ""
|
104 |
|
105 |
def _extract_finish_reason(self) -> Optional[str]:
|
106 |
try:
|
107 |
-
|
108 |
-
|
109 |
-
return finish_reason
|
110 |
-
except (KeyError, IndexError) as e:
|
111 |
-
logger.error("Failed to extract finish reason: %s", e)
|
112 |
return None
|
113 |
|
114 |
@property
|
115 |
def text(self) -> str:
|
116 |
-
logger.debug("Accessing text property: %s", self._text)
|
117 |
return self._text
|
118 |
|
119 |
@property
|
120 |
def finish_reason(self) -> Optional[str]:
|
121 |
-
logger.debug("Accessing finish_reason property: %s", self._finish_reason)
|
122 |
return self._finish_reason
|
123 |
|
124 |
-
|
125 |
class APIKeyManager:
|
126 |
def __init__(self):
|
127 |
self.api_keys = re.findall(r"AIzaSy[a-zA-Z0-9_-]{33}", os.environ.get('KeyArray'))
|
|
|
84 |
text: str
|
85 |
finish_reason: Optional[str] = None
|
86 |
|
87 |
+
|
88 |
class ResponseWrapper:
|
89 |
def __init__(self, data: Dict[Any, Any]):
|
90 |
self._data = data
|
|
|
91 |
self._text = self._extract_text()
|
92 |
self._finish_reason = self._extract_finish_reason()
|
|
|
|
|
93 |
|
94 |
def _extract_text(self) -> str:
|
95 |
try:
|
96 |
+
return str(self._data)
|
97 |
+
except (KeyError, IndexError):
|
|
|
|
|
|
|
98 |
return ""
|
99 |
|
100 |
def _extract_finish_reason(self) -> Optional[str]:
|
101 |
try:
|
102 |
+
return self._data['candidates'][0].get('finishReason')
|
103 |
+
except (KeyError, IndexError):
|
|
|
|
|
|
|
104 |
return None
|
105 |
|
106 |
@property
|
107 |
def text(self) -> str:
|
|
|
108 |
return self._text
|
109 |
|
110 |
@property
|
111 |
def finish_reason(self) -> Optional[str]:
|
|
|
112 |
return self._finish_reason
|
113 |
|
|
|
114 |
class APIKeyManager:
|
115 |
def __init__(self):
|
116 |
self.api_keys = re.findall(r"AIzaSy[a-zA-Z0-9_-]{33}", os.environ.get('KeyArray'))
|