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

feat: enabled type checking of examples #166

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ publish: build
poetry publish -u __token__ -p ${PYPI_TOKEN} --skip-existing

lint: install
poetry run nox -s lint
poetry run nox -s lint_sdk
poetry run nox -s lint_examples

format: install
poetry run nox -s format
Expand Down
12 changes: 7 additions & 5 deletions examples/langchain_rag/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
from langchain.storage import LocalFileStore
from langchain_community.document_loaders import PyPDFLoader, WebBaseLoader
from langchain_community.vectorstores import Chroma
from langchain_core.pydantic_v1 import SecretStr
from langchain_openai import AzureChatOpenAI, AzureOpenAIEmbeddings
from langchain_text_splitters import RecursiveCharacterTextSplitter
from utils import get_last_attachment_url, sanitize_namespace

from aidial_sdk import DIALApp
from aidial_sdk import HTTPException as DIALException
from aidial_sdk.chat_completion import ChatCompletion, Choice, Request, Response

from .utils import get_last_attachment_url, sanitize_namespace


def get_env(name: str) -> str:
value = os.getenv(name)
Expand Down Expand Up @@ -97,8 +99,8 @@ async def chat_completion(
azure_deployment=EMBEDDINGS_MODEL,
azure_endpoint=DIAL_URL,
# Header propagation automatically propagates the API key from the request headers.
openai_api_key="-",
openai_api_version=API_VERSION,
api_key=SecretStr("-"),
api_version=API_VERSION,
# The check leads to tokenization of the input strings.
# Tokenized input is only supported by OpenAI embedding models.
# For other models, the check should be disabled.
Expand All @@ -120,8 +122,8 @@ async def chat_completion(
azure_deployment=CHAT_MODEL,
azure_endpoint=DIAL_URL,
# Header propagation automatically propagates the API key from the request headers.
openai_api_key="-",
openai_api_version=API_VERSION,
api_key=SecretStr("-"),
api_version=API_VERSION,
temperature=0,
streaming=True,
callbacks=[CustomCallbackHandler(choice)],
Expand Down
34 changes: 33 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
from pathlib import Path

import nox

nox.options.reuse_existing_virtualenvs = True
Expand All @@ -12,7 +15,7 @@ def format_with_args(session: nox.Session, *args):


@nox.session
def lint(session: nox.Session):
def lint_sdk(session: nox.Session):
"""Runs linters and fixers"""
try:
session.run("poetry", "install", "--all-extras", external=True)
Expand All @@ -26,6 +29,35 @@ def lint(session: nox.Session):
)


EXAMPLES = [
folder for folder in os.listdir("examples") if not folder.startswith("_")
]


@nox.session
@nox.parametrize("example_dir", EXAMPLES)
def lint_examples(session: nox.Session, example_dir: str):
try:
root = str(Path(__file__).parent)
project_dir = f"{root}/examples/{example_dir}"

session.run("poetry", "install", "--with=lint", external=True)
session.run("poetry", "check", "--lock", external=True)

session.run(
"pip", "install", "-r", f"{project_dir}/requirements.txt", "-q"
)

session.chdir(project_dir)
session.run("pyright", SRC)
session.run("flake8", SRC)
format_with_args(session, SRC, "--check")
except Exception:
session.error(
"linting has failed. Run 'make format' to fix formatting and fix other errors manually"
)


@nox.session
def format(session: nox.Session):
"""Runs linters and fixers"""
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ exclude = [
".pytest_cache",
"**/__pycache__",
"build",
"examples/langchain_rag"
]

[tool.black]
Expand Down
Loading