Skip to content

Commit

Permalink
Move redis-stream to environment variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
sairam4123 committed Sep 2, 2024
1 parent 96f53ac commit 3475287
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 972 deletions.
1 change: 1 addition & 0 deletions ai/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
REDIS_BROKER=redis://localhost:6379/0
REDIS_BACKEND=redis://localhost:6379/0
MISTRAL_API_KEY=cCpcQhIsggTkErjaa3ZVCtu6XAjetH0h
REDIS_URL=redis://localhost:6379/1
3 changes: 2 additions & 1 deletion ai/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from mistralapi import main as task_ai
from mistralapi import async_main as async_task_ai
from redis import Redis
import os

redis = Redis(host='redis', port=6379, db=1)
redis = Redis.from_url(url=os.environ["REDIS_URL"])

@celery.task
def process_model(data: dict):
Expand Down
6 changes: 3 additions & 3 deletions ai/celery_app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from celery import Celery
from app import *

from dotenv import load_dotenv
load_dotenv()

from celery import Celery
from app import *
import os

celery = Celery("ai", broker=os.environ["REDIS_BROKER"], backend=os.environ["REDIS_BACKEND"])
Expand Down
2 changes: 1 addition & 1 deletion ai/mistralapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def async_main(in_buffer: StringIO, out_buffer: StringIO):
client = Mistral(api_key=api_key)
prompt = construct_prompt(in_buffer)
completion = client.chat.stream(
max_tokens=2**32,
# max_tokens=2**32,
model=model_name,
messages=[
{"role": "user", "content": prompt}
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
environment:
- REDIS_BACKEND=redis://redis:6379/0
- REDIS_BROKER=redis://redis:6379/0
- REDIS_URL=redis://redis:6379/1

client:
container_name: client
Expand Down Expand Up @@ -44,6 +45,7 @@ services:
environment:
- REDIS_BACKEND=redis://redis:6379/0
- REDIS_BROKER=redis://redis:6379/0
- REDIS_URL=redis://redis:6379/1
secrets:
- mistral_ai_key

Expand Down
3 changes: 2 additions & 1 deletion server/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
REDIS_BACKEND=redis://localhost:6379/0
REDIS_BROKER=redis://localhost:6379/0
REDIS_BROKER=redis://localhost:6379/0
REDIS_URL=redis://localhost:6379/1
2 changes: 1 addition & 1 deletion server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CustomizedQueryModel(BaseModel):


celery = Celery(__name__, broker=os.environ["REDIS_BROKER"], backend=os.environ["REDIS_BACKEND"])
redis_client = Redis(host="redis", port=6379, db=1)
redis_client = Redis.from_url(url=os.environ["REDIS_URL"])
celery.conf.broker_connection_retry_on_startup = True
celery.conf.task_routes = {
'main.process_excel': {'queue': 'main'},
Expand Down
Loading

0 comments on commit 3475287

Please sign in to comment.