poe_client.py
Ricky/cat_project/backend/app/services/poe_client.py
import requests
class PoeClient:
def __init__(
self,
base_url: str,
endpoint: str,
api_key: str,
timeout: int = 45,
language: str = "zh",
):
self.base_url = base_url.rstrip("/")
self.endpoint = endpoint if endpoint.startswith("/") else f"/{endpoint}"
self.api_key = api_key
self.timeout = timeout
self.language = language
def analyze(self, text: str) -> str:
if not self.api_key:
raise RuntimeError("POE_API_KEY is missing")
url = f"{self.base_url}{self.endpoint}"
headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json",
}
body = {
"text": text,
"language": self.language,
}
resp = requests.post(
url,
headers=headers,
json=body,
timeout=self.timeout,
)
resp.raise_for_status()
data = resp.json()
if isinstance(data, dict):
return data.get("result") or data.get("text") or str(data)
return str(data)
Articoli correlati
__init__.py
__init__.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/__init__.py).
Leggi l'articolo →auth.py
auth.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/admin/auth.py).
Leggi l'articolo →routes.py
routes.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/admin/routes.py).
Leggi l'articolo →config.py
config.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/config.py).
Leggi l'articolo →admin_ingest.py
admin_ingest.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/routes/admin_ingest.py).
Leggi l'articolo →admin_stats.py
admin_stats.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/routes/admin_stats.py).
Leggi l'articolo →