Skip to content

Commit

Permalink
organize import
Browse files Browse the repository at this point in the history
Signed-off-by: Stephanie <[email protected]>
  • Loading branch information
yangcao77 committed Jan 23, 2025
1 parent 0568e76 commit 97ded98
Show file tree
Hide file tree
Showing 21 changed files with 31 additions and 61 deletions.
4 changes: 2 additions & 2 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@
"type": "human"
},
{
"content": " OpenShift is a container orchestration platform built by Red Hat...",
"content": "OpenShift is a container orchestration platform ...",
"type": "ai"
}
]
Expand All @@ -630,7 +630,7 @@
"type": "object"
},
"ConversationDeletionResponse": {
"description": "Model representing a response to a conversation deletion request.\n\n Attributes:\n response: The response of the conversation deletion request.\n\n Example:\n ```python\n conversation_deletion_response = ConversationDeletionResponse(response='conversation deleted')\n ```",
"description": "Model representing a response to a conversation deletion request.\n\n Attributes:\n response: The response of the conversation deletion request.\n\n Example:\n ```python\n response = ConversationDeletionResponse(response='conversation deleted')\n ```",
"examples": [
{
"response": "conversation deleted"
Expand Down
4 changes: 2 additions & 2 deletions ols/app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class ChatHistoryResponse(BaseModel):
"type": "human",
},
{
"content": " OpenShift is a container orchestration platform built by Red Hat...",
"content": "OpenShift is a container orchestration platform ...",
"type": "ai",
},
]
Expand Down Expand Up @@ -274,7 +274,7 @@ class ConversationDeletionResponse(BaseModel):
Example:
```python
conversation_deletion_response = ConversationDeletionResponse(response="conversation deleted")
response = ConversationDeletionResponse(response="conversation deleted")
```
"""

Expand Down
10 changes: 5 additions & 5 deletions ols/src/cache/postgres_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from ols.src.cache.cache import Cache
from ols.src.cache.cache_error import CacheError


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -78,14 +77,14 @@ class PostgresCache(Cache):
"""

DELETE_SINGLE_CONVERSATION_STATEMENT = """
DELETE FROM cache
DELETE FROM cache
WHERE user_id=%s AND conversation_id=%s
"""

LIST_CONVERSATIONS_STATEMENT = """
SELECT conversation_id
FROM cache
WHERE user_id=%s
SELECT conversation_id
FROM cache
WHERE user_id=%s
ORDER BY updated_at DESC
"""

Expand Down Expand Up @@ -209,6 +208,7 @@ def list(self, user_id: str, skip_user_id_check: bool = False) -> list[str]:
Args:
user_id: User identification.
skip_user_id_check: Skip user_id suid check.
Returns:
A list of conversation ids from the cache
Expand Down
9 changes: 2 additions & 7 deletions ols/src/cache/redis_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@

import redis
from redis.backoff import ExponentialBackoff
from redis.exceptions import (
BusyLoadingError,
RedisError,
)
from redis.exceptions import (
ConnectionError as RedisConnectionError,
)
from redis.exceptions import BusyLoadingError, RedisError
from redis.exceptions import ConnectionError as RedisConnectionError
from redis.retry import Retry

from ols.app.models.config import RedisConfig
Expand Down
4 changes: 1 addition & 3 deletions ols/src/llms/providers/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
from typing import Any, Optional

import httpx
from ibm_watsonx_ai.metanames import (
GenTextParamsMetaNames as GenParams,
)
from ibm_watsonx_ai.metanames import GenTextParamsMetaNames as GenParams
from langchain.llms.base import LLM

from ols import config
Expand Down
4 changes: 1 addition & 3 deletions ols/src/llms/providers/watsonx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import logging
from typing import Any, Optional

from ibm_watsonx_ai.metanames import (
GenTextParamsMetaNames as GenParams,
)
from ibm_watsonx_ai.metanames import GenTextParamsMetaNames as GenParams
from langchain.llms.base import LLM
from langchain_ibm.llms import WatsonxLLM

Expand Down
3 changes: 2 additions & 1 deletion ols/src/prompts/prompt_generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Prompt generator based on model / context."""

from copy import copy
from langchain_core.messages import HumanMessage, BaseMessage

from langchain_core.messages import BaseMessage, HumanMessage
from langchain_core.prompts import (
ChatPromptTemplate,
HumanMessagePromptTemplate,
Expand Down
3 changes: 1 addition & 2 deletions ols/src/query_helpers/docs_summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from typing import Any, AsyncGenerator, Optional

from langchain.chains import LLMChain
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.messages import AIMessage, BaseMessage
from langchain_core.prompts import ChatPromptTemplate
from llama_index.core import VectorStoreIndex

from ols import config
Expand All @@ -21,7 +21,6 @@
from ols.src.query_helpers.query_helper import QueryHelper
from ols.utils.token_handler import TokenHandler


logger = logging.getLogger(__name__)


Expand Down
5 changes: 1 addition & 4 deletions ols/utils/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
from typing import Optional
from urllib.parse import urlparse

from pydantic import (
AnyHttpUrl,
FilePath,
)
from pydantic import AnyHttpUrl, FilePath


class InvalidConfigurationError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion ols/utils/token_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import logging
from math import ceil

from langchain_core.messages import BaseMessage
from llama_index.core.schema import NodeWithScore
from tiktoken import get_encoding
from langchain_core.messages import BaseMessage

from ols.app.models.models import RagChunk
from ols.constants import (
Expand Down
1 change: 0 additions & 1 deletion tests/integration/test_conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def _setup():
@pytest.mark.parametrize("endpoint", ("/conversations/{conversation_id}",))
def test_get_conversation_with_history(_setup, endpoint):
"""Test getting conversation history after creating some chat history."""

ml = mock_langchain_interface("test response")
with (
patch(
Expand Down
6 changes: 1 addition & 5 deletions tests/integration/test_ols.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
from langchain_core.messages import AIMessage, HumanMessage

from ols import config, constants
from ols.app.models.config import (
LoggingConfig,
ProviderConfig,
QueryFilter,
)
from ols.app.models.config import LoggingConfig, ProviderConfig, QueryFilter
from ols.customize import prompts
from ols.utils import suid
from ols.utils.errors_parsing import DEFAULT_ERROR_MESSAGE, DEFAULT_STATUS_CODE
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/app/endpoints/test_authorized.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
# needs to be setup there before is_user_authorized is imported
config.ols_config.authentication_config.module = "k8s"

from ols.app.endpoints.authorized import ( # noqa:E402
is_user_authorized,
)
from ols.app.endpoints.authorized import is_user_authorized # noqa:E402
from ols.app.models.models import AuthorizationResponse # noqa:E402
from tests.mock_classes.mock_k8s_api import ( # noqa:E402
mock_subject_access_review_response,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/auth/test_k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def test_auth_dependency_valid_token(mock_authz_api, mock_authn_api):
# Check if the correct user info has been returned
assert user_uid == "valid-uid"
assert username == "valid-user"
assert skip_user_id_check == False
assert skip_user_id_check is False


@pytest.mark.usefixtures("_setup")
Expand Down Expand Up @@ -126,7 +126,7 @@ async def test_cluster_id_is_used_for_kube_admin(mock_authz_api):
# check if the correct user info has been returned
assert user_uid == "some-cluster-id"
assert username == "kube:admin"
assert skip_user_id_check == False
assert skip_user_id_check is False


@pytest.mark.usefixtures("_setup")
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/auth/test_noop_auth_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def test_noop_auth_dependency_call():
# Check if the correct user info has been returned
assert user_uid == DEFAULT_USER_UID
assert username == DEFAULT_USER_NAME
assert skip_user_id_check == True
assert skip_user_id_check is True


@pytest.mark.asyncio
Expand All @@ -44,7 +44,7 @@ async def test_noop_auth_dependency_call_disable_auth():
# Check if the correct user info has been returned
assert user_uid == DEFAULT_USER_UID
assert username == DEFAULT_USER_NAME
assert skip_user_id_check == True
assert skip_user_id_check is True


@pytest.mark.asyncio
Expand All @@ -66,4 +66,4 @@ async def test_noop_auth_dependency_call_with_user_id():
# Check if the correct user info has been returned
assert user_uid == user_id_in_request
assert username == DEFAULT_USER_NAME
assert skip_user_id_check == True
assert skip_user_id_check is True
2 changes: 1 addition & 1 deletion tests/unit/cache/test_redis_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ols import constants
from ols.app.models.config import RedisConfig
from ols.app.models.models import CacheEntry, MessageDecoder, MessageEncoder
from ols.app.models.models import CacheEntry
from ols.src.cache.redis_cache import RedisCache
from ols.utils import suid
from tests.mock_classes.mock_redis_client import MockRedisClient
Expand Down
5 changes: 1 addition & 4 deletions tests/unit/llms/providers/test_azure_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
from langchain_openai import AzureChatOpenAI

from ols.app.models.config import ProviderConfig
from ols.src.llms.providers.azure_openai import (
AzureOpenAI,
token_is_expired,
)
from ols.src.llms.providers.azure_openai import AzureOpenAI, token_is_expired


@pytest.fixture
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/llms/providers/test_watsonx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from unittest.mock import patch

import pytest
from ibm_watsonx_ai.metanames import (
GenTextParamsMetaNames as GenParams,
)
from ibm_watsonx_ai.metanames import GenTextParamsMetaNames as GenParams

from ols.app.models.config import ProviderConfig
from ols.constants import GenericLLMParameters
Expand Down
6 changes: 1 addition & 5 deletions tests/unit/prompts/test_prompt_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
)
from langchain_core.messages import AIMessage, HumanMessage

from ols.constants import (
GPT35_TURBO,
GRANITE_13B_CHAT_V2,
ModelFamily,
)
from ols.constants import GPT35_TURBO, GRANITE_13B_CHAT_V2, ModelFamily
from ols.src.prompts.prompt_generator import (
GeneratePrompt,
restructure_history,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/query_helpers/test_docs_summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_prepare_prompt_context():
"""Basic test for DocsSummarizer to check re-structuring of context for the 'temp' prompt."""
summarizer = DocsSummarizer(llm_loader=mock_llm_loader(None))
question = "What's the ultimate question with answer 42?"
history = ["human: What is Kubernetes?"]
history = [HumanMessage("What is Kubernetes?")]
rag_index = MockLlamaIndex()

with patch(
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/utils/test_pyroscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import pytest
from requests.exceptions import RequestException

from ols.utils.pyroscope import (
start_with_pyroscope_enabled,
)
from ols.utils.pyroscope import start_with_pyroscope_enabled


@pytest.fixture
Expand Down

0 comments on commit 97ded98

Please sign in to comment.