Skip to content

Commit

Permalink
✨ entrypoint.sh container script improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Montleon <jmontleo@redhat.com>
  • Loading branch information
jmontleon committed Jul 3, 2024
1 parent 4ace200 commit da0c1cb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ Kai will also work with [OpenAI API Compatible alternatives](docs/OpenAI-API-Com
1. `cd kai`
1. Make changes to `kai/config.toml` to select your desired provider and model
1. Export `GENAI_KEY` or `OPENAI_API_KEY` as appropriate
1. Run `podman compose up`
1. Run `podman compose up`. It will take the server several minutes to start while data is loaded, the first time this is run.

After the first run the DB will be populated and subsequent starts will be much faster, as long as the kai_kai_db_data volume is not deleted.

To clean up all resources run `podman compose down && podman volume rm kai_kai_db_data`.

### Local Development

Expand Down
33 changes: 24 additions & 9 deletions build/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,33 @@ if [ -f /podman_compose/kai/config.toml ]; then
sed -i "s/^password =.*/password =\"$POSTGRES_PASSWORD\"/g" /kai/kai/config.toml
fi

TABLE=applications
SQL_EXISTS=$(printf '\dt "%s"' "$TABLE")
if [[ $(PGPASSWORD="$POSTGRES_PASSWORD" psql -h "kai_db" -U $POSTGRES_USER -d $POSTGRES_DB -c "$SQL_EXISTS") ]]
then
echo "load-data has run already"
else
echo "load-data has not run yet, starting ..."
echo "Fetching examples"
until PGPASSWORD="$POSTGRES_PASSWORD" pg_isready -q -h kai_db -U $POSTGRES_USER -d $POSTGRES_DB ; do
sleep 1
done

if [ "$USE_HUB_IMPORTER" = "False" ]; then
TABLE=applications
SQL_EXISTS=$(printf "\dt %s" "$TABLE")
STDERR="Did not find any relation"
if PGPASSWORD="$POSTGRES_PASSWORD" psql -h kai_db -U $POSTGRES_USER -d $POSTGRES_DB -c "$SQL_EXISTS" 2>&1 | grep -q -v "$STDERR"; then
echo "################################################"
echo "load-data has run already run, starting server.#"
echo "################################################"
else
echo "################################################"
echo "load-data has never been run. #"
echo "Please wait, this will take a few minutes. #"
echo "################################################"
sleep 5
cd /kai/samples
./fetch_apps.py
cd /kai
python ./kai/service/incident_store/psql.py --config_filepath ./kai/config.toml --drop_tables False
python ./kai/service/incident_store/psql.py --config_filepath ./kai/config.toml --drop_tables False
echo "################################################"
echo "load-data has completed, starting server. #"
echo "################################################"
sleep 5
fi
fi

PYTHONPATH="/kai/kai" exec gunicorn --timeout 3600 -w $NUM_WORKERS --bind 0.0.0.0:8080 --worker-class aiohttp.GunicornWebWorker 'kai.server:app()'
9 changes: 6 additions & 3 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version: "3.4"

x-common-variables: &common-variables
POSTGRES_USER: foo
POSTGRES_PASSWORD: bar
POSTGRES_DB: baz
POSTGRES_USER: kai
POSTGRES_PASSWORD: dog8code
POSTGRES_DB: kai

services:
kai:
Expand All @@ -12,6 +12,9 @@ services:
LOGLEVEL: info
DEMO_MODE: False
NUM_WORKERS: 8
USE_HUB_IMPORTER: False
HUB_URL: "https://localhost"
IMPORTER_ARGS: ""
# Do not edit the variables below otherwise
# you risk committing keys to a public repo
# These lines will pass in the environment
Expand Down
13 changes: 10 additions & 3 deletions kai/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,18 @@ password = "dog8code"
# model = "gpt-3.5-turbo"
# ```

#[models]
#provider = "ChatIBMGenAI"

#[models.args]
#model_id = "mistralai/mixtral-8x7b-instruct-v01"

[embeddings]
todo = true

# **IBM served mistral**
[models]
provider = "ChatIBMGenAI"

[models.args]
model_id = "mistralai/mixtral-8x7b-instruct-v01"

[embeddings]
todo = true

0 comments on commit da0c1cb

Please sign in to comment.