Skip to content

Commit a326c37

Browse files
Add files via upload
1 parent 4fa3d41 commit a326c37

12 files changed

Lines changed: 190 additions & 0 deletions

File tree

omnicare-engine/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt .
6+
RUN pip install --no-cache-dir -r requirements.txt
7+
8+
COPY . .
9+
10+
EXPOSE 8000
11+
12+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

omnicare-engine/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# OmniCare Engine
2+
3+
Enterprise customer support engine integrating Claude, Llama, Mistral, RAG, Bedrock Agents, Guardrails, and Long-Term Memory (LTM).
4+
5+
## Quickstart
6+
7+
1. Run locally via Docker Compose:
8+
```bash
9+
docker-compose up --build
10+
```
11+
12+
2. Deploy to AWS ECR:
13+
```bash
14+
chmod +x deploy.sh
15+
./deploy.sh
16+
```

omnicare-engine/app/__init__.py

Whitespace-only changes.

omnicare-engine/app/audit.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import requests
2+
import os
3+
4+
def async_llama_audit(user_id: str, prompt: str, response: str):
5+
llama_url = os.getenv("LLAMA_HOST", "http://localhost:11434/api/generate")
6+
payload = {
7+
"model": "llama3",
8+
"prompt": f"Audit transaction for user {user_id}.\nInput: {prompt}\nOutput: {response}",
9+
"stream": False
10+
}
11+
try:
12+
requests.post(llama_url, json=payload, timeout=2)
13+
except Exception:
14+
pass

omnicare-engine/app/ltm.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import boto3
2+
import os
3+
4+
def get_user_ltm(user_id: str) -> dict:
5+
dynamodb = boto3.resource('dynamodb', region_name=os.getenv('AWS_REGION', 'us-east-1'))
6+
table = dynamodb.Table('OmniCare_UserMemory')
7+
try:
8+
response = table.get_item(Key={'userId': user_id})
9+
return response.get('Item', {'preferred_color': 'Blue', 'vip_status': True})
10+
except Exception:
11+
return {'preferred_color': 'Unknown', 'vip_status': False}

omnicare-engine/app/main.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from fastapi import FastAPI, BackgroundTasks
2+
from pydantic import BaseModel
3+
from app.routing import classify_intent
4+
from app.ltm import get_user_ltm
5+
from app.rag import retrieve_policy_context
6+
from app.orchestrator import generate_response
7+
from app.audit import async_llama_audit
8+
9+
app = FastAPI(title="OmniCare Engine")
10+
11+
class RequestModel(BaseModel):
12+
user_id: str
13+
prompt: str
14+
15+
@app.get("/health")
16+
def health_check():
17+
return {"status": "healthy"}
18+
19+
@app.post("/chat")
20+
def process_request(data: RequestModel, background_tasks: BackgroundTasks):
21+
intent = classify_intent(data.prompt)
22+
ltm_data = get_user_ltm(data.user_id)
23+
rag_data = retrieve_policy_context(data.prompt)
24+
25+
answer = generate_response(data.prompt, ltm_data, rag_data)
26+
27+
# Run self-hosted Llama audit asynchronously
28+
background_tasks.add_task(async_llama_audit, data.user_id, data.prompt, answer)
29+
30+
return {
31+
"intent": intent,
32+
"response": answer
33+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import boto3
2+
import os
3+
4+
def generate_response(user_prompt: str, ltm_context: dict, rag_context: str) -> str:
5+
bedrock = boto3.client('bedrock-runtime', region_name=os.getenv('AWS_REGION', 'us-east-1'))
6+
7+
system_context = f"User Memory (LTM): {ltm_context}\nPolicy Context (RAG): {rag_context}"
8+
guardrail_id = os.getenv('BEDROCK_GUARDRAIL_ID')
9+
10+
kwargs = {
11+
"modelId": "anthropic.claude-3-5-sonnet-20240620-v1:0",
12+
"messages": [{"role": "user", "content": [{"text": user_prompt}]}],
13+
"system": [{"text": system_context}]
14+
}
15+
16+
if guardrail_id:
17+
kwargs["guardrailConfig"] = {
18+
"guardrailIdentifier": guardrail_id,
19+
"guardrailVersion": "1"
20+
}
21+
22+
response = bedrock.converse(**kwargs)
23+
return response['output']['message']['content'][0]['text']

omnicare-engine/app/rag.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from opensearchpy import OpenSearch
2+
import os
3+
4+
def retrieve_policy_context(query: str) -> str:
5+
host = os.getenv('OPENSEARCH_HOST')
6+
if not host:
7+
return "Standard 30-day return policy applies."
8+
9+
client = OpenSearch(hosts=[{'host': host, 'port': 443}], use_ssl=True)
10+
search_query = {"size": 1, "query": {"match": {"text": query}}}
11+
try:
12+
res = client.search(body=search_query, index="policies")
13+
return res['hits']['hits'][0]['_source']['text']
14+
except Exception:
15+
return "Standard policy document context."

omnicare-engine/app/routing.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
from mistralai import Mistral
3+
4+
def classify_intent(user_query: str) -> str:
5+
api_key = os.getenv("MISTRAL_API_KEY")
6+
if not api_key:
7+
return "GENERAL"
8+
client = Mistral(api_key=api_key)
9+
prompt = f"Classify intent into strictly one word [REFUND, INVENTORY, GENERAL]: {user_query}"
10+
response = client.chat.complete(
11+
model="mistral-small-latest",
12+
messages=[{"role": "user", "content": prompt}]
13+
)
14+
return response.choices[0].message.content.strip().upper()

omnicare-engine/deploy.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Config settings
5+
AWS_REGION="us-east-1"
6+
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
7+
ECR_REPO_NAME="omnicare-engine"
8+
IMAGE_TAG="latest"
9+
10+
echo "=== Step 1: Authenticating Docker to AWS ECR ==="
11+
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
12+
13+
echo "=== Step 2: Creating ECR Repository (if not exists) ==="
14+
aws ecr describe-repositories --repository-names $ECR_REPO_NAME --region $AWS_REGION || \
15+
aws ecr create-repository --repository-name $ECR_REPO_NAME --region $AWS_REGION
16+
17+
echo "=== Step 3: Building and Tagging Docker Image ==="
18+
docker build -t $ECR_REPO_NAME .
19+
docker tag $ECR_REPO_NAME:latest $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPO_NAME:$IMAGE_TAG
20+
21+
echo "=== Step 4: Pushing Docker Image to ECR ==="
22+
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPO_NAME:$IMAGE_TAG
23+
24+
echo "=== Success! Docker image deployed to ECR ==="
25+
echo "URI: $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPO_NAME:$IMAGE_TAG"

0 commit comments

Comments
 (0)