Skip to content

Commit

Permalink
Resolve asyncio error at FastAPI server execution (Marker-Inc-Korea#611)
Browse files Browse the repository at this point in the history
* resolve event loop issue at uvicorn

* delete nest_asyncio at api server test function

---------

Co-authored-by: jeffrey <vkefhdl1@gmail.com>
  • Loading branch information
vkehfdl1 and jeffrey authored Aug 13, 2024
1 parent fabf829 commit 6488163
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions autorag/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from copy import deepcopy
from typing import Optional, Dict, List

import nest_asyncio
import pandas as pd
import uvicorn
import yaml
Expand Down Expand Up @@ -207,7 +208,7 @@ def run_api_server(self, host: str = '0.0.0.0', port: int = 8000, **kwargs):
{
"Query": "your query",
"result_column": "answer"
"result_column": "generated_texts"
}
And it returns json response like below:
Expand All @@ -222,10 +223,11 @@ def run_api_server(self, host: str = '0.0.0.0', port: int = 8000, **kwargs):
:param port: The port of the api server.
:param kwargs: Other arguments for uvicorn.run.
"""
nest_asyncio.apply()
logger.info(f"Run api server at {host}:{port}")
uvicorn.run(self.app, host=host, port=port, **kwargs)
uvicorn.run(self.app, host=host, port=port, loop="asyncio", **kwargs)


class RunnerInput(BaseModel):
query: str
result_column: str = "answer"
result_column: str = "generated_texts"
2 changes: 2 additions & 0 deletions tests/autorag/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def test_validator_cli():


def test_run_api():
# This test code only tests cli function, not API server itself
# If you are looking for API server test code, please go to test_deploy.py test_runner_api_server()
runner = CliRunner()
result = runner.invoke(cli, ['run_api', '--config_path', 'test/path/test.yaml',
'--host', '0.0.0.0', '--port', '8080'])
Expand Down
2 changes: 0 additions & 2 deletions tests/autorag/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def test_runner_full(evaluator):
def test_runner_api_server(evaluator):
os.environ['BM25'] = 'bm25'
project_dir = evaluator.project_dir
import nest_asyncio
nest_asyncio.apply()
evaluator.start_trial(os.path.join(resource_dir, 'simple.yaml'))
runner = Runner.from_trial_folder(os.path.join(project_dir, '0'))

Expand Down

0 comments on commit 6488163

Please sign in to comment.