Skip to content

Commit

Permalink
fix type check
Browse files Browse the repository at this point in the history
Signed-off-by: Stephanie <yangcao@redhat.com>
  • Loading branch information
yangcao77 committed Jan 22, 2025
1 parent 837b7fe commit c147719
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions ols/app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import json
from collections import OrderedDict
from typing import Optional, Self
from typing import Any, Dict, Optional, Self, Union

from langchain.llms.base import LLM
from pydantic import BaseModel, field_validator, model_validator
Expand Down Expand Up @@ -713,7 +713,7 @@ def cache_entries_to_history(
class MessageEncoder(json.JSONEncoder):
"""Convert Message objects to serializable dictionaries."""

def default(self, o):
def default(self, o: Any) -> Union[dict, Any]:
"""Convert a Message object into a serializable dictionary.
This method is called when an object cannot be serialized by default
Expand Down Expand Up @@ -756,11 +756,13 @@ class MessageDecoder(json.JSONDecoder):
HumanMessage(content="Hello", ...)
"""

def __init__(self, *args, **kwargs):
def __init__(self, *args: Any, **kwargs: Any):
"""Initialize the MessageDecoder with custom object hook."""
super().__init__(object_hook=self._decode_message, *args, **kwargs)

def _decode_message(self, dct):
def _decode_message(
self, dct: Dict[str, Any]
) -> Union[HumanMessage, AIMessage, Dict[str, Any]]:
"""Decode JSON dictionary into Message objects if applicable.
Args:
Expand Down
2 changes: 1 addition & 1 deletion ols/src/auth/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def __init__(self, virtual_path: str = "/ols-access") -> None:
"""Initialize the required allowed paths for authorization checks."""
self.virtual_path = virtual_path

async def __call__(self, request: Request) -> tuple[str, str]:
async def __call__(self, request: Request) -> tuple[str, str, bool]:
"""Validate FastAPI Requests for authentication and authorization.
Validates the bearer token from the request,
Expand Down
2 changes: 1 addition & 1 deletion ols/src/auth/noop.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, virtual_path: str = "/ols-access") -> None:
# skip user_id suid check if noop auth to allow consumers provide user_id
self.skip_userid_check = True

async def __call__(self, request: Request) -> tuple[str, str]:
async def __call__(self, request: Request) -> tuple[str, str, bool]:
"""Validate FastAPI Requests for authentication and authorization.
Args:
Expand Down
2 changes: 1 addition & 1 deletion ols/src/query_helpers/docs_summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _prepare_prompt(
"""
# if history is not provided, initialize to empty history
if history is None:
history: list[BaseMessage] = []
history = []

settings_string = (
f"query: {query}, "
Expand Down

0 comments on commit c147719

Please sign in to comment.