diff --git a/integrations-service/docker-compose.yml b/integrations-service/docker-compose.yml index 2496e7c10..51e8d078f 100644 --- a/integrations-service/docker-compose.yml +++ b/integrations-service/docker-compose.yml @@ -2,8 +2,21 @@ name: julep-integrations # Shared environment variables x--shared-environment: &shared-environment - OPENAI_API_KEY: ${OPENAI_API_KEY} INTEGRATIONS_SERVICE_PORT: ${INTEGRATIONS_SERVICE_PORT:-8000} + RAPID_API_KEY: ${RAPID_API_KEY} + RAPID_API_HOST: ${RAPID_API_HOST} + ARYSHARE_KEY: ${ARYSHARE_KEY} + ARYSHARE_PROFILE_ID: ${ARYSHARE_PROFILE_ID} + BROWSERBASE_API_KEY: ${BROWSERBASE_API_KEY} + BROWSERBASE_PROJECT_ID: ${BROWSERBASE_PROJECT_ID} + OPENWEATHER_API_KEY: ${OPENWEATHER_API_KEY} + SPIDER_API_KEY: ${SPIDER_API_KEY} + BRAVE_API_KEY: ${BRAVE_API_KEY} + LLAMA_API_KEY: ${LLAMA_API_KEY} + CLOUDINARY_API_KEY: ${CLOUDINARY_API_KEY} + CLOUDINARY_API_SECRET: ${CLOUDINARY_API_SECRET} + CLOUDINARY_CLOUD_NAME: ${CLOUDINARY_CLOUD_NAME} + MAILGUN_PASSWORD: ${MAILGUN_PASSWORD} services: integrations: diff --git a/integrations-service/integrations/env.py b/integrations-service/integrations/env.py new file mode 100644 index 000000000..5102d3a00 --- /dev/null +++ b/integrations-service/integrations/env.py @@ -0,0 +1,21 @@ +from environs import Env + +# Initialize the Env object for environment variable parsing. +env = Env() +env.read_env() # Read .env file, if it exists + +# Load environment variables +rapid_api_key = env.str("RAPID_API_KEY") +rapid_api_host = env.str("RAPID_API_HOST") +aryshare_key = env.str("ARYSHARE_KEY") +aryshare_profile_id = env.str("ARYSHARE_PROFILE_ID") +browserbase_api_key = env.str("BROWSERBASE_API_KEY") +browserbase_project_id = env.str("BROWSERBASE_PROJECT_ID") +openweather_api_key = env.str("OPENWEATHER_API_KEY") +spider_api_key = env.str("SPIDER_API_KEY") +brave_api_key = env.str("BRAVE_API_KEY") +llama_api_key = env.str("LLAMA_API_KEY") +cloudinary_api_key = env.str("CLOUDINARY_API_KEY") +cloudinary_api_secret = env.str("CLOUDINARY_API_SECRET") +cloudinary_cloud_name = env.str("CLOUDINARY_CLOUD_NAME") +mailgun_password = env.str("MAILGUN_PASSWORD") diff --git a/integrations-service/integrations/utils/integrations/brave.py b/integrations-service/integrations/utils/integrations/brave.py index 549379a82..7414e081a 100644 --- a/integrations-service/integrations/utils/integrations/brave.py +++ b/integrations-service/integrations/utils/integrations/brave.py @@ -5,6 +5,7 @@ from tenacity import retry, stop_after_attempt, wait_exponential from ...autogen.Tools import BraveSearchArguments, BraveSearchSetup +from ...env import brave_api_key # Import env to access environment variables from ...models import BraveSearchOutput, SearchResult @@ -24,6 +25,10 @@ async def search( assert isinstance(setup, BraveSearchSetup), "Invalid setup" assert isinstance(arguments, BraveSearchArguments), "Invalid arguments" + # Check if the setup.api_key is 'DEMO_API_KEY' and load from environment if true + if setup.api_key == "DEMO_API_KEY": + setup.api_key = brave_api_key + tool = BraveSearch.from_api_key(api_key=setup.api_key, search_kwargs={"count": 3}) result = tool.run(arguments.query) diff --git a/integrations-service/integrations/utils/integrations/browserbase.py b/integrations-service/integrations/utils/integrations/browserbase.py index 2cdd813ff..f9885e976 100644 --- a/integrations-service/integrations/utils/integrations/browserbase.py +++ b/integrations-service/integrations/utils/integrations/browserbase.py @@ -22,6 +22,10 @@ BrowserbaseListSessionsArguments, BrowserbaseSetup, ) +from ...env import ( # Import env to access environment variables + browserbase_api_key, + browserbase_project_id, +) from ...models import ( BrowserbaseCompleteSessionOutput, BrowserbaseCreateSessionOutput, @@ -34,6 +38,11 @@ def get_browserbase_client(setup: BrowserbaseSetup) -> Browserbase: + if setup.api_key == "DEMO_API_KEY": + setup.api_key = browserbase_api_key + if setup.project_id == "DEMO_PROJECT_ID": + setup.project_id = browserbase_project_id + return Browserbase( api_key=setup.api_key, project_id=setup.project_id, @@ -71,6 +80,9 @@ async def create_session( ) -> BrowserbaseCreateSessionOutput: client = get_browserbase_client(setup) + if arguments.project_id == "DEMO_PROJECT_ID": + arguments.project_id = setup.browserbase_project_id + options = CreateSessionOptions( projectId=arguments.project_id or setup.project_id, extensionId=arguments.extension_id, diff --git a/integrations-service/integrations/utils/integrations/cloudinary.py b/integrations-service/integrations/utils/integrations/cloudinary.py index 5562ab968..213efd405 100644 --- a/integrations-service/integrations/utils/integrations/cloudinary.py +++ b/integrations-service/integrations/utils/integrations/cloudinary.py @@ -11,6 +11,11 @@ CloudinarySetup, CloudinaryUploadArguments, ) +from ...env import ( # Import env to access environment variables + cloudinary_api_key, + cloudinary_api_secret, + cloudinary_cloud_name, +) from ...models.cloudinary import CloudinaryEditOutput, CloudinaryUploadOutput @@ -32,9 +37,15 @@ async def media_upload( try: # Configure Cloudinary with credentials cloudinary.config( - cloud_name=setup.cloudinary_cloud_name, - api_key=setup.cloudinary_api_key, - api_secret=setup.cloudinary_api_secret, + cloud_name=setup.cloudinary_cloud_name + if setup.cloudinary_cloud_name != "DEMO_CLOUD_NAME" + else cloudinary_cloud_name, + api_key=setup.cloudinary_api_key + if setup.cloudinary_api_key != "DEMO_API_KEY" + else cloudinary_api_key, + api_secret=setup.cloudinary_api_secret + if setup.cloudinary_api_secret != "DEMO_API_SECRET" + else cloudinary_api_secret, **(setup.params or {}), ) @@ -93,9 +104,15 @@ async def media_edit( try: # Configure Cloudinary with credentials cloudinary.config( - cloud_name=setup.cloudinary_cloud_name, - api_key=setup.cloudinary_api_key, - api_secret=setup.cloudinary_api_secret, + cloud_name=setup.cloudinary_cloud_name + if setup.cloudinary_cloud_name != "DEMO_CLOUD_NAME" + else cloudinary_cloud_name, + api_key=setup.cloudinary_api_key + if setup.cloudinary_api_key != "DEMO_API_KEY" + else cloudinary_api_key, + api_secret=setup.cloudinary_api_secret + if setup.cloudinary_api_secret != "DEMO_API_SECRET" + else cloudinary_api_secret, **(setup.params or {}), ) diff --git a/integrations-service/integrations/utils/integrations/email.py b/integrations-service/integrations/utils/integrations/email.py index c38030128..d7967128f 100644 --- a/integrations-service/integrations/utils/integrations/email.py +++ b/integrations-service/integrations/utils/integrations/email.py @@ -5,6 +5,7 @@ from tenacity import retry, stop_after_attempt, wait_exponential from ...autogen.Tools import EmailArguments, EmailSetup +from ...env import mailgun_password # Import env to access environment variables from ...models import EmailOutput @@ -25,6 +26,9 @@ async def send(setup: EmailSetup, arguments: EmailArguments) -> EmailOutput: message["From"] = arguments.from_ message["To"] = arguments.to + if setup.password == "DEMO_PASSWORD": + setup.password = mailgun_password + with SMTP(setup.host, setup.port) as server: server.login(setup.user, setup.password) server.send_message(message) diff --git a/integrations-service/integrations/utils/integrations/llama_parse.py b/integrations-service/integrations/utils/integrations/llama_parse.py index 1e60dee60..5d15debe5 100644 --- a/integrations-service/integrations/utils/integrations/llama_parse.py +++ b/integrations-service/integrations/utils/integrations/llama_parse.py @@ -6,6 +6,7 @@ from tenacity import retry, stop_after_attempt, wait_exponential from ...autogen.Tools import LlamaParseFetchArguments, LlamaParseSetup +from ...env import llama_api_key # Import env to access environment variables from ...models import LlamaParseFetchOutput @@ -25,6 +26,9 @@ async def parse( assert isinstance(setup, LlamaParseSetup), "Invalid setup" assert isinstance(arguments, LlamaParseFetchArguments), "Invalid arguments" + if setup.llamaparse_api_key == "DEMO_API_KEY": + setup.llamaparse_api_key = llama_api_key + parser = LlamaParse( api_key=setup.llamaparse_api_key, result_type=arguments.result_format, diff --git a/integrations-service/integrations/utils/integrations/spider.py b/integrations-service/integrations/utils/integrations/spider.py index a75fb90c9..baac7c5e6 100644 --- a/integrations-service/integrations/utils/integrations/spider.py +++ b/integrations-service/integrations/utils/integrations/spider.py @@ -3,6 +3,7 @@ from tenacity import retry, stop_after_attempt, wait_exponential from ...autogen.Tools import SpiderFetchArguments, SpiderSetup +from ...env import spider_api_key # Import env to access environment variables from ...models import SpiderFetchOutput @@ -27,6 +28,9 @@ async def crawl( if not url: raise ValueError("URL parameter is required for spider") + if setup.spider_api_key == "DEMO_API_KEY": + setup.spider_api_key = spider_api_key + spider_loader = SpiderLoader( api_key=setup.spider_api_key, url=str(url), diff --git a/integrations-service/integrations/utils/integrations/weather.py b/integrations-service/integrations/utils/integrations/weather.py index 33e36ec2b..19e6c659e 100644 --- a/integrations-service/integrations/utils/integrations/weather.py +++ b/integrations-service/integrations/utils/integrations/weather.py @@ -3,6 +3,7 @@ from tenacity import retry, stop_after_attempt, wait_exponential from ...autogen.Tools import WeatherGetArguments, WeatherSetup +from ...env import openweather_api_key # Import env to access environment variables from ...models import WeatherGetOutput @@ -23,6 +24,9 @@ async def get(setup: WeatherSetup, arguments: WeatherGetArguments) -> WeatherGet location = arguments.location openweathermap_api_key = setup.openweathermap_api_key + if openweathermap_api_key == "DEMO_API_KEY": + openweathermap_api_key = openweather_api_key + if not location: raise ValueError("Location parameter is required for weather data") diff --git a/integrations-service/poetry.lock b/integrations-service/poetry.lock index cbf0da504..2d7e2e309 100644 --- a/integrations-service/poetry.lock +++ b/integrations-service/poetry.lock @@ -756,6 +756,26 @@ files = [ dnspython = ">=2.0.0" idna = ">=2.0.0" +[[package]] +name = "environs" +version = "11.2.1" +description = "simplified environment variable parsing" +optional = false +python-versions = ">=3.8" +files = [ + {file = "environs-11.2.1-py3-none-any.whl", hash = "sha256:9d2080cf25807a26fc0d4301e2d7b62c64fbf547540f21e3a30cc02bc5fbe948"}, + {file = "environs-11.2.1.tar.gz", hash = "sha256:e068ae3174cef52ba4b95ead22e639056a02465f616e62323e04ae08e86a75a4"}, +] + +[package.dependencies] +marshmallow = ">=3.13.0" +python-dotenv = "*" + +[package.extras] +dev = ["environs[tests]", "pre-commit (>=3.5,<5.0)", "tox"] +django = ["dj-database-url", "dj-email-url", "django-cache-url"] +tests = ["environs[django]", "pytest"] + [[package]] name = "fastapi" version = "0.115.4" @@ -4080,4 +4100,4 @@ propcache = ">=0.2.0" [metadata] lock-version = "2.0" python-versions = ">=3.12,<3.13" -content-hash = "f395084232b0cbfaeb8c1fe90c971dbad935d5ef479178b672adaaed6c85e769" +content-hash = "d36621b8c1cc5ff844eff52bb9d622b69dc9d6d512977d6d1fe11b38f22ca4f5" diff --git a/integrations-service/pyproject.toml b/integrations-service/pyproject.toml index 571846b9e..427a59b45 100644 --- a/integrations-service/pyproject.toml +++ b/integrations-service/pyproject.toml @@ -31,6 +31,7 @@ pillow = "^11.0.0" llama-index = "^0.11.22" llama-parse = "^0.5.13" cloudinary = "^1.41.0" +environs = "^11.2.1" [tool.poe.tasks] format = "ruff format"