Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip #2

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1d2a3c3
wip
debdutdeb May 15, 2024
8322f3d
wip add test healthchecks
debdutdeb May 16, 2024
cff24ed
wip healthz endpoints
debdutdeb May 16, 2024
6f62b7c
centralize configs for task-executor
debdutdeb May 16, 2024
c89cdd8
vectordb changes
debdutdeb May 16, 2024
ba2fedb
fix ordering of unpacking stupid
debdutdeb May 16, 2024
0773853
remove cache
debdutdeb May 19, 2024
e3cfd12
make it so we connect to milvus before any actions
debdutdeb May 19, 2024
4a31840
health endpoint for vectordb api
debdutdeb May 19, 2024
63887f8
status codes for healthz
debdutdeb May 19, 2024
0ed071f
run workflow for this branch
debdutdeb May 20, 2024
48390df
trigger workflow
debdutdeb May 20, 2024
d009cde
temp
debdutdeb May 20, 2024
5589458
what i forgot
debdutdeb May 20, 2024
8a98fa4
main-release
debdutdeb May 20, 2024
e2b437d
dont run this workflow
debdutdeb May 20, 2024
81210ea
change to new branch name
debdutdeb May 20, 2024
3d34d60
...
debdutdeb May 21, 2024
fe4f84b
don't build for arm
debdutdeb May 21, 2024
546c926
run for this branch
debdutdeb May 21, 2024
a1d3e84
things you foget to port over
debdutdeb May 21, 2024
acd3358
...
debdutdeb May 21, 2024
e4e6ce2
run workflow
debdutdeb May 21, 2024
77edbba
?
debdutdeb May 21, 2024
f95c9a5
?
debdutdeb May 21, 2024
d7876b8
...Z
debdutdeb May 21, 2024
2a273a8
now revert the force and reduce stress
debdutdeb May 21, 2024
8c8b3cb
fix lower case
Dnouv May 22, 2024
349b54e
..
debdutdeb May 23, 2024
6ff667b
remove older code
debdutdeb May 27, 2024
a0c6be5
?
debdutdeb Jun 5, 2024
b8f289f
Merge branch 'fork-modifications' into modifications
debdutdeb Jun 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/workflows/main-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
push:
branches:
- main
- fork-modifications

jobs:
build-and-push:
Expand All @@ -32,13 +33,22 @@ jobs:
- name: Expose GH Runtime
uses: crazy-max/ghaction-github-runtime@v3

- name: set lower case owner name
run: |
echo "OWNER_LC=${OWNER,,}" >>${GITHUB_ENV}
env:
OWNER: "${{ github.repository_owner }}"

- name: Convert repository name to lowercase
run: echo "REPO_NAME_LC=$(echo ${{ github.event.repository.name }} | awk '{print tolower($0)}')" >> $GITHUB_ENV

- name: Build and Push Docker Images
run: |
make build_and_push_images
env:
REGISTRY: "ghcr.io"
ORG: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
ORG: ${{ env.OWNER_LC }}
REPO: ${{ env.REPO_NAME_LC }}
GITHUB_WORKFLOW: ${{ github.workflow }}

