admin管理员组

文章数量:1389757

I think i tried different solutions, i spent many hours before sending this post, but still I cannot cope by myslef. I am running docker container with Rag chatbot. You will also notice that I am not copying app folder from my localhost into image because I mount volumes to the application, db and documents. Could u help me to solve the issue ? Here is the Dockerfile:

# Use a lightweight Python base image with necessary dependencies
FROM python:3.10-slim

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive \
    PYTHONUNBUFFERED=1 \
    PYTHONPATH=/app

# Install necessary system dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    cmake \
    libgl1-mesa-glx \
    libglib2.0-0 \
    libpoppler-cpp-dev \
    tesseract-ocr \
    portaudio19-dev \
    git \
    ffmpeg \
    mpg321 \
    && rm -rf /var/lib/apt/lists/*

# Set the working directory in the container
WORKDIR /app

# Copy the requirements.txt into the container
COPY requirements.txt /app/

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Expose API port (FastAPI will run on port 8000)
EXPOSE 8000

# Copy the application files into the container
#COPY . /app
 
# Start the bash shell and keep the container running
CMD ["bash", "-c", "while true; do sleep 1000; done"]

I am running this container with that command:

~/projekty/chatbot1$ docker run -p 8000:8000 --name chatbot   -v /home/myuser/projekty/chatbot1/vector_db:/app/vector_db   -v /home/myuser/projekty/chatbot1/documents:/app/documents   -v /home/myuser/projekty/chatbot1/rag-chatbot:/app   -e OPENAI_API_KEY=your-api-key-here   rag-chatbot

Inside container when i run tree, i get:

/app
root@319388c4b543:/app# tree
.
├── Dockerfile
├── Dockerfile (copy)
├── __init__.py
├── app
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-310.pyc
│   │   ├── chatbot.cpython-310.pyc
│   │   ├── main.cpython-310.pyc
│   │   └── tts.cpython-310.pyc
│   ├── chatbot.py
│   ├── documents
│   ├── images
│   ├── llm
│   │   └── anwser_generation.py
│   ├── main.py
│   ├── parsers
│   │   ├── __init__.py
│   │   ├── excel_parser.py
│   │   ├── pdf_parser.py
│   │   └── word_parser.py
│   ├── routes
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-310.pyc
│   │   │   ├── voice_mode.cpython-310.pyc
│   │   │   └── written_mode.cpython-310.pyc
│   │   ├── stt.py
│   │   ├── tts.py
│   │   ├── voice_mode.py
│   │   └── written_mode.py
│   ├── static
│   │   └── index.html
│   ├── stt.py
│   ├── tts.py
│   └── vector_db
├── documents
│   └── Tabb'sTROY-Final.pdf
├── requirements.txt
└── vector_db
    ├── index
    │   ├── =1.10.0,
    │   ├── =1.21.0
    │   ├── =3.7.0,
    │   ├── =4.20.0,
    │   ├── index.faiss
    │   ├── index.faiss2
    │   ├── index.pkl
    │   └── metadata.json
    └── vector_db
        └── index
            ├── index.faiss
            ├── index.faiss2
            ├── index.pkl
            └── metadata.json

16 directories, 40 files

I am running my application inside container with this command:

uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

And I get

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/usr/local/lib/python3.10/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.10/site-packages/uvicorn/_subprocess.py", line 76, in subprocess_started
    target(sockets=sockets)
  File "/usr/local/lib/python3.10/site-packages/uvicorn/server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "uvloop/loop.pyx", line 1518, in uvloop.loop.Loop.run_until_complete
  File "/usr/local/lib/python3.10/site-packages/uvicorn/server.py", line 68, in serve
    config.load()
  File "/usr/local/lib/python3.10/site-packages/uvicorn/config.py", line 473, in load
    self.loaded_app = import_from_string(self.app)
  File "/usr/local/lib/python3.10/site-packages/uvicorn/importer.py", line 24, in import_from_string
    raise exc from None
  File "/usr/local/lib/python3.10/site-packages/uvicorn/importer.py", line 21, in import_from_string
    module = importlib.import_module(module_str)
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/app/app/__init__.py", line 4, in <module>
    from app.main import app
  File "/app/app/main.py", line 4, in <module>
    from app.routes.voice_mode import router as voice_router
  File "/app/app/routes/voice_mode.py", line 3, in <module>
    from .sst import speech_to_text
ModuleNotFoundError: No module named 'app.routes.sst'

The /app/app/routes/voice_mode.py file is this one:

from fastapi import APIRouter
#from app.sst import speech_to_text - FAILS
#from ..sst import speech_to_text - FAILS
from .sst import speech_to_text
from .tts import text_to_speech
import openai

(rest not relevant, it fails at line 4) from .sst import speech_to_text

本文标签: