Skip to content
Merged
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
Binary file modified docs/config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/config.puml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class "Configuration" as src.models.config.Configuration {
authentication : Optional[AuthenticationConfiguration]
authorization : Optional[AuthorizationConfiguration]
byok_rag : Optional[list[ByokRag]]
conversation_cache : Optional[ConversationCacheConfiguration]
conversation_cache : Optional[ConversationHistoryConfiguration]
customization : Optional[Customization]
database : Optional[DatabaseConfiguration]
inference : Optional[InferenceConfiguration]
Expand All @@ -53,7 +53,7 @@ class "Configuration" as src.models.config.Configuration {
class "ConfigurationBase" as src.models.config.ConfigurationBase {
model_config
}
class "ConversationCacheConfiguration" as src.models.config.ConversationCacheConfiguration {
class "ConversationHistoryConfiguration" as src.models.config.ConversationHistoryConfiguration {
memory : Optional[InMemoryCacheConfig]
postgres : Optional[PostgreSQLDatabaseConfiguration]
sqlite : Optional[SQLiteDatabaseConfiguration]
Expand Down Expand Up @@ -185,7 +185,7 @@ src.models.config.AuthorizationConfiguration --|> src.models.config.Configuratio
src.models.config.ByokRag --|> src.models.config.ConfigurationBase
src.models.config.CORSConfiguration --|> src.models.config.ConfigurationBase
src.models.config.Configuration --|> src.models.config.ConfigurationBase
src.models.config.ConversationCacheConfiguration --|> src.models.config.ConfigurationBase
src.models.config.ConversationHistoryConfiguration --|> src.models.config.ConfigurationBase
src.models.config.Customization --|> src.models.config.ConfigurationBase
src.models.config.DatabaseConfiguration --|> src.models.config.ConfigurationBase
src.models.config.InMemoryCacheConfig --|> src.models.config.ConfigurationBase
Expand Down
556 changes: 278 additions & 278 deletions docs/config.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 56 additions & 56 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@
"$ref": "#/components/schemas/InferenceConfiguration"
},
"conversation_cache": {
"$ref": "#/components/schemas/ConversationCacheConfiguration"
"$ref": "#/components/schemas/ConversationHistoryConfiguration"
},
"byok_rag": {
"items": {
Expand All @@ -1948,61 +1948,6 @@
"title": "Configuration",
"description": "Global service configuration."
},
"ConversationCacheConfiguration": {
"properties": {
"type": {
"anyOf": [
{
"type": "string",
"enum": [
"noop",
"memory",
"sqlite",
"postgres"
]
},
{
"type": "null"
}
],
"title": "Type"
},
"memory": {
"anyOf": [
{
"$ref": "#/components/schemas/InMemoryCacheConfig"
},
{
"type": "null"
}
]
},
"sqlite": {
"anyOf": [
{
"$ref": "#/components/schemas/SQLiteDatabaseConfiguration"
},
{
"type": "null"
}
]
},
"postgres": {
"anyOf": [
{
"$ref": "#/components/schemas/PostgreSQLDatabaseConfiguration"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false,
"type": "object",
"title": "ConversationCacheConfiguration",
"description": "Conversation cache configuration."
},
"ConversationData": {
"properties": {
"conversation_id": {
Expand Down Expand Up @@ -2175,6 +2120,61 @@
"title": "ConversationDetails",
"description": "Model representing the details of a user conversation.\n\nAttributes:\n conversation_id: The conversation ID (UUID).\n created_at: When the conversation was created.\n last_message_at: When the last message was sent.\n message_count: Number of user messages in the conversation.\n last_used_model: The last model used for the conversation.\n last_used_provider: The provider of the last used model.\n topic_summary: The topic summary for the conversation.\n\nExample:\n ```python\n conversation = ConversationDetails(\n conversation_id=\"123e4567-e89b-12d3-a456-426614174000\"\n created_at=\"2024-01-01T00:00:00Z\",\n last_message_at=\"2024-01-01T00:05:00Z\",\n message_count=5,\n last_used_model=\"gemini/gemini-2.0-flash\",\n last_used_provider=\"gemini\",\n topic_summary=\"Openshift Microservices Deployment Strategies\",\n )\n ```"
},
"ConversationHistoryConfiguration": {
"properties": {
"type": {
"anyOf": [
{
"type": "string",
"enum": [
"noop",
"memory",
"sqlite",
"postgres"
]
},
{
"type": "null"
}
],
"title": "Type"
},
"memory": {
"anyOf": [
{
"$ref": "#/components/schemas/InMemoryCacheConfig"
},
{
"type": "null"
}
]
},
"sqlite": {
"anyOf": [
{
"$ref": "#/components/schemas/SQLiteDatabaseConfiguration"
},
{
"type": "null"
}
]
},
"postgres": {
"anyOf": [
{
"$ref": "#/components/schemas/PostgreSQLDatabaseConfiguration"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false,
"type": "object",
"title": "ConversationHistoryConfiguration",
"description": "Conversation cache configuration."
},
"ConversationResponse": {
"properties": {
"conversation_id": {
Expand Down
4 changes: 2 additions & 2 deletions src/cache/cache_factory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Cache factory class."""

import constants
from models.config import ConversationCacheConfiguration
from models.config import ConversationHistoryConfiguration
from cache.cache import Cache
from cache.noop_cache import NoopCache
from cache.in_memory_cache import InMemoryCache
Expand All @@ -17,7 +17,7 @@ class CacheFactory:
"""Cache factory class."""

@staticmethod
def conversation_cache(config: ConversationCacheConfiguration) -> Cache:
def conversation_cache(config: ConversationHistoryConfiguration) -> Cache:
"""Create an instance of Cache based on loaded configuration.

Returns:
Expand Down
4 changes: 2 additions & 2 deletions src/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
AuthenticationConfiguration,
InferenceConfiguration,
DatabaseConfiguration,
ConversationCacheConfiguration,
ConversationHistoryConfiguration,
QuotaHandlersConfiguration,
)

Expand Down Expand Up @@ -138,7 +138,7 @@ def inference(self) -> InferenceConfiguration:
return self._configuration.inference

@property
def conversation_cache_configuration(self) -> ConversationCacheConfiguration:
def conversation_cache_configuration(self) -> ConversationHistoryConfiguration:
"""Return conversation cache configuration."""
if self._configuration is None:
raise LogicError("logic error: configuration is not loaded")
Expand Down
6 changes: 3 additions & 3 deletions src/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def check_default_model_and_provider(self) -> Self:
return self


class ConversationCacheConfiguration(ConfigurationBase):
class ConversationHistoryConfiguration(ConfigurationBase):
"""Conversation cache configuration."""

type: Literal["noop", "memory", "sqlite", "postgres"] | None = None
Expand Down Expand Up @@ -608,8 +608,8 @@ class Configuration(ConfigurationBase):
authorization: Optional[AuthorizationConfiguration] = None
customization: Optional[Customization] = None
inference: InferenceConfiguration = Field(default_factory=InferenceConfiguration)
conversation_cache: ConversationCacheConfiguration = Field(
default_factory=ConversationCacheConfiguration
conversation_cache: ConversationHistoryConfiguration = Field(
default_factory=ConversationHistoryConfiguration
)
byok_rag: list[ByokRag] = Field(default_factory=list)
quota_handlers: QuotaHandlersConfiguration = Field(
Expand Down
45 changes: 23 additions & 22 deletions tests/unit/cache/test_cache_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)

from models.config import (
ConversationCacheConfiguration,
ConversationHistoryConfiguration,
InMemoryCacheConfig,
SQLiteDatabaseConfiguration,
PostgreSQLDatabaseConfiguration,
Expand All @@ -28,23 +28,23 @@


@pytest.fixture(scope="module", name="noop_cache_config_fixture")
def noop_cache_config() -> ConversationCacheConfiguration:
"""Fixture containing initialized instance of ConversationCacheConfiguration."""
return ConversationCacheConfiguration(type=CACHE_TYPE_NOOP)
def noop_cache_config() -> ConversationHistoryConfiguration:
"""Fixture containing initialized instance of ConversationHistoryConfiguration."""
return ConversationHistoryConfiguration(type=CACHE_TYPE_NOOP)


@pytest.fixture(scope="module", name="memory_cache_config_fixture")
def memory_cache_config() -> ConversationCacheConfiguration:
def memory_cache_config() -> ConversationHistoryConfiguration:
"""Fixture containing initialized instance of InMemory cache."""
return ConversationCacheConfiguration(
return ConversationHistoryConfiguration(
type=CACHE_TYPE_MEMORY, memory=InMemoryCacheConfig(max_entries=10)
)


@pytest.fixture(scope="module", name="postgres_cache_config_fixture")
def postgres_cache_config() -> ConversationCacheConfiguration:
def postgres_cache_config() -> ConversationHistoryConfiguration:
"""Fixture containing initialized instance of PostgreSQL cache."""
return ConversationCacheConfiguration(
return ConversationHistoryConfiguration(
type=CACHE_TYPE_POSTGRES,
postgres=PostgreSQLDatabaseConfiguration(
db="database", user="user", password=SecretStr("password")
Expand All @@ -53,25 +53,25 @@ def postgres_cache_config() -> ConversationCacheConfiguration:


@pytest.fixture(name="sqlite_cache_config_fixture")
def sqlite_cache_config(tmpdir: Path) -> ConversationCacheConfiguration:
def sqlite_cache_config(tmpdir: Path) -> ConversationHistoryConfiguration:
"""Fixture containing initialized instance of SQLite cache."""
db_path = str(tmpdir / "test.sqlite")
return ConversationCacheConfiguration(
return ConversationHistoryConfiguration(
type=CACHE_TYPE_SQLITE, sqlite=SQLiteDatabaseConfiguration(db_path=db_path)
)


@pytest.fixture(scope="module", name="invalid_cache_type_config_fixture")
def invalid_cache_type_config() -> ConversationCacheConfiguration:
"""Fixture containing instance of ConversationCacheConfiguration with improper settings."""
c = ConversationCacheConfiguration()
def invalid_cache_type_config() -> ConversationHistoryConfiguration:
"""Fixture containing instance of ConversationHistoryConfiguration with improper settings."""
c = ConversationHistoryConfiguration()
# the conversation cache type name is incorrect in purpose
c.type = "foo bar baz" # pyright: ignore
return c


def test_conversation_cache_noop(
noop_cache_config_fixture: ConversationCacheConfiguration,
noop_cache_config_fixture: ConversationHistoryConfiguration,
) -> None:
"""Check if NoopCache is returned by factory with proper configuration."""
cache = CacheFactory.conversation_cache(noop_cache_config_fixture)
Expand All @@ -81,7 +81,7 @@ def test_conversation_cache_noop(


def test_conversation_cache_in_memory(
memory_cache_config_fixture: ConversationCacheConfiguration,
memory_cache_config_fixture: ConversationHistoryConfiguration,
) -> None:
"""Check if InMemoryCache is returned by factory with proper configuration."""
cache = CacheFactory.conversation_cache(memory_cache_config_fixture)
Expand All @@ -92,7 +92,7 @@ def test_conversation_cache_in_memory(

def test_conversation_cache_in_memory_improper_config() -> None:
"""Check if memory cache configuration is checked in cache factory."""
cc = ConversationCacheConfiguration(
cc = ConversationHistoryConfiguration(
type=CACHE_TYPE_MEMORY, memory=InMemoryCacheConfig(max_entries=10)
)
# simulate improper configuration (can not be done directly as model checks this)
Expand All @@ -102,7 +102,7 @@ def test_conversation_cache_in_memory_improper_config() -> None:


def test_conversation_cache_sqlite(
sqlite_cache_config_fixture: ConversationCacheConfiguration,
sqlite_cache_config_fixture: ConversationHistoryConfiguration,
) -> None:
"""Check if SQLiteCache is returned by factory with proper configuration."""
cache = CacheFactory.conversation_cache(sqlite_cache_config_fixture)
Expand All @@ -114,7 +114,7 @@ def test_conversation_cache_sqlite(
def test_conversation_cache_sqlite_improper_config(tmpdir: Path) -> None:
"""Check if memory cache configuration is checked in cache factory."""
db_path = str(tmpdir / "test.sqlite")
cc = ConversationCacheConfiguration(
cc = ConversationHistoryConfiguration(
type=CACHE_TYPE_SQLITE, sqlite=SQLiteDatabaseConfiguration(db_path=db_path)
)
# simulate improper configuration (can not be done directly as model checks this)
Expand All @@ -124,7 +124,8 @@ def test_conversation_cache_sqlite_improper_config(tmpdir: Path) -> None:


def test_conversation_cache_postgres(
postgres_cache_config_fixture: ConversationCacheConfiguration, mocker: MockerFixture
postgres_cache_config_fixture: ConversationHistoryConfiguration,
mocker: MockerFixture,
) -> None:
"""Check if PostgreSQL is returned by factory with proper configuration."""
mocker.patch("psycopg2.connect")
Expand All @@ -136,7 +137,7 @@ def test_conversation_cache_postgres(

def test_conversation_cache_postgres_improper_config() -> None:
"""Check if PostgreSQL cache configuration is checked in cache factory."""
cc = ConversationCacheConfiguration(
cc = ConversationHistoryConfiguration(
type=CACHE_TYPE_POSTGRES,
postgres=PostgreSQLDatabaseConfiguration(
db="db", user="u", password=SecretStr("p")
Expand All @@ -152,15 +153,15 @@ def test_conversation_cache_postgres_improper_config() -> None:

def test_conversation_cache_no_type() -> None:
"""Check if wrong cache configuration is detected properly."""
cc = ConversationCacheConfiguration(type=CACHE_TYPE_NOOP)
cc = ConversationHistoryConfiguration(type=CACHE_TYPE_NOOP)
# simulate improper configuration (can not be done directly as model checks this)
cc.type = None
with pytest.raises(ValueError, match="Cache type must be set"):
CacheFactory.conversation_cache(cc)


def test_conversation_cache_wrong_cache(
invalid_cache_type_config_fixture: ConversationCacheConfiguration,
invalid_cache_type_config_fixture: ConversationHistoryConfiguration,
) -> None:
"""Check if wrong cache configuration is detected properly."""
with pytest.raises(ValueError, match="Invalid cache type"):
Expand Down
Loading
Loading