From e21740575124ad73a674545eb573b22ab09222f8 Mon Sep 17 00:00:00 2001 From: Radoslav Dimitrov Date: Tue, 28 Jan 2025 14:49:38 +0200 Subject: [PATCH 1/2] Add integration tests for Ollama Signed-off-by: Radoslav Dimitrov --- .github/workflows/integration-tests.yml | 38 +++++++++++++++++++++++-- tests/integration/testcases.yaml | 7 +++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 352af48e..94a304bb 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -58,8 +58,7 @@ jobs: echo "Running container from image: $DOCKER_IMAGE" # Run the container - docker run --name $CONTAINER_NAME -d -p 8989:8989 -p 9090:9090 \ - -p 8990:8990 \ + docker run --name $CONTAINER_NAME -d --network host \ -v "$(pwd)"/codegate_volume:/app/codegate_volume \ -e CODEGATE_APP_LOG_LEVEL=DEBUG \ --restart unless-stopped $DOCKER_IMAGE @@ -146,6 +145,41 @@ jobs: run: | poetry run python tests/integration/integration_tests.py + - name: Run Ollama + run: | + docker run -d -v ollama:/root/.ollama --network host --name ollama ollama/ollama + docker ps -f name=ollama + echo "Loop until the endpoint responds successfully" + while ! curl --silent --fail --get "http://localhost:11434" >/dev/null; do + echo "Ollama not available yet. Retrying in 2 seconds..." + sleep 2 + done + echo "Ollama is now available!" + docker exec -d ollama ollama run qwen2.5-coder:0.5b + + sleep 120 # Sleep for 2 minutes to allow Ollama to download the model. TODO: Improve this + docker logs ollama + + # Verify the Ollama API is working + curl http://localhost:11434/api/generate -d '{ + "model": "qwen2.5-coder:0.5b", + "prompt": "Why is the sky blue?", + "stream": false + }' + + docker logs ollama + + - name: Run integration tests - Ollama + env: + CODEGATE_PROVIDERS: "ollama" + run: | + poetry run python tests/integration/integration_tests.py + + - name: Print the Ollama container logs (useful for debugging) + if: always() + run: | + docker logs ollama + - name: Print the container logs (useful for debugging) if: always() run: | diff --git a/tests/integration/testcases.yaml b/tests/integration/testcases.yaml index c61d8a9d..7798bf69 100644 --- a/tests/integration/testcases.yaml +++ b/tests/integration/testcases.yaml @@ -4,6 +4,7 @@ headers: openai: Authorization: Bearer ENV_OPENAI_KEY ollama: + Content-Type: application/json llamacpp: anthropic: x-api-key: ENV_ANTHROPIC_KEY @@ -275,12 +276,12 @@ testcases: "role":"user" } ], - "model":"qwen2.5-coder:latest", + "model":"qwen2.5-coder:0.5b", "stream":true, "temperature":0 } likes: | - Hello! How can I assist you today? If you have any questions or need guidance on secure coding practices, software security, package analysis, or anything else related to cybersecurity, feel free to ask! + Hello! How can I assist you today? ollama_fim: name: Ollama FIM @@ -288,7 +289,7 @@ testcases: url: http://127.0.0.1:8989/ollama/api/generate data: | { - "model": "qwen2.5-coder:latest", + "model": "qwen2.5-coder:0.5b", "max_tokens": 4096, "temperature": 0, "stream": true, From bc8bd401ff6d57110c1d39001ebd463cd95217fb Mon Sep 17 00:00:00 2001 From: Radoslav Dimitrov Date: Wed, 29 Jan 2025 13:58:56 +0200 Subject: [PATCH 2/2] Set the CODEGATE_OLLAMA_URL explicitly Signed-off-by: Radoslav Dimitrov --- .github/workflows/integration-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 94a304bb..4c56a69c 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -61,6 +61,7 @@ jobs: docker run --name $CONTAINER_NAME -d --network host \ -v "$(pwd)"/codegate_volume:/app/codegate_volume \ -e CODEGATE_APP_LOG_LEVEL=DEBUG \ + -e CODEGATE_OLLAMA_URL=http://localhost:11434 \ --restart unless-stopped $DOCKER_IMAGE # Confirm the container started