reorganize folder structure
This commit is contained in:
parent
2aaeff8259
commit
c188497731
@ -1,32 +0,0 @@
|
|||||||
import logging
|
|
||||||
from pgvector.psycopg2 import register_vector
|
|
||||||
import psycopg2
|
|
||||||
|
|
||||||
|
|
||||||
class Database:
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
database,
|
|
||||||
user="postgres",
|
|
||||||
password="postgres",
|
|
||||||
host="localhost",
|
|
||||||
port="5433",
|
|
||||||
) -> None:
|
|
||||||
logging.info("Connecting to database")
|
|
||||||
self.conn = psycopg2.connect(
|
|
||||||
database="rag",
|
|
||||||
user="postgres",
|
|
||||||
password="postgres",
|
|
||||||
host="localhost",
|
|
||||||
port="5433",
|
|
||||||
)
|
|
||||||
register_vector(self.conn)
|
|
||||||
self.cur = self.conn.cursor()
|
|
||||||
self.cur.execute("SELECT version();")
|
|
||||||
logging.info(" DB Version: %s", self.cur.fetchone()[0])
|
|
||||||
logging.info(" psycopg2 Version: %s", psycopg2.__version__)
|
|
||||||
|
|
||||||
def close(self):
|
|
||||||
logging.info("Closing connection to database")
|
|
||||||
self.cur.close()
|
|
||||||
self.conn.close()
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
version: '3.8'
|
|
||||||
services:
|
|
||||||
db:
|
|
||||||
image: pgvector/pgvector:pg16
|
|
||||||
restart: always
|
|
||||||
environment:
|
|
||||||
- POSTGRES_USER=postgres
|
|
||||||
- POSTGRES_PASSWORD=postgres
|
|
||||||
ports:
|
|
||||||
- '5433:5432'
|
|
||||||
volumes:
|
|
||||||
- db:/var/lib/postgresql/data
|
|
||||||
volumes:
|
|
||||||
db:
|
|
||||||
driver: local
|
|
||||||
13
agent/Dockerfile
Normal file
13
agent/Dockerfile
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
FROM python:3.11-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY src/requirements.txt /app/
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY src/ /app/
|
||||||
|
RUN find /app/plugins -name "requirements.txt" -exec sh -c 'pip install --no-cache-dir -r "{}"' \;
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
CMD ["uvicorn", "backend:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||||
30
agent/docker-compose.yml
Normal file
30
agent/docker-compose.yml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
version: '3.7'
|
||||||
|
services:
|
||||||
|
voice-assistant:
|
||||||
|
container_name: voice-assistant
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
networks:
|
||||||
|
smart_home:
|
||||||
|
ipv4_address: 172.21.0.30
|
||||||
|
# db:
|
||||||
|
# image: pgvector/pgvector:pg16
|
||||||
|
# restart: always
|
||||||
|
# environment:
|
||||||
|
# - POSTGRES_USER=postgres
|
||||||
|
# - POSTGRES_PASSWORD=postgres
|
||||||
|
# ports:
|
||||||
|
# - '5433:5432'
|
||||||
|
# volumes:
|
||||||
|
# - db:/var/lib/postgresql/data
|
||||||
|
volumes:
|
||||||
|
db:
|
||||||
|
driver: local
|
||||||
|
networks:
|
||||||
|
smart_home:
|
||||||
|
external:
|
||||||
|
name: smart_home
|
||||||
35
agent/src/db.py
Normal file
35
agent/src/db.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import logging
|
||||||
|
from pgvector.psycopg2 import register_vector
|
||||||
|
import psycopg2
|
||||||
|
|
||||||
|
|
||||||
|
class Database:
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
database,
|
||||||
|
user="postgres",
|
||||||
|
password="postgres",
|
||||||
|
host="localhost",
|
||||||
|
port="5433",
|
||||||
|
) -> None:
|
||||||
|
logging.info("Connecting to database")
|
||||||
|
try:
|
||||||
|
self.conn = psycopg2.connect(
|
||||||
|
database="rag",
|
||||||
|
user="postgres",
|
||||||
|
password="postgres",
|
||||||
|
host="localhost",
|
||||||
|
port="5433",
|
||||||
|
)
|
||||||
|
register_vector(self.conn)
|
||||||
|
self.cur = self.conn.cursor()
|
||||||
|
self.cur.execute("SELECT version();")
|
||||||
|
logging.info(" DB Version: %s", self.cur.fetchone()[0])
|
||||||
|
logging.info(" psycopg2 Version: %s", psycopg2.__version__)
|
||||||
|
except:
|
||||||
|
logging.error("Could not connect to database.")
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
logging.info("Closing connection to database")
|
||||||
|
self.cur.close()
|
||||||
|
self.conn.close()
|
||||||
@ -1,12 +1,17 @@
|
|||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import json
|
import json
|
||||||
from llama_cpp.llama import Llama
|
|
||||||
import logging
|
import logging
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
from sentence_transformers import SentenceTransformer, CrossEncoder
|
|
||||||
from typing import Union, List
|
from typing import Union, List
|
||||||
|
|
||||||
|
try:
|
||||||
|
from llama_cpp.llama import Llama
|
||||||
|
from sentence_transformers import SentenceTransformer, CrossEncoder
|
||||||
|
except ImportError as e:
|
||||||
|
print("Faield to import packages:")
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
class BaseChat:
|
class BaseChat:
|
||||||
def __init__(self, config: dict) -> None:
|
def __init__(self, config: dict) -> None:
|
||||||
@ -39,7 +44,7 @@ class OpenAIChat(BaseChat):
|
|||||||
base_url = self.config["openai"]["base_url"]
|
base_url = self.config["openai"]["base_url"]
|
||||||
else:
|
else:
|
||||||
base_url = None
|
base_url = None
|
||||||
self.client = OpenAI(base_url=base_url)
|
self.client = OpenAI(base_url=base_url, api_key=self.config["openai"]["api_key"])
|
||||||
|
|
||||||
def chat(self, messages, tools) -> str:
|
def chat(self, messages, tools) -> str:
|
||||||
function_map, functions = self.prepare_function_calling(tools)
|
function_map, functions = self.prepare_function_calling(tools)
|
||||||
@ -180,7 +185,7 @@ class LLM:
|
|||||||
else:
|
else:
|
||||||
self.embedding_model = self.config["openai"]["embedding_model"]
|
self.embedding_model = self.config["openai"]["embedding_model"]
|
||||||
self.rerank_model = None
|
self.rerank_model = None
|
||||||
self.embedding_client = OpenAI()
|
self.embedding_client = OpenAI(api_key=self.config["openai"]["api_key"])
|
||||||
|
|
||||||
def query(
|
def query(
|
||||||
self,
|
self,
|
||||||
@ -17,7 +17,12 @@ class Plugin(BasePlugin):
|
|||||||
super().__init__(config=config)
|
super().__init__(config=config)
|
||||||
|
|
||||||
self.spotify = spotipy.Spotify(
|
self.spotify = spotipy.Spotify(
|
||||||
auth_manager=SpotifyOAuth(scope="user-library-read", redirect_uri="http://localhost:8080")
|
auth_manager=SpotifyOAuth(
|
||||||
|
scope="user-library-read",
|
||||||
|
redirect_uri="http://localhost:8080",
|
||||||
|
client_id=self.config["plugins"]["music"]["spotify_client_id"],
|
||||||
|
client_secret=self.config["plugins"]["music"]["spotify_client_secret"]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def _search(self, query: str, limit: int = 10):
|
def _search(self, query: str, limit: int = 10):
|
||||||
1
agent/src/plugins/music/requirements.txt
Normal file
1
agent/src/plugins/music/requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
spotipy
|
||||||
@ -1,11 +1,11 @@
|
|||||||
fastapi
|
fastapi
|
||||||
uvicorn[standard]
|
uvicorn[standard]
|
||||||
openai>=1.11.1
|
openai>=1.11.1
|
||||||
sentence_transformers
|
#sentence_transformers
|
||||||
dateparser
|
dateparser
|
||||||
pgvector
|
pgvector
|
||||||
psycopg2
|
psycopg2-binary
|
||||||
pyyaml
|
pyyaml
|
||||||
gradio
|
gradio
|
||||||
hass-client>=1.0.1
|
hass-client>=1.0.1
|
||||||
llama_cpp_python>=0.2.44
|
#llama_cpp_python>=0.2.44
|
||||||
Loading…
x
Reference in New Issue
Block a user