Skip to content

Commit

Permalink
chore: add logging, refactor module, fix missing parameters in defaul…
Browse files Browse the repository at this point in the history
…t values
  • Loading branch information
jfaldanam committed May 16, 2024
1 parent c46fef8 commit 9779f73
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 11 deletions.
4 changes: 1 addition & 3 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ROOT_PATH=/eidos/
API_HOST=127.0.0.1
API_PORT=6004
LOG_LEVEL=info
API_KEY=API_KEY_GOES_HERE
FUNCTIONS_FOLDER=functions
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM python:3.10

# Install ASGI server
RUN pip install uvicorn

WORKDIR /code

COPY README.md /code/README.md
Expand All @@ -13,4 +16,4 @@ RUN pip install "."

EXPOSE 80

CMD ["uvicorn", "--app-dir", "/code", "src.eidos.main:app", "--host", "0.0.0.0", "--port", "80"]
CMD ["uvicorn", "eidos.api:app", "--host", "0.0.0.0", "--port", "80"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pip install "eidos @ git+ssh://git@github.com/KhaosResearch/eidos.git
Run the API with the following command:
```bash
uvicorn eidos.main:app --host 0.0.0.0 --port 8090 --reload
uvicorn eidos.api:app --host 0.0.0.0 --port 8090 --reload
```
You can override the default configuration by setting [environment variables](src/eidos/settings.py).
Expand Down
2 changes: 1 addition & 1 deletion examples/joke/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from setuptools import setup, find_packages
from setuptools import find_packages, setup

setup(
name="joke",
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ dependencies = [
"pydantic-settings>=2.0.0",
"fastapi>=0.103.0",
"structlog",
"uvicorn",
]

[project.urls]
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions src/eidos/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,22 @@ def execute(function_name: str, arguments: dict | None) -> dict[str, Any]:
arguments, schema=function_definition["parameters"]
)
except (ValueError, TypeError) as e:
log.error("Error: function arguments are malformed.", error=str(e))
raise ValueError(f"Error: function arguments are malformed.\n{str(e)}")

try:
fn = import_function(function_definition["module"])
result = fn(**arguments) if arguments else fn()
except Exception as e:
log.error("Error: function execution failed.", error=str(e))
raise Exception(f"Error: function execution failed.\n{str(e)}")

try:
validated_result = validate_output_schema(
result, schema=function_definition["response"].copy()
)
except (ValueError, TypeError) as e:
log.error("Error: function result is malformed.", error=str(e))
raise ValueError(f"Error: function result is malformed.\n{str(e)}")

return validated_result
1 change: 1 addition & 0 deletions src/eidos/routes/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async def execute_endpoint(
) -> JSONResponse:
"""Executes an AI function with the given arguments."""
try:
log.info("Executing function", function=function_name, arguments=arguments)
data = execute(function_name, arguments)
response, status = (
{
Expand Down
3 changes: 2 additions & 1 deletion src/eidos/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
class Settings(BaseSettings):
model_config = SettingsConfigDict(
# `.env.prod` takes priority over `.env`
env_file=(".env", ".env.prod")
env_file=(".env", ".env.prod"),
extra="ignore"
)

# The root path of the API. Useful when deploying the API behind a reverse proxy.
Expand Down
4 changes: 2 additions & 2 deletions src/eidos/validation/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def validate_input_schema(
validated_arguments = {}
for param in schema:
param_name = param["name"]
is_required = param["required"]
is_required = param.get("required", True)
param_type = param["type"]
param_default = param.get("default")
param_default = param.get("default", None)

if param_name not in input_arguments:
if is_required:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from eidos.main import app
from eidos.api import app
from fastapi.testclient import TestClient

client = TestClient(app)
Expand Down

0 comments on commit 9779f73

Please sign in to comment.