From 045a8cfdcbbb596ef05d6835ae6b30b602b37cd0 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 9 Mar 2024 16:52:59 -0800 Subject: [PATCH 01/11] (fix) use python 3.8 on ci/cd --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ff6e6e1b2..6375f9ad0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2.1 jobs: local_testing: docker: - - image: circleci/python:3.9 + - image: circleci/python:3.8.18 working_directory: ~/project steps: From 38f9413dfc614537de065be338901379b2fad214 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 9 Mar 2024 16:55:05 -0800 Subject: [PATCH 02/11] (fix) python 3.8 bug --- litellm/llms/prompt_templates/factory.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/litellm/llms/prompt_templates/factory.py b/litellm/llms/prompt_templates/factory.py index a13130c62..dc4207a05 100644 --- a/litellm/llms/prompt_templates/factory.py +++ b/litellm/llms/prompt_templates/factory.py @@ -4,6 +4,7 @@ import json, re, xml.etree.ElementTree as ET from jinja2 import Template, exceptions, Environment, meta from typing import Optional, Any import imghdr, base64 +from typing import List def default_pt(messages): @@ -633,7 +634,7 @@ def anthropic_messages_pt(messages: list): return new_messages -def extract_between_tags(tag: str, string: str, strip: bool = False) -> list[str]: +def extract_between_tags(tag: str, string: str, strip: bool = False) -> List[str]: ext_list = re.findall(f"<{tag}>(.+?)", string, re.DOTALL) if strip: ext_list = [e.strip() for e in ext_list] From bd340562b8abfd856623716c574d6dcdf47f9ab6 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 9 Mar 2024 16:56:46 -0800 Subject: [PATCH 03/11] (fix) use python 3.8 for testing --- .circleci/config.yml | 2 +- litellm/tests/test_completion.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6375f9ad0..3e1fd7f34 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2.1 jobs: local_testing: docker: - - image: circleci/python:3.8.18 + - image: circleci/python:3.8 working_directory: ~/project steps: diff --git a/litellm/tests/test_completion.py b/litellm/tests/test_completion.py index e54617bd9..729bf7bd9 100644 --- a/litellm/tests/test_completion.py +++ b/litellm/tests/test_completion.py @@ -69,7 +69,7 @@ def test_completion_claude(): response = completion( model="claude-instant-1", messages=messages, request_timeout=10 ) - # Add any assertions, here to check response args + # Add any assertions here to check response args print(response) print(response.usage) print(response.usage.completion_tokens) From abe0ec601c21303964f1c9cc8fdd61cf5298c346 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 9 Mar 2024 18:11:11 -0800 Subject: [PATCH 04/11] (test) installing litellm --- .circleci/config.yml | 73 +++------------------------------ litellm/tests/test_python_38.py | 16 ++++++++ 2 files changed, 22 insertions(+), 67 deletions(-) create mode 100644 litellm/tests/test_python_38.py diff --git a/.circleci/config.yml b/.circleci/config.yml index 3e1fd7f34..8834eea26 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,7 @@ version: 2.1 jobs: - local_testing: + installing_litellm_on_python: + local_testing: docker: - image: circleci/python:3.8 working_directory: ~/project @@ -8,87 +9,25 @@ jobs: steps: - checkout - - run: - name: Check if litellm dir was updated or if pyproject.toml was modified - command: | - if [ -n "$(git diff --name-only $CIRCLE_SHA1^..$CIRCLE_SHA1 | grep -E 'pyproject\.toml|litellm/')" ]; then - echo "litellm updated" - else - echo "No changes to litellm or pyproject.toml. Skipping tests." - circleci step halt - fi - - restore_cache: - keys: - - v1-dependencies-{{ checksum ".circleci/requirements.txt" }} - - run: + - run: name: Install Dependencies command: | python -m pip install --upgrade pip python -m pip install -r .circleci/requirements.txt - pip install "pytest==7.3.1" - pip install "pytest-asyncio==0.21.1" - pip install mypy - pip install "google-generativeai>=0.3.2" - pip install "google-cloud-aiplatform>=1.38.0" - pip install "boto3>=1.28.57" - pip install "aioboto3>=12.3.0" - pip install langchain - pip install "langfuse>=2.0.0" - pip install numpydoc - pip install traceloop-sdk==0.0.69 pip install openai pip install prisma pip install "httpx==0.24.1" - pip install "gunicorn==21.2.0" - pip install "anyio==3.7.1" - pip install "aiodynamo==23.10.1" - pip install "asyncio==3.4.3" - pip install "apscheduler==3.10.4" - pip install "PyGithub==1.59.1" - pip install python-multipart - - save_cache: - paths: - - ./venv - key: v1-dependencies-{{ checksum ".circleci/requirements.txt" }} - - run: - name: Run prisma ./entrypoint.sh - command: | - set +e - chmod +x entrypoint.sh - ./entrypoint.sh - set -e - - run: - name: Black Formatting - command: | - cd litellm - python -m pip install black - python -m black . - cd .. - - run: - name: Linting Testing - command: | - cd litellm - python -m pip install types-requests types-setuptools types-redis - if ! python -m mypy . --ignore-missing-imports; then - echo "mypy detected errors" - exit 1 - fi - cd .. - - # Run pytest and generate JUnit XML report + - run: + name: Check if litellm dir was updated or if pyproject.toml was modified - run: name: Run tests command: | pwd ls - python -m pytest -vv litellm/tests/ -x --junitxml=test-results/junit.xml --durations=5 + python -m pytest -vv litellm/tests/test_python_38.py no_output_timeout: 120m - # Store test results - - store_test_results: - path: test-results - build_and_test: machine: image: ubuntu-2204:2023.10.1 diff --git a/litellm/tests/test_python_38.py b/litellm/tests/test_python_38.py new file mode 100644 index 000000000..0712dcaf3 --- /dev/null +++ b/litellm/tests/test_python_38.py @@ -0,0 +1,16 @@ +import sys, os, time +import traceback, asyncio +import pytest + +sys.path.insert( + 0, os.path.abspath("../..") +) # Adds the parent directory to the system path + + +def test_using_litellm(): + try: + import litellm + except Exception as e: + pytest.fail( + f"Error occurred: {e}. Installing litellm on python3.8 failed please retry" + ) From ada6cdab3d0df461bd2675c5487ab587341208e8 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 9 Mar 2024 18:18:18 -0800 Subject: [PATCH 05/11] (fix) testing import litellm on python 3.8 --- .circleci/config.yml | 13 ++++++++----- litellm/tests/test_python_38.py | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8834eea26..4b0ae434f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,11 +13,14 @@ jobs: name: Install Dependencies command: | python -m pip install --upgrade pip - python -m pip install -r .circleci/requirements.txt - pip install openai - pip install prisma - pip install "httpx==0.24.1" - + pip install python-dotenv + pip install pytest + pip install tiktoken + pip install aiohttp + pip install click + pip install jinja2 + pip install tokenizers + pip install openai - run: name: Check if litellm dir was updated or if pyproject.toml was modified - run: diff --git a/litellm/tests/test_python_38.py b/litellm/tests/test_python_38.py index 0712dcaf3..077e65a3a 100644 --- a/litellm/tests/test_python_38.py +++ b/litellm/tests/test_python_38.py @@ -10,6 +10,8 @@ sys.path.insert( def test_using_litellm(): try: import litellm + + print("litellm imported successfully") except Exception as e: pytest.fail( f"Error occurred: {e}. Installing litellm on python3.8 failed please retry" From ce19c2aeef7cc6921a6e5803f6117594347a1832 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 9 Mar 2024 18:23:57 -0800 Subject: [PATCH 06/11] (fix) config.yml --- .circleci/config.yml | 6 ++---- litellm/tests/test_completion.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4b0ae434f..e44394280 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,15 +1,13 @@ version: 2.1 jobs: installing_litellm_on_python: - local_testing: docker: - image: circleci/python:3.8 working_directory: ~/project steps: - checkout - - - run: + - run: name: Install Dependencies command: | python -m pip install --upgrade pip @@ -20,7 +18,7 @@ jobs: pip install click pip install jinja2 pip install tokenizers - pip install openai + pip install openai - run: name: Check if litellm dir was updated or if pyproject.toml was modified - run: diff --git a/litellm/tests/test_completion.py b/litellm/tests/test_completion.py index 729bf7bd9..e54617bd9 100644 --- a/litellm/tests/test_completion.py +++ b/litellm/tests/test_completion.py @@ -69,7 +69,7 @@ def test_completion_claude(): response = completion( model="claude-instant-1", messages=messages, request_timeout=10 ) - # Add any assertions here to check response args + # Add any assertions, here to check response args print(response) print(response.usage) print(response.usage.completion_tokens) From 578d1ef3c6bf6079f5d1e055b23f20d7e0c45b36 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 9 Mar 2024 18:29:44 -0800 Subject: [PATCH 07/11] (fix) ci/cd test --- .circleci/config.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index e44394280..502f3a1b8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -217,6 +217,12 @@ workflows: only: - main - /litellm_.*/ + - installing_litellm_on_python: + filters: + branches: + only: + - main + - /litellm_.*/ - publish_to_pypi: requires: - local_testing From d648cd6c0f9256aa6e9b451b9e76b4dab39c03c5 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 9 Mar 2024 18:37:56 -0800 Subject: [PATCH 08/11] (fix) config.yml --- .circleci/config.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 502f3a1b8..df4fbca78 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,15 +19,12 @@ jobs: pip install jinja2 pip install tokenizers pip install openai - - run: - name: Check if litellm dir was updated or if pyproject.toml was modified - run: name: Run tests command: | pwd ls python -m pytest -vv litellm/tests/test_python_38.py - no_output_timeout: 120m build_and_test: machine: From 4f5222a90235c6d3a9fe58fc8c22b882f7e570e2 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 9 Mar 2024 18:40:47 -0800 Subject: [PATCH 09/11] (fix) ci/cd --- .circleci/config.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index df4fbca78..2790b5539 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -202,12 +202,6 @@ workflows: version: 2 build_and_test: jobs: - - local_testing: - filters: - branches: - only: - - main - - /litellm_.*/ - build_and_test: filters: branches: @@ -222,7 +216,6 @@ workflows: - /litellm_.*/ - publish_to_pypi: requires: - - local_testing - build_and_test filters: branches: From d3b29b63fe6102c545bd2c7db3ae2aaab0e77ba0 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 9 Mar 2024 18:44:06 -0800 Subject: [PATCH 10/11] (fix) ci/cd local testing --- .circleci/config.yml | 95 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2790b5539..38b844256 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,94 @@ version: 2.1 jobs: + local_testing: + docker: + - image: circleci/python:3.9 + working_directory: ~/project + + steps: + - checkout + + - run: + name: Check if litellm dir was updated or if pyproject.toml was modified + command: | + if [ -n "$(git diff --name-only $CIRCLE_SHA1^..$CIRCLE_SHA1 | grep -E 'pyproject\.toml|litellm/')" ]; then + echo "litellm updated" + else + echo "No changes to litellm or pyproject.toml. Skipping tests." + circleci step halt + fi + - restore_cache: + keys: + - v1-dependencies-{{ checksum ".circleci/requirements.txt" }} + - run: + name: Install Dependencies + command: | + python -m pip install --upgrade pip + python -m pip install -r .circleci/requirements.txt + pip install "pytest==7.3.1" + pip install "pytest-asyncio==0.21.1" + pip install mypy + pip install "google-generativeai>=0.3.2" + pip install "google-cloud-aiplatform>=1.38.0" + pip install "boto3>=1.28.57" + pip install "aioboto3>=12.3.0" + pip install langchain + pip install "langfuse>=2.0.0" + pip install numpydoc + pip install traceloop-sdk==0.0.69 + pip install openai + pip install prisma + pip install "httpx==0.24.1" + pip install "gunicorn==21.2.0" + pip install "anyio==3.7.1" + pip install "aiodynamo==23.10.1" + pip install "asyncio==3.4.3" + pip install "apscheduler==3.10.4" + pip install "PyGithub==1.59.1" + pip install python-multipart + - save_cache: + paths: + - ./venv + key: v1-dependencies-{{ checksum ".circleci/requirements.txt" }} + - run: + name: Run prisma ./entrypoint.sh + command: | + set +e + chmod +x entrypoint.sh + ./entrypoint.sh + set -e + - run: + name: Black Formatting + command: | + cd litellm + python -m pip install black + python -m black . + cd .. + - run: + name: Linting Testing + command: | + cd litellm + python -m pip install types-requests types-setuptools types-redis + if ! python -m mypy . --ignore-missing-imports; then + echo "mypy detected errors" + exit 1 + fi + cd .. + + + # Run pytest and generate JUnit XML report + - run: + name: Run tests + command: | + pwd + ls + python -m pytest -vv litellm/tests/ -x --junitxml=test-results/junit.xml --durations=5 + no_output_timeout: 120m + + # Store test results + - store_test_results: + path: test-results + installing_litellm_on_python: docker: - image: circleci/python:3.8 @@ -202,6 +291,12 @@ workflows: version: 2 build_and_test: jobs: + - local_testing: + filters: + branches: + only: + - main + - /litellm_.*/ - build_and_test: filters: branches: From c51d25b063ba6dc242926c0b1007e575f730e4ba Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 9 Mar 2024 18:45:27 -0800 Subject: [PATCH 11/11] (ci/cd) test --- .circleci/config.yml | 1 + litellm/tests/test_completion.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 38b844256..bbce7ce6d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -311,6 +311,7 @@ workflows: - /litellm_.*/ - publish_to_pypi: requires: + - local_testing - build_and_test filters: branches: diff --git a/litellm/tests/test_completion.py b/litellm/tests/test_completion.py index e54617bd9..729bf7bd9 100644 --- a/litellm/tests/test_completion.py +++ b/litellm/tests/test_completion.py @@ -69,7 +69,7 @@ def test_completion_claude(): response = completion( model="claude-instant-1", messages=messages, request_timeout=10 ) - # Add any assertions, here to check response args + # Add any assertions here to check response args print(response) print(response.usage) print(response.usage.completion_tokens)