build-tauri:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tag-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- name: Build and Push Docker Images
run: |
TAG=${GITHUB_REF#refs/tags/} make build_and_push_images
TAG=${GITHUB_REF#refs/heads/} make build_and_push_images
env:
REGISTRY: ghcr.io
ORG: ${{ github.repository_owner }}
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:

- name: get release version
id: get_release_version
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
run: echo "TAG=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV

- name: get release id
id: get_release_id
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
TAG := $(or $(TAG),main)
GITHUB_WORKFLOW := $(or $(GITHUB_WORKFLOW),local)
REGISTRY := $(or $(REGISTRY),index.docker.io)
PLATFORMS := linux/amd64,linux/arm64
PLATFORMS := linux/amd64
BUILDX_FLAGS := --platform $(PLATFORMS) --push

define get_full_tag
Expand Down
1 change: 1 addition & 0 deletions core/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .config import *
84 changes: 84 additions & 0 deletions core/config/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from os import getenv

def get_mongo_database_name():
return getenv("MONGODB_DATABASE", "rubra_db")

def get_mongo_url() -> str:
url = getenv("MONGODB_URL")
if url:
return url

host = getenv("MONGODB_HOST", "localhost")
user = getenv("MONGODB_USER", getenv("MONGODB_USERNAME", None))
password = getenv("MONGODB_PASS", getenv("MONGODB_PASSWORD", None))
port = getenv("MONGODB_PORT", 27017)
database = get_mongo_database_name()

if user and not password:
print("MONGODB_USER set but password not found, ignoring user")

if not user and password:
print("MONGODB_PASSWORD set but user not found, ignoring password")

if user and password:
return f"mongodb://{user}:{password}@{host}:${port}/{database}"

return f"mongodb://{host}:{port}/{database}"

def get_redis_url() -> str:
url = getenv("REDIS_URL")
if url:
return url

host = getenv("REDIS_HOST", "localhost")
password = getenv("REDIS_PASS", getenv("REDIS_PASSWORD", None))
user = getenv("REDIS_USER", getenv("REDIS_USERNAME", None))
port = getenv("REDIS_PORT", 6379)
database = getenv("REDIS_DATABASE", 0)

if password:
return f"redis://{user or ''}:{password}@{host}:{port}/{database}"

return f"redis://{host}:{port}/{database}"

def get_litellm_url() -> str:
url = getenv("LITELLM_URL")
if url:
return url

host = getenv("LITELLM_HOST", "localhost")
port = getenv("LITELLM_PORT", 8002)

return f"http://{host}:{port}"

def get_vector_db_url() -> str:
url = getenv("VECTOR_DB_URL")
if url:
return url

host = getenv("VECTOR_DB_HOST", "localhost")
port = getenv("VECTOR_DB_PORT", 8010)

return f"http://{host}:{port}"

def get_embedding_url():
url = getenv("EMBEDDING_URL")
if url:
return url

host = getenv("EMBEDDING_HOST", "localhost")
port = getenv("EMBEDDING_PORT", 8020)

return f"http://{host}:{port}"

mongo_database = get_mongo_database_name()

mongo_url = get_mongo_url()

litellm_url = get_litellm_url()

vector_db_url = get_vector_db_url()

redis_url = get_redis_url()

embedding_url = get_embedding_url()
26 changes: 19 additions & 7 deletions core/local_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
)
from openai import OpenAI

import core.config as configs

ner = spacy.load("en_core_web_sm")

pattern = r">(.*?)</"
Expand All @@ -27,14 +29,15 @@
TOOL_OUTPUT_ROLE = Role7.tool_output.value
QUERY_FORMAT = '{"query": "refined question"}'

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


oai_client = OpenAI(
base_url=f"http://{litellm_host}:8002/v1/",
# base_url="http://localhost:1234/v1/",
api_key="abc",
base_url=f"{configs.litellm_url}/v1",
api_key='sk-something',
)

print(os.getenv("LITELLM_MASTER_KEY", None))

print(configs.litellm_url)

model_name = "custom"

logging.basicConfig(
Expand Down Expand Up @@ -331,8 +334,17 @@ def chat(
):
messages.append(msg)

oai_client = OpenAI(
base_url=f"{configs.litellm_url}/v1",
api_key='sk-something',
)

print(oai_client)

os.environ["OPENAI_API_KEY"] = "sk-something"

response = oai_client.chat.completions.create(
model="openai/custom",
model="ollama/llama3",
messages=messages,
stream=stream,
temperature=0.1,
Expand Down
Empty file added core/tasks/__init__.py
Empty file.
7 changes: 0 additions & 7 deletions core/tasks/celery_config.py

This file was deleted.

30 changes: 30 additions & 0 deletions core/tasks/is_ready.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import socket

import requests

from core.config import litellm_url, vector_db_url

def is_ready():
# response = requests.get(f"{litellm_url}/health", headers={
# "Authorization": f"Bearer {os.getenv('LITELLM_MASTER_KEY', '')}"
# })
# if not response.ok:
# raise Exception(response.text)

# print(response)

response = requests.get(f"{litellm_url}/health/readiness")
if not response.ok:
raise Exception(response.text)

print(response)

response = requests.get(f"{vector_db_url}/healthz")
if not response.ok:
raise Exception(response.text)

print(response)


if __name__ == "__main__":
is_ready()
66 changes: 35 additions & 31 deletions core/tasks/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
import sys
from functools import partial

from typing import cast, Any

# Third Party
from core.tools.knowledge.vector_db.milvus.operations import add_texts, milvus_connection_alias
from langchain.text_splitter import RecursiveCharacterTextSplitter
from core.tools.knowledge.file_knowledge_tool import FileKnowledgeTool
from core.tools.web_browse.web_browse_tool import WebBrowseTool

from pymilvus import connections

# Get the current working directory
current_directory = os.getcwd()

Expand All @@ -31,33 +41,38 @@
from openai import OpenAI
from pymongo import MongoClient

litellm_host = os.getenv("LITELLM_HOST", "localhost")
redis_host = os.getenv("REDIS_HOST", "localhost")
mongodb_host = os.getenv("MONGODB_HOST", "localhost")
import core.config as configs

redis_client = redis.Redis(host=redis_host, port=6379, db=0)
app = Celery("tasks", broker=f"redis://{redis_host}:6379/0")
app.config_from_object("core.tasks.celery_config")
app.autodiscover_tasks(["core.tasks"]) # Explicitly discover tasks in 'app' package
from .is_ready import is_ready

redis_client = cast(redis.Redis, redis.Redis.from_url(configs.redis_url)) # annoyingly from_url returns None, not Self
app = Celery("tasks", broker=configs.redis_url)

# MongoDB Configuration
MONGODB_URL = f"mongodb://{mongodb_host}:27017"
DATABASE_NAME = "rubra_db"
app.autodiscover_tasks(["core.tasks"]) # Explicitly discover tasks in 'app' package

# Global MongoDB client
mongo_client = None
mongo_client: MongoClient = MongoClient(configs.mongo_url)

def ping_pong():
pong = app.control.ping([f'celery@{socket.gethostname()}'])
if len(pong) == 0 or list(pong[0].values())[0].get('ok', None) is None:
raise Exception('ping failed with' + str(pong))

print(pong)


@signals.worker_process_init.connect
def setup_mongo_connection(*args, **kwargs):
global mongo_client
mongo_client = MongoClient(f"mongodb://{mongodb_host}:27017")
async def ensure_connections(*args, **kwargs):
mongo_client.admin.command('ping')

is_ready()

ping_pong()

def create_assistant_message(
thread_id, assistant_id, run_id, content_text, role=Role7.assistant.value
):
db = mongo_client[DATABASE_NAME]
db = mongo_client[configs.mongo_database]

# Generate a unique ID for the message
message_id = f"msg_{uuid.uuid4().hex[:6]}"
Expand Down Expand Up @@ -175,10 +190,6 @@ def rubra_local_agent_chat_completion(


def form_openai_tools(tools, assistant_id: str):
# Third Party
from core.tools.knowledge.file_knowledge_tool import FileKnowledgeTool
from core.tools.web_browse.web_browse_tool import WebBrowseTool

retrieval = FileKnowledgeTool()
googlesearch = WebBrowseTool()
res_tools = []
Expand Down Expand Up @@ -214,13 +225,13 @@ def form_openai_tools(tools, assistant_id: str):

@shared_task
def execute_chat_completion(assistant_id, thread_id, redis_channel, run_id):
db = mongo_client[configs.mongo_database]
try:
oai_client = OpenAI(
base_url=f"http://{litellm_host}:8002/v1/",
api_key="abc", # point to litellm server
base_url=configs.litellm_url,
api_key=os.getenv("LITELLM_MASTER_KEY"), # point to litellm server
)
db = mongo_client[DATABASE_NAME]

print(oai_client.models.list().data)
# Fetch assistant and thread messages synchronously
assistant = db.assistants.find_one({"id": assistant_id})
thread_messages = list(db.messages.find({"thread_id": thread_id}))
Expand Down Expand Up @@ -453,15 +464,8 @@ def execute_chat_completion(assistant_id, thread_id, redis_channel, run_id):

@app.task
def execute_asst_file_create(file_id: str, assistant_id: str):
# Standard Library
import json

# Third Party
from core.tools.knowledge.vector_db.milvus.operations import add_texts
from langchain.text_splitter import RecursiveCharacterTextSplitter

try:
db = mongo_client[DATABASE_NAME]
db = mongo_client[configs.mongo_database]
collection_name = assistant_id
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
parsed_text = ""
Expand Down
9 changes: 4 additions & 5 deletions core/tools/knowledge/file_knowledge_tool.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Standard Library
import json
import os

import core.config as configs

# Third Party
import requests

VECTOR_DB_HOST = os.getenv("VECTOR_DB_HOST", "localhost")
VECTOR_DB_MATCH_URL = f"http://{VECTOR_DB_HOST}:8010/similarity_match"

vector_db_url = f"{configs.vector_db_url}/similarity_search"

class FileKnowledgeTool:
name = "FileKnowledge"
Expand Down Expand Up @@ -42,7 +41,7 @@ def file_knowledge_search_api(query: str, assistant_id: str):
}
)

response = requests.post(VECTOR_DB_MATCH_URL, headers=headers, data=data)
response = requests.post(vector_db_url, headers=headers, data=data)
res = response.json()["response"]
txt = ""
for r in res:
Expand Down
6 changes: 3 additions & 3 deletions core/tools/knowledge/vector_db/milvus/custom_embeddigs.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Standard Library
import json
import os
from typing import List

# Third Party
import requests
from langchain.embeddings.base import Embeddings

HOST = os.getenv("EMBEDDING_HOST", "localhost")
EMBEDDING_URL = f"http://{HOST}:8020/embed_multiple"
import core.config as configs

EMBEDDING_URL = f"{configs.embedding_url}/embed_multiple"


def embed_text(texts: List[str]) -> List[List[float]]:
Expand Down
Loading