Spaces:
Runtime error
Runtime error
File size: 2,638 Bytes
105b369 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
from os import getenv
from typing import Union, Dict, List
from httpx import Response
from phi.api.api import api, invalid_response
from phi.api.routes import ApiRoutes
from phi.api.schemas.assistant import (
AssistantEventCreate,
AssistantRunCreate,
)
from phi.constants import PHI_API_KEY_ENV_VAR, PHI_WS_KEY_ENV_VAR
from phi.cli.settings import phi_cli_settings
from phi.utils.log import logger
def create_assistant_run(run: AssistantRunCreate) -> bool:
if not phi_cli_settings.api_enabled:
return True
logger.debug("--o-o-- Creating Assistant Run")
with api.AuthenticatedClient() as api_client:
try:
r: Response = api_client.post(
ApiRoutes.ASSISTANT_RUN_CREATE,
headers={
"Authorization": f"Bearer {getenv(PHI_API_KEY_ENV_VAR)}",
"PHI-WORKSPACE": f"{getenv(PHI_WS_KEY_ENV_VAR)}",
},
json={
"run": run.model_dump(exclude_none=True),
# "workspace": assistant_workspace.model_dump(exclude_none=True),
},
)
if invalid_response(r):
return False
response_json: Union[Dict, List] = r.json()
if response_json is None:
return False
logger.debug(f"Response: {response_json}")
return True
except Exception as e:
logger.debug(f"Could not create assistant run: {e}")
return False
def create_assistant_event(event: AssistantEventCreate) -> bool:
if not phi_cli_settings.api_enabled:
return True
logger.debug("--o-o-- Creating Assistant Event")
with api.AuthenticatedClient() as api_client:
try:
r: Response = api_client.post(
ApiRoutes.ASSISTANT_EVENT_CREATE,
headers={
"Authorization": f"Bearer {getenv(PHI_API_KEY_ENV_VAR)}",
"PHI-WORKSPACE": f"{getenv(PHI_WS_KEY_ENV_VAR)}",
},
json={
"event": event.model_dump(exclude_none=True),
# "workspace": assistant_workspace.model_dump(exclude_none=True),
},
)
if invalid_response(r):
return False
response_json: Union[Dict, List] = r.json()
if response_json is None:
return False
logger.debug(f"Response: {response_json}")
return True
except Exception as e:
logger.debug(f"Could not create assistant event: {e}")
return False
|