Rulga commited on
Commit
2cacc96
·
1 Parent(s): 2aa225e

Refactor Dockerfile to improve cache directory structure and permissions; update app.py to use a more accurate model identifier and enhance logging for model initialization.

Browse files
Files changed (2) hide show
  1. Dockerfile +8 -4
  2. app.py +10 -3
Dockerfile CHANGED
@@ -13,11 +13,15 @@ RUN apt-get update && apt-get install -y \
13
  RUN mkdir -p /app/vector_store /app/chat_history /app/.cache && \
14
  chmod 777 /app/vector_store /app/chat_history /app/.cache
15
 
16
- # Set environment variables
17
- ENV TRANSFORMERS_CACHE=/app/.cache
18
- ENV HF_HOME=/app/.cache
19
  ENV XDG_CACHE_HOME=/app/.cache
20
 
 
 
 
 
21
  # Copy requirements first to leverage Docker cache
22
  COPY requirements.txt .
23
  RUN pip install --no-cache-dir -r requirements.txt
@@ -36,4 +40,4 @@ EXPOSE 8000
36
  USER 1000
37
 
38
  # Run the application
39
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
 
13
  RUN mkdir -p /app/vector_store /app/chat_history /app/.cache && \
14
  chmod 777 /app/vector_store /app/chat_history /app/.cache
15
 
16
+ # Set environment variables and cache directories
17
+ ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
18
+ ENV HF_HOME=/app/.cache/huggingface
19
  ENV XDG_CACHE_HOME=/app/.cache
20
 
21
+ # Create cache directories with proper permissions
22
+ RUN mkdir -p /app/.cache/huggingface && \
23
+ chmod -R 777 /app/.cache
24
+
25
  # Copy requirements first to leverage Docker cache
26
  COPY requirements.txt .
27
  RUN pip install --no-cache-dir -r requirements.txt
 
40
  USER 1000
41
 
42
  # Run the application
43
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
app.py CHANGED
@@ -113,12 +113,19 @@ def init_models():
113
  api_key=os.getenv("GROQ_API_KEY"),
114
  callback_manager=callback_manager
115
  )
116
- # Используем smaller модель для эмбеддингов
 
117
  embeddings = HuggingFaceEmbeddings(
118
- model_name="intfloat/multilingual-e5-small-instruct"
 
119
  )
 
 
120
  return llm, embeddings
 
121
  except Exception as e:
 
 
122
  raise Exception(f"Model initialization failed: {str(e)}")
123
 
124
  async def fetch_url(session, url):
@@ -394,4 +401,4 @@ def log_interaction(user_input: str, bot_response: str, context: str):
394
 
395
  if __name__ == "__main__":
396
  import uvicorn
397
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
113
  api_key=os.getenv("GROQ_API_KEY"),
114
  callback_manager=callback_manager
115
  )
116
+
117
+ # Используем модель с корректным идентификатором
118
  embeddings = HuggingFaceEmbeddings(
119
+ model_name="sentence-transformers/paraphrase-multilingual-mpnet-base-v2",
120
+ cache_folder="/app/.cache"
121
  )
122
+
123
+ logger.info("Models initialized successfully")
124
  return llm, embeddings
125
+
126
  except Exception as e:
127
+ logger.error(f"Model initialization error: {str(e)}")
128
+ logger.error(traceback.format_exc())
129
  raise Exception(f"Model initialization failed: {str(e)}")
130
 
131
  async def fetch_url(session, url):
 
401
 
402
  if __name__ == "__main__":
403
  import uvicorn
404
+ uvicorn.run(app, host="0.0.0.0", port=8000)