Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
[server] Moved FastAPI app to its own 'canopy_server' sub-package
Browse files Browse the repository at this point in the history
  • Loading branch information
igiloh-pinecone committed Oct 26, 2023
1 parent d586a48 commit b99eac5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ authors = ["Relevance Team <[email protected]>"]
readme = "README.md"
license = "Apache-2.0"
packages = [{include = "canopy", from = "src"},
{include = "canopy_cli", from = "src"},]
{include = "canopy_cli", from = "src"},
{include = "canopy_server", from = "src"},]

[tool.poetry.dependencies]
python = "^3.9"
Expand Down
10 changes: 5 additions & 5 deletions src/canopy_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

from canopy import __version__

from .app import start as start_service
from canopy_server.app import start as start_service
from .cli_spinner import Spinner
from .api_models import ChatDebugInfo
from canopy_server.api_models import ChatDebugInfo


load_dotenv()
Expand Down Expand Up @@ -479,7 +479,7 @@ def start(host: str, port: str, reload: bool, config: Optional[str]):
"🚨 Note 🚨\n"
"For debugging only. To run the Canopy service in production, run the command:"
"\n"
"gunicorn canopy_cli.app:app --worker-class uvicorn.workers.UvicornWorker "
"gunicorn canopy_server.app:app --worker-class uvicorn.workers.UvicornWorker "
f"--bind {host}:{port} --workers <num_workers>"
)
for c in note_msg:
Expand All @@ -504,7 +504,7 @@ def start(host: str, port: str, reload: bool, config: Optional[str]):
help="URL of the Canopy service to use. Defaults to http://0.0.0.0:8000")
def stop(url):
# Check if the service was started using Gunicorn
res = subprocess.run(["pgrep", "-f", "gunicorn canopy_cli.app:app"],
res = subprocess.run(["pgrep", "-f", "gunicorn canopy_server.app:app"],
capture_output=True)
output = res.stdout.decode("utf-8").split()

Expand All @@ -514,7 +514,7 @@ def stop(url):
"Do you want to kill all Gunicorn processes?")
click.confirm(click.style(msg, fg="red"), abort=True)
try:
subprocess.run(["pkill", "-f", "gunicorn canopy_cli.app:app"], check=True)
subprocess.run(["pkill", "-f", "gunicorn canopy_server.app:app"], check=True)
except subprocess.CalledProcessError:
try:
[os.kill(int(pid), signal.SIGINT) for pid in output]
Expand Down
Empty file added src/canopy_server/__init__.py
Empty file.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/canopy_cli/app.py → src/canopy_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

from canopy.models.api_models import StreamingChatResponse, ChatResponse
from canopy.models.data_models import Context
from canopy_cli.api_models import \
ChatRequest, ContextQueryRequest, \
ContextUpsertRequest, HealthStatus, ContextDeleteRequest
from .api_models import \
ChatRequest, ContextQueryRequest, \
ContextUpsertRequest, HealthStatus, ContextDeleteRequest

from canopy.llm.openai import OpenAILLM
from canopy_cli.errors import ConfigError
Expand Down Expand Up @@ -260,7 +260,7 @@ def start(host="0.0.0.0", port=8000, reload=False, config_file=None):
if config_file:
os.environ["CANOPY_CONFIG_FILE"] = config_file

uvicorn.run("canopy_cli.app:app", host=host, port=port, reload=reload, workers=0)
uvicorn.run("canopy_server.app:app", host=host, port=port, reload=reload, workers=0)


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

from canopy.knowledge_base import KnowledgeBase

from canopy_cli.app import app
from canopy_cli.api_models import (HealthStatus, ContextUpsertRequest,
ContextQueryRequest)
from canopy_server.app import app
from canopy_server.api_models import (HealthStatus, ContextUpsertRequest,
ContextQueryRequest)
from .. import Tokenizer

upsert_payload = ContextUpsertRequest(
Expand Down

0 comments on commit b99eac5

Please sign in to comment.