Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: added typechecking #1537

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Typecheck

# If a pull-request is pushed then cancel all previously running jobs related
# to that pull-request
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

on:
push:
branches:
- main
pull_request:
branches:
- main
- master

env:
PY_COLORS: 1

jobs:
typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: Install poetry
run: pipx install poetry
- uses: actions/[email protected]
with:
python-version: '3.12'
- run: poetry install
- name: Run mypy
# for some strange reason, the config specified in pyproject.toml is not respected
run: poetry run mypy . --ignore-missing-imports
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# use the auto eval Factuality() evaluator

print("calling evaluator")
evaluator = Factuality()
evaluator = Factuality() # type: ignore
result = evaluator(
output=response.choices[0]["message"][
"content"
Expand Down
13 changes: 7 additions & 6 deletions cookbook/litellm-ollama-docker-image/test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import openai
from litellm import completion

api_base = f"http://0.0.0.0:8000"
api_base = "http://0.0.0.0:8000"

openai.api_base = api_base
openai.base_url = api_base
openai.api_key = "temp-key"
print(openai.api_base)
print(openai.base_url)


print(f"LiteLLM: response from proxy with streaming")
response = openai.ChatCompletion.create(
print("LiteLLM: response from proxy with streaming")
response = completion(
model="ollama/llama2",
messages=[
{
Expand All @@ -22,7 +23,7 @@
for chunk in response:
print(f"LiteLLM: streaming response from proxy {chunk}")

response = openai.ChatCompletion.create(
response = completion(
model="ollama/llama2",
messages=[
{
Expand Down
Empty file added litellm/py.typed
Empty file.
260 changes: 257 additions & 3 deletions poetry.lock

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ description = "Library to easily interface with LLM API providers"
authors = ["BerriAI"]
license = "MIT"
readme = "README.md"
packages = [
{ include = "litellm" }
]

[tool.poetry.dependencies]
python = ">=3.8.1,<3.9.7 || >3.9.7"
Expand Down Expand Up @@ -55,6 +58,14 @@ litellm = 'litellm:run_server'
flake8 = "^6.1.0"
black = "^23.12.0"
pytest = "^7.4.3"
mypy = "^1.8.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @ErikBjare @jamesbraza is it necessary to add mypy and types in our core dependencies?

for context i'm looking at openai's dependencies and i don't see this there - https://github.com/openai/openai-python/blob/54a5911f5215148a0bdeb10e2bcfb84f635a75b9/pyproject.toml#L10

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So these are not the core deps, they're dev (developer) deps. Also, #4136 added mypy to the dev group already, so if this PR were rebased atop main this particular line would go away.

However, the below type stubs added need to stay in dev group dependencies.

Tho I don't think the type stubs should be so specifically pinned, it's okay with something like >= instead of ^


types-requests = "^2.31.0.20240106"
types-redis = "^4.6.0.20240106"
types-tabulate = "^0.9.0.20240106"
types-waitress = "^2.1.4.20240106"
types-pyyaml = "^6.0.12.12"
types-setuptools = "^69.0.0.20240115"

[build-system]
requires = ["poetry-core", "wheel"]
Expand All @@ -66,3 +77,5 @@ version_files = [
"pyproject.toml:^version"
]

[tool.mypy]
ignore_missing_imports = true
9 changes: 4 additions & 5 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# What this tests ?
## Tests /models and /model/* endpoints

import pytest
import asyncio
import aiohttp
import pytest


async def generate_key(session, models=[]):
Expand Down Expand Up @@ -55,7 +54,7 @@ async def test_get_models():
async def add_models(session, model_id="123"):
url = "http://0.0.0.0:4000/model/new"
headers = {
"Authorization": f"Bearer sk-1234",
"Authorization": "Bearer sk-1234",
"Content-Type": "application/json",
}

Expand Down Expand Up @@ -141,7 +140,7 @@ async def test_add_models():


@pytest.mark.asyncio
async def test_get_models():
async def test_get_models_2():
"""
Get models user has access to
"""
Expand All @@ -160,7 +159,7 @@ async def delete_model(session, model_id="123"):
"""
url = "http://0.0.0.0:4000/model/delete"
headers = {
"Authorization": f"Bearer sk-1234",
"Authorization": "Bearer sk-1234",
"Content-Type": "application/json",
}
data = {"id": model_id}
Expand Down