version: '3.8'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
container_name: elasticsearch
environment:
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ports:
- "9200:9200"
volumes:
- esdata:/usr/share/elasticsearch/data
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:9200 || exit 1"]
interval: 30s
timeout: 10s
retries: 5
pokemon_app:
build: .
container_name: pokemon_app
ports:
- "8000:8000"
depends_on:
elasticsearch:
condition: service_healthy
ollama:
condition: service_started
environment:
LLM_MODEL_NAME: ${LLM_MODEL_NAME}
ELASTICSEARCH_URL: ${ELASTICSEARCH_URL}
OLLAMA_URL: ${OLLAMA_URL}
LOG_LEVEL: DEBUG
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8000/healthcheck || exit 1"]
interval: 30s
timeout: 10s
retries: 5
ollama:
image: ollama/ollama:latest
container_name: ollama
volumes:
- ollama:/root/.ollama
ports:
- "11434:11434"
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:11434 || exit 1"]
interval: 30s
timeout: 10s
retries: 5
volumes:
esdata:
driver: local
ollama:
driver: local
我在应用中使用的默认LLM名称具有此ENV变量:
LLM_MODEL_NAME
我如何做到这一点,以便通过更改ENV变量的价值,我控制了Ollama使用哪种模型?
ollama
的ENV变量指定模型。 我的服务开始后,我有一个入口点bash脚本,称为
LLM_MODEL_VERSION
:
ollama
所以我的新yaml是:
ollama_entrypoint.sh
现在我指定的.env文件中:#!/bin/bash
echo "Starting Ollama..."
/bin/ollama serve &
pid=$!
echo "Waiting for Ollama to start..."
until ollama list > /dev/null 2>&1; do
sleep 2
done
MODEL_NAME=${LLM_MODEL_VERSION}
if ollama list | grep -q "$MODEL_NAME"; then
echo "Model $MODEL_NAME already available."
else
echo "Retrieving model: $MODEL_NAME"
ollama pull "$MODEL_NAME"
echo "Model $MODEL_NAME is ready!"
fi
wait $pid
然后
version: '3.8'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
container_name: elasticsearch
environment:
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ports:
- "9200:9200"
volumes:
- esdata:/usr/share/elasticsearch/data
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:9200 || exit 1"]
interval: 30s
timeout: 10s
retries: 5
pokemon_app:
build: .
container_name: pokemon_app
ports:
- "8000:8000"
depends_on:
- elasticsearch
- ollama
environment:
- LLM_MODEL_VERSION=${LLM_MODEL_VERSION}
- ELASTICSEARCH_URL=${ELASTICSEARCH_URL}
- OLLAMA_URL=${OLLAMA_URL}
- LOG_LEVEL=DEBUG
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8000/healthcheck || exit 1"]
interval: 30s
timeout: 10s
retries: 5
ollama:
image: ollama/ollama:0.5.7
container_name: ollama
volumes:
- ollama:/root/.ollama
- ./ollama_entrypoint.sh:/ollama_entrypoint.sh
ports:
- "11434:11434"
environment:
- LLM_MODEL_VERSION=${LLM_MODEL_VERSION}
entrypoint: ["/bin/bash", "/ollama_entrypoint.sh"]
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:11434 || exit 1"]
interval: 30s
timeout: 10s
retries: 5
volumes:
esdata:
driver: local
ollama:
driver: local
服务在星星之后下载,我的pokemon_app也知道在来自同一环境变量的调用中使用此型号