mirror of
https://github.com/ijaric/voice_assistant.git
synced 2025-12-14 19:06:17 +00:00
feat: [#60] review fix
This commit is contained in:
@@ -18,6 +18,11 @@ RUN pip install poetry \
|
||||
|
||||
COPY bin /opt/app/bin
|
||||
COPY lib /opt/app/lib
|
||||
|
||||
COPY alembic /opt/app/alembic
|
||||
COPY alembic.ini /opt/app/alembic.ini
|
||||
|
||||
COPY entrypoint.sh /opt/app/entrypoint.sh
|
||||
|
||||
RUN chmod +x /opt/app/entrypoint.sh
|
||||
ENTRYPOINT ["/opt/app/entrypoint.sh"]
|
||||
|
||||
@@ -2,7 +2,7 @@ version: "3"
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:15.2
|
||||
image: ankane/pgvector:v0.5.0
|
||||
restart: always
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
@@ -13,6 +13,7 @@ services:
|
||||
ports:
|
||||
- "${POSTGRES_PORT}:${POSTGRES_PORT}"
|
||||
volumes:
|
||||
- ./dump.sql:/docker-entrypoint-initdb.d/dump.sql:ro
|
||||
- postgres_data:/var/lib/postgresql/data/
|
||||
networks:
|
||||
- backend_network
|
||||
@@ -23,7 +24,6 @@ services:
|
||||
container_name: fastapi_app
|
||||
image: fastapi_app
|
||||
restart: always
|
||||
entrypoint: ["/opt/app/entrypoint.sh"]
|
||||
env_file:
|
||||
- .env
|
||||
ports:
|
||||
@@ -48,9 +48,6 @@ services:
|
||||
networks:
|
||||
- api_network
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
|
||||
networks:
|
||||
api_network:
|
||||
driver: bridge
|
||||
|
||||
@@ -23,7 +23,6 @@ services:
|
||||
container_name: api
|
||||
image: fastapi_app
|
||||
restart: always
|
||||
entrypoint: ["/opt/app/entrypoint.sh"]
|
||||
env_file:
|
||||
- .env
|
||||
expose:
|
||||
|
||||
@@ -23,7 +23,6 @@ services:
|
||||
container_name: api
|
||||
image: fastapi_app
|
||||
restart: always
|
||||
entrypoint: ["/opt/app/entrypoint.sh"]
|
||||
env_file:
|
||||
- .env
|
||||
expose:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
while ! nc -z postgres 5432; do sleep 1; done;
|
||||
while ! nc -z $POSTGRES_HOST $POSTGRES_PORT; do sleep 1; done;
|
||||
|
||||
alembic upgrade head
|
||||
poetry run alembic upgrade head
|
||||
|
||||
exec .venv/bin/python -m bin
|
||||
|
||||
@@ -7,6 +7,7 @@ import sqlalchemy.ext.asyncio as sa_asyncio
|
||||
import lib.agent.repositories as repositories
|
||||
import lib.models as models
|
||||
import lib.orm_models as orm_models
|
||||
import lib.app.settings as app_settings
|
||||
|
||||
|
||||
class OpenAIFunctions:
|
||||
@@ -16,10 +17,12 @@ class OpenAIFunctions:
|
||||
self,
|
||||
repository: repositories.EmbeddingRepository,
|
||||
pg_async_session: sa_asyncio.async_sessionmaker[sa_asyncio.AsyncSession],
|
||||
settings: app_settings.Settings,
|
||||
) -> None:
|
||||
self.logger = logging.getLogger(__name__)
|
||||
self.pg_async_session = pg_async_session
|
||||
self.repository = repository
|
||||
self.settings = settings
|
||||
|
||||
async def get_movie_by_description(self, description: str) -> list[models.Movie] | None:
|
||||
"""Use this function to find data about a movie by movie's description."""
|
||||
@@ -32,7 +35,7 @@ class OpenAIFunctions:
|
||||
stmt = (
|
||||
sa.select(orm_models.FilmWork)
|
||||
.order_by(orm_models.FilmWork.embeddings.cosine_distance(embedded_description.root))
|
||||
.limit(5)
|
||||
.limit(self.settings.agent.embeddings_limit)
|
||||
)
|
||||
response = await session.execute(stmt)
|
||||
neighbours = response.scalars()
|
||||
|
||||
@@ -47,4 +47,3 @@ class VoiceResponseHandler:
|
||||
)
|
||||
)
|
||||
return fastapi.responses.StreamingResponse(io.BytesIO(response.audio_content), media_type="audio/ogg")
|
||||
# return fastapi.responses.StreamingResponse(io.BytesIO(voice), media_type="audio/ogg")
|
||||
|
||||
@@ -97,7 +97,9 @@ class Application:
|
||||
)
|
||||
embedding_repository = agent_repositories.EmbeddingRepository(settings=settings)
|
||||
agent_tools = agent_functions.OpenAIFunctions(
|
||||
repository=embedding_repository, pg_async_session=postgres_client.get_async_session()
|
||||
repository=embedding_repository,
|
||||
pg_async_session=postgres_client.get_async_session(),
|
||||
settings=settings
|
||||
)
|
||||
tts_yandex_repository = tts.TTSYandexRepository(
|
||||
tts_settings=app_split_settings.TTSYandexSettings(),
|
||||
|
||||
@@ -4,6 +4,7 @@ import lib.app.split_settings as app_split_settings
|
||||
|
||||
|
||||
class Settings(pydantic_settings.BaseSettings):
|
||||
agent: app_split_settings.AgentSettings = app_split_settings.AgentSettings()
|
||||
api: app_split_settings.ApiSettings = app_split_settings.ApiSettings()
|
||||
app: app_split_settings.AppSettings = app_split_settings.AppSettings()
|
||||
postgres: app_split_settings.PostgresSettings = app_split_settings.PostgresSettings()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from .agent import *
|
||||
from .api import *
|
||||
from .app import *
|
||||
from .logger import *
|
||||
@@ -9,6 +10,7 @@ from .tts import *
|
||||
from .voice import *
|
||||
|
||||
__all__ = [
|
||||
"AgentSettings",
|
||||
"ApiSettings",
|
||||
"AppSettings",
|
||||
"LoggingSettings",
|
||||
|
||||
14
src/assistant/lib/app/split_settings/agent.py
Normal file
14
src/assistant/lib/app/split_settings/agent.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import pydantic_settings
|
||||
|
||||
import lib.app.split_settings.utils as app_split_settings_utils
|
||||
|
||||
|
||||
class AgentSettings(pydantic_settings.BaseSettings):
|
||||
model_config = pydantic_settings.SettingsConfigDict(
|
||||
env_file=app_split_settings_utils.ENV_PATH,
|
||||
env_prefix="AGENT_",
|
||||
env_file_encoding="utf-8",
|
||||
extra="ignore",
|
||||
)
|
||||
|
||||
embeddings_limit: int = 5
|
||||
@@ -13,7 +13,7 @@ COPY poetry.toml /opt/app/poetry.toml
|
||||
|
||||
WORKDIR /opt/app
|
||||
|
||||
RUN pip install poetry \
|
||||
RUN pip install poetry \
|
||||
&& poetry install --no-dev
|
||||
|
||||
COPY bin /opt/app/bin
|
||||
@@ -21,3 +21,5 @@ COPY lib /opt/app/lib
|
||||
COPY entrypoint.sh /opt/app/entrypoint.sh
|
||||
|
||||
RUN chmod +x /opt/app/entrypoint.sh
|
||||
|
||||
CMD [".venv/bin/python", "-m", "bin"]
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
while ! nc -z postgres 5432; do sleep 1; done;
|
||||
|
||||
exec .venv/bin/python -m bin
|
||||
Reference in New Issue
Block a user