Skip to content

Commit

Permalink
chore: introduce more variables for different config
Browse files Browse the repository at this point in the history
chore: update workflow to run

trigger workflow
  • Loading branch information
debdutdeb committed Apr 29, 2024
1 parent abf872e commit 7b000e6
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ concurrency:
on:
push:
branches:
- main
- chore/new-environment-variable-configuration

jobs:
build-and-push:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,4 @@ dist-ssr
*.sln
*.sw?

**/.vim/
4 changes: 2 additions & 2 deletions core/local_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
QUERY_FORMAT = '{"query": "refined question"}'

litellm_host = os.getenv("LITELLM_HOST", "localhost")

litellm_api_key = os.getenv("LITELLM_MASTER_KEY")

oai_client = OpenAI(
base_url=f"http://{litellm_host}:8002/v1/",
# base_url="http://localhost:1234/v1/",
api_key="abc",
api_key=litellm_api_key,
)
model_name = "custom"

Expand Down
5 changes: 3 additions & 2 deletions core/tasks/celery_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os

CELERY_REDIS_HOST = os.getenv("REDIS_HOST", "localhost")
BROKER_URL = f"redis://{CELERY_REDIS_HOST}:6379/0" # Redis configuration
CELERY_RESULT_BACKEND = f"redis://{CELERY_REDIS_HOST}:6379/0"
CELERY_REDIS_PORT = os.getenv("REDIS_PORT", 6379)
BROKER_URL = f"redis://{CELERY_REDIS_HOST}:{CELERY_REDIS_PORT}/0" # Redis configuration
CELERY_RESULT_BACKEND = BROKER_URL
CELERY_IMPORTS = ("core.tasks.tasks",)
2 changes: 2 additions & 0 deletions core/tasks/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from openai import OpenAI
from pymongo import MongoClient

from

litellm_host = os.getenv("LITELLM_HOST", "localhost")
redis_host = os.getenv("REDIS_HOST", "localhost")
mongodb_host = os.getenv("MONGODB_HOST", "localhost")
Expand Down
66 changes: 53 additions & 13 deletions services/backend/api_server/app/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,16 @@
generate_thread_id,
)

litellm_host = os.getenv("LITELLM_HOST", "localhost")
redis_host = os.getenv("REDIS_HOST", "localhost")
mongodb_host = os.getenv("MONGODB_HOST", "localhost")

app = FastAPI()

origins = [
default_origins = [
"http://localhost:3000", # Add the frontend host here
"http://localhost",
"https://docs.rubra.ai",
]

origins = os.getenv("CORS_ALLOWED_ORIGINS", default_origins)

app.add_middleware(
CORSMiddleware,
allow_origins=origins,
Expand All @@ -124,17 +122,59 @@
allow_headers=["*"], # Allows all headers
)


def _get_mongo_url():
url = os.getenv("MONGODB_URL")
if url:
return url

host = os.getenv("MONGODB_HOST", "localhost")
user = os.getenv("MONGODB_USER")
password = os.getenv("MONGODB_PASSWORD")
port = os.getenv("MONGODB_PORT", 27017)
if (
not user or not password
): # if any of these not passed, just return unauthenticated url
return f"mongodb://{host}:{port}"

return f"mongodb://{user}:{password}@{host}:{port}"


def _get_litellm_proxy_url():
host = os.getenv("LITELLM_HOST", "localhost")
port = os.getenv("LITELLM_PORT", 8002)
return f"http://{host}:{port}"


def _get_redis_url():
url = os.getenv("REDIS_URL")
if url:
return url

host = os.getenv("REDIS_HOST", "localhost")
user = os.getenv("REDIS_USER")
password = os.getenv("REDIS_PASSWORD")
port = os.getenv("REDIS_PORT", 6379)

if not password:
return f"redis://{host}:{port}/0"

return f"redis://{user}:{password}@{host}:{port}/0"


# MongoDB Configurationget
MONGODB_URL = f"mongodb://{mongodb_host}:27017"
DATABASE_NAME = "rubra_db"
LITELLM_URL = f"http://{litellm_host}:8002"
MONGODB_URL = _get_mongo_url()
DATABASE_NAME = os.getenv("MONGODB_DATABASE", "rubra_db")
LITELLM_URL = _get_litellm_proxy_url()
HEADERS = {"accept": "application/json", "Content-Type": "application/json"}

# Initialize MongoDB client
mongo_client = AsyncIOMotorClient(MONGODB_URL)
database = mongo_client[DATABASE_NAME]

celery_app = Celery(broker=f"redis://{redis_host}:6379/0")
redis_url = _get_redis_url()

celery_app = Celery(broker=redis_url)

logging.basicConfig(level=logging.INFO)

Expand Down Expand Up @@ -203,7 +243,7 @@ async def on_startup():
async def get_api_key_status():
try:
redis = await aioredis.from_url(
f"redis://{redis_host}:6379/0", encoding="utf-8", decode_responses=True
redis_url, encoding="utf-8", decode_responses=True
)
openai_key = await redis.get("OPENAI_API_KEY")
anthropic_key = await redis.get("ANTHROPIC_API_KEY")
Expand All @@ -226,7 +266,7 @@ async def get_api_key_status():
async def set_api_key_status(api_keys: ApiKeysUpdateModel):
try:
redis = await aioredis.from_url(
f"redis://{redis_host}:6379/0", encoding="utf-8", decode_responses=True
redis_url, encoding="utf-8", decode_responses=True
)

logging.info("Setting API keys")
Expand Down Expand Up @@ -752,7 +792,7 @@ async def list_messages(
async def redis_subscriber(channel, timeout=1):
logging.info(f"Connecting to Redis and subscribing to channel: {channel}")
redis = await aioredis.from_url(
f"redis://{redis_host}:6379/0", encoding="utf-8", decode_responses=True
redis_url, encoding="utf-8", decode_responses=True
)
pubsub = redis.pubsub()
await pubsub.subscribe(channel)
Expand Down Expand Up @@ -782,7 +822,7 @@ async def listen_for_task_status(
pubsub = None
try:
redis = await aioredis.from_url(
f"redis://{redis_host}:6379/0", encoding="utf-8", decode_responses=True
redis_url, encoding="utf-8", decode_responses=True
)
pubsub = redis.pubsub()
await pubsub.subscribe(task_status_channel)
Expand Down

0 comments on commit 7b000e6

Please sign in to comment.