Make fastapi a regular dependency (#243)

## PR Description
Changes `pip install 'arcade-ai[fastapi]'` to `pip install arcade-ai`. 
In other words, FastAPI is now a required dependecy of arcade-ai.


Additionally, I snuck in some minor cleanup changes.
This commit is contained in:
Eric Gustin 2025-02-10 15:30:51 -08:00 committed by GitHub
parent a00bd4734e
commit 19086818d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 23 additions and 67 deletions

26
.vscode/launch.json vendored
View file

@ -1,25 +1,9 @@
{ {
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{
"name": "Debug examples/fastapi",
"type": "python",
"request": "launch",
"module": "uvicorn",
"args": [
"main:app",
"--app-dir",
"${workspaceFolder}/examples/fastapi/arcade_example_fastapi",
"--port",
"8002"
],
"jinja": true,
"justMyCode": true,
"cwd": "${workspaceFolder}/examples/fastapi/arcade_example_fastapi"
},
{ {
"name": "Debug `arcade workerup --no-auth`", "name": "Debug `arcade workerup --no-auth`",
"type": "python", "type": "debugpy",
"request": "launch", "request": "launch",
"program": "${workspaceFolder}/arcade/run_cli.py", "program": "${workspaceFolder}/arcade/run_cli.py",
"args": ["workerup", "--no-auth"], "args": ["workerup", "--no-auth"],
@ -29,8 +13,8 @@
"cwd": "${workspaceFolder}" "cwd": "${workspaceFolder}"
}, },
{ {
"name": "Debug `arcade chat -s -d -h localhost`", "name": "Debug `arcade chat -d -h localhost`",
"type": "python", "type": "debugpy",
"request": "launch", "request": "launch",
"program": "${workspaceFolder}/arcade/run_cli.py", "program": "${workspaceFolder}/arcade/run_cli.py",
"args": ["chat", "-d", "-h", "localhost"], "args": ["chat", "-d", "-h", "localhost"],
@ -41,7 +25,7 @@
}, },
{ {
"name": "Debug `arcade dev`", "name": "Debug `arcade dev`",
"type": "python", "type": "debugpy",
"request": "launch", "request": "launch",
"program": "${workspaceFolder}/arcade/run_cli.py", "program": "${workspaceFolder}/arcade/run_cli.py",
"args": ["dev"], "args": ["dev"],
@ -52,7 +36,7 @@
}, },
{ {
"name": "Debug `arcade evals -d` on current file", "name": "Debug `arcade evals -d` on current file",
"type": "python", "type": "debugpy",
"request": "launch", "request": "launch",
"program": "${workspaceFolder}/arcade/run_cli.py", "program": "${workspaceFolder}/arcade/run_cli.py",
"args": ["evals", "-d", "${fileDirname}", "-h", "localhost"], "args": ["evals", "-d", "${fileDirname}", "-h", "localhost"],

View file

@ -91,8 +91,8 @@ build-and-publish: build publish ## Build and publish.
docker: ## Build and run the Docker container docker: ## Build and run the Docker container
@echo "🚀 Building arcade and toolkit wheels..." @echo "🚀 Building arcade and toolkit wheels..."
@make full-dist @make full-dist
@echo "Writing extras requirements.txt" @echo "Writing requirements.txt"
@cd arcade && poetry export --extras "fastapi" --output ../dist/requirements.txt @cd arcade && poetry export --output ../dist/requirements.txt
@echo "🚀 Building Docker image" @echo "🚀 Building Docker image"
@cd docker && make docker-build @cd docker && make docker-build
@cd docker && make docker-run @cd docker && make docker-run
@ -101,8 +101,8 @@ docker: ## Build and run the Docker container
docker-base: ## Build and run the Docker container docker-base: ## Build and run the Docker container
@echo "🚀 Building arcade and toolkit wheels..." @echo "🚀 Building arcade and toolkit wheels..."
@make full-dist @make full-dist
@echo "Writing extras requirements.txt" @echo "Writing requirements.txt"
@cd arcade && poetry export --extras "fastapi" --output ../dist/requirements.txt @cd arcade && poetry export --output ../dist/requirements.txt
@echo "🚀 Building Docker image" @echo "🚀 Building Docker image"
@cd docker && INSTALL_TOOLKITS=false make docker-build @cd docker && INSTALL_TOOLKITS=false make docker-build
@cd docker && INSTALL_TOOLKITS=false make docker-run @cd docker && INSTALL_TOOLKITS=false make docker-run

View file

@ -65,7 +65,7 @@ _Pst. hey, you, give us a star if you like it!_
Install the package: Install the package:
```bash ```bash
pip install 'arcade-ai[fastapi]' pip install arcade-ai
``` ```
Log in to your account via the CLI: Log in to your account via the CLI:

View file

@ -5,24 +5,11 @@ import sys
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from typing import Any from typing import Any
import fastapi
import uvicorn
from loguru import logger from loguru import logger
from arcade.core.telemetry import OTELHandler from arcade.core.telemetry import OTELHandler
try:
import fastapi
except ImportError:
raise ImportError(
"FastAPI is not installed. Please install it using `pip install arcade-ai[fastapi]`."
)
try:
import uvicorn
except ImportError:
raise ImportError(
"Uvicorn is not installed. Please install it using `pip install arcade-ai[fastapi]`."
)
from arcade.sdk import Toolkit from arcade.sdk import Toolkit
from arcade.worker.fastapi.worker import FastAPIWorker from arcade.worker.fastapi.worker import FastAPIWorker

View file

@ -214,7 +214,7 @@ class SimilarityCritic(Critic):
from sklearn.metrics.pairwise import cosine_similarity from sklearn.metrics.pairwise import cosine_similarity
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"Use `pip install arcade[evals]` to install the required dependencies for similarity metrics." "Use `pip install 'arcade-ai[evals]'` to install the required dependencies for similarity metrics."
) )
vectorizer = TfidfVectorizer() vectorizer = TfidfVectorizer()
tfidf_matrix = vectorizer.fit_transform([expected, actual]) tfidf_matrix = vectorizer.fit_transform([expected, actual])

View file

@ -13,7 +13,7 @@ try:
from scipy.optimize import linear_sum_assignment from scipy.optimize import linear_sum_assignment
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"Use `pip install arcade-ai[evals]` to install the required dependencies for evaluation." "Use `pip install 'arcade-ai[evals]'` to install the required dependencies for evaluation."
) )
from openai import AsyncOpenAI from openai import AsyncOpenAI

View file

@ -53,7 +53,7 @@
1. [Install the Arcade Engine Locally](https://docs.arcade.dev/home/install/local) 1. [Install the Arcade Engine Locally](https://docs.arcade.dev/home/install/local)
2. Install extra dependencies needed for evals: 2. Install extra dependencies needed for evals:
```bash ```bash
pip install 'arcade-ai[fastapi,evals]' pip install 'arcade-ai[evals]'
``` ```
3. Log into Arcade: 3. Log into Arcade:
```bash ```bash

View file

@ -1,7 +0,0 @@
import importlib.util
# FastAPI is an optional dependency, so make sure it's installed
if importlib.util.find_spec("fastapi") is None:
raise ImportError(
"FastAPI is not installed. Please install it using `pip install arcade-ai[fastapi]`."
)

View file

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "arcade-ai" name = "arcade-ai"
version = "1.0.1" version = "1.1.0"
description = "Arcade Python SDK and CLI" description = "Arcade Python SDK and CLI"
readme = "README.md" readme = "README.md"
packages = [ packages = [
@ -27,11 +27,11 @@ loguru = "^0.7.0"
tqdm = "^4.1.0" tqdm = "^4.1.0"
types-python-dateutil = "2.9.0.20241003" types-python-dateutil = "2.9.0.20241003"
types-pytz = "2024.2.0.20241003" types-pytz = "2024.2.0.20241003"
opentelemetry-instrumentation-fastapi = {version = "0.48b0", optional = true} opentelemetry-instrumentation-fastapi = "0.48b0"
opentelemetry-exporter-otlp-proto-http = {version = "1.27.0", optional = true} opentelemetry-exporter-otlp-proto-http = "1.27.0"
opentelemetry-exporter-otlp-proto-common = {version = "1.27.0", optional = true} opentelemetry-exporter-otlp-proto-common = "1.27.0"
fastapi = {version = "^0.115.3", optional = true} fastapi = "^0.115.3"
uvicorn = {version = "^0.30.0", optional = true} uvicorn = "^0.30.0"
scipy = {version = "^1.14.0", optional = true} scipy = {version = "^1.14.0", optional = true}
numpy = {version = "^2.0.0", optional = true} numpy = {version = "^2.0.0", optional = true}
scikit-learn = {version = "^1.5.0", optional = true} scikit-learn = {version = "^1.5.0", optional = true}
@ -40,7 +40,6 @@ python-dateutil = {version = "^2.8.2", optional = true}
pyreadline3 = {version = "^3.5.4", platform = "win32"} pyreadline3 = {version = "^3.5.4", platform = "win32"}
[tool.poetry.extras] [tool.poetry.extras]
fastapi = ["fastapi", "uvicorn", "opentelemetry-instrumentation-fastapi", "opentelemetry-exporter-otlp-proto-http", "opentelemetry-exporter-otlp-proto-common"]
evals = ["scipy", "numpy", "scikit-learn", "pytz", "python-dateutil"] evals = ["scipy", "numpy", "scikit-learn", "pytz", "python-dateutil"]
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]

View file

@ -37,7 +37,7 @@ RUN ls -la /app/arcade/
# Conditional installation based on version # Conditional installation based on version
RUN if [ ! "$(echo ${VERSION} | grep -E '\.dev0$')" ]; then \ RUN if [ ! "$(echo ${VERSION} | grep -E '\.dev0$')" ]; then \
echo "Installing wheel file" && \ echo "Installing wheel file" && \
python -m pip install ./arcade_ai-${VERSION}-py3-none-any.whl fastapi && \ python -m pip install ./arcade_ai-${VERSION}-py3-none-any.whl && \
python -m pip install -r ./requirements.txt; \ python -m pip install -r ./requirements.txt; \
else \ else \
echo "Installing from source" && \ echo "Installing from source" && \
@ -45,7 +45,6 @@ RUN if [ ! "$(echo ${VERSION} | grep -E '\.dev0$')" ]; then \
pip install poetry && \ pip install poetry && \
poetry lock && \ poetry lock && \
poetry version 0.1.0 && \ poetry version 0.1.0 && \
pip install fastapi && \
pip install -r requirements.txt && \ pip install -r requirements.txt && \
pip install .; \ pip install .; \
fi fi

View file

@ -7,13 +7,7 @@ app = App("arcade-worker")
toolkits = ["arcade-google", "arcade-slack"] toolkits = ["arcade-google", "arcade-slack"]
image = ( image = Image.debian_slim().pip_install("arcade-ai").pip_install(toolkits)
Image.debian_slim()
.pip_install("arcade-ai[fastapi]")
.pip_install(toolkits)
.pip_install("fastapi>=0.115.3")
.pip_install("uvicorn>=0.24.0")
)
@app.function(image=image) @app.function(image=image)