Skip to content

Commit 13a2960

Browse files
authored
Merge branch 'main' into auto_instrument_1
2 parents efbab60 + bd5ad29 commit 13a2960

File tree

68 files changed

+302
-309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+302
-309
lines changed

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ exclude = [
356356
module = [
357357
"yaml",
358358
"fire",
359+
"redis.asyncio",
360+
"psycopg2",
361+
"psycopg2.extras",
362+
"psycopg2.extensions",
359363
"torchtune.*",
360364
"fairscale.*",
361365
"torchvision.*",

src/llama_stack/core/conversations/conversations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
from pydantic import BaseModel, TypeAdapter
1212

1313
from llama_stack.core.datatypes import AccessRule, StackRunConfig
14+
from llama_stack.core.storage.sqlstore.authorized_sqlstore import AuthorizedSqlStore
15+
from llama_stack.core.storage.sqlstore.sqlstore import sqlstore_impl
1416
from llama_stack.log import get_logger
15-
from llama_stack.providers.utils.sqlstore.api import ColumnDefinition, ColumnType
16-
from llama_stack.providers.utils.sqlstore.authorized_sqlstore import AuthorizedSqlStore
17-
from llama_stack.providers.utils.sqlstore.sqlstore import sqlstore_impl
1817
from llama_stack_api import (
1918
Conversation,
2019
ConversationDeletedResource,
@@ -25,6 +24,7 @@
2524
Conversations,
2625
Metadata,
2726
)
27+
from llama_stack_api.internal.sqlstore import ColumnDefinition, ColumnType
2828

2929
logger = get_logger(name=__name__, category="openai_conversations")
3030

src/llama_stack/core/prompts/prompts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pydantic import BaseModel
1111

1212
from llama_stack.core.datatypes import StackRunConfig
13-
from llama_stack.providers.utils.kvstore import KVStore, kvstore_impl
13+
from llama_stack.core.storage.kvstore import KVStore, kvstore_impl
1414
from llama_stack_api import ListPromptsResponse, Prompt, Prompts
1515

1616

src/llama_stack/core/server/quota.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from starlette.types import ASGIApp, Receive, Scope, Send
1212

1313
from llama_stack.core.storage.datatypes import KVStoreReference, StorageBackendType
14+
from llama_stack.core.storage.kvstore.kvstore import _KVSTORE_BACKENDS, kvstore_impl
1415
from llama_stack.log import get_logger
15-
from llama_stack.providers.utils.kvstore.api import KVStore
16-
from llama_stack.providers.utils.kvstore.kvstore import _KVSTORE_BACKENDS, kvstore_impl
16+
from llama_stack_api.internal.kvstore import KVStore
1717

1818
logger = get_logger(name=__name__, category="core::server")
1919

src/llama_stack/core/stack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@ def _initialize_storage(run_config: StackRunConfig):
385385
else:
386386
raise ValueError(f"Unknown storage backend type: {type}")
387387

388-
from llama_stack.providers.utils.kvstore.kvstore import register_kvstore_backends
389-
from llama_stack.providers.utils.sqlstore.sqlstore import register_sqlstore_backends
388+
from llama_stack.core.storage.kvstore.kvstore import register_kvstore_backends
389+
from llama_stack.core.storage.sqlstore.sqlstore import register_sqlstore_backends
390390

391391
register_kvstore_backends(kv_backends)
392392
register_sqlstore_backends(sql_backends)

src/llama_stack/providers/utils/kvstore/__init__.py renamed to src/llama_stack/core/storage/kvstore/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
# This source code is licensed under the terms described in the LICENSE file in
55
# the root directory of this source tree.
66

7+
from llama_stack_api.internal.kvstore import KVStore as KVStore
8+
79
from .kvstore import * # noqa: F401, F403

src/llama_stack/providers/utils/kvstore/kvstore.py renamed to src/llama_stack/core/storage/kvstore/kvstore.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@
1313

1414
import asyncio
1515
from collections import defaultdict
16+
from datetime import datetime
17+
from typing import cast
1618

17-
from llama_stack.core.storage.datatypes import KVStoreReference, StorageBackendConfig, StorageBackendType
19+
from llama_stack.core.storage.datatypes import KVStoreReference, StorageBackendConfig
20+
from llama_stack_api.internal.kvstore import KVStore
1821

19-
from .api import KVStore
20-
from .config import KVStoreConfig
22+
from .config import (
23+
KVStoreConfig,
24+
MongoDBKVStoreConfig,
25+
PostgresKVStoreConfig,
26+
RedisKVStoreConfig,
27+
SqliteKVStoreConfig,
28+
)
2129

2230

2331
def kvstore_dependencies():
@@ -33,15 +41,15 @@ def kvstore_dependencies():
3341

3442
class InmemoryKVStoreImpl(KVStore):
3543
def __init__(self):
36-
self._store = {}
44+
self._store: dict[str, str] = {}
3745

3846
async def initialize(self) -> None:
3947
pass
4048

4149
async def get(self, key: str) -> str | None:
4250
return self._store.get(key)
4351

44-
async def set(self, key: str, value: str) -> None:
52+
async def set(self, key: str, value: str, expiration: datetime | None = None) -> None:
4553
self._store[key] = value
4654

4755
async def values_in_range(self, start_key: str, end_key: str) -> list[str]:
@@ -70,7 +78,8 @@ def register_kvstore_backends(backends: dict[str, StorageBackendConfig]) -> None
7078
_KVSTORE_INSTANCES.clear()
7179
_KVSTORE_LOCKS.clear()
7280
for name, cfg in backends.items():
73-
_KVSTORE_BACKENDS[name] = cfg
81+
typed_cfg = cast(KVStoreConfig, cfg)
82+
_KVSTORE_BACKENDS[name] = typed_cfg
7483

7584

7685
async def kvstore_impl(reference: KVStoreReference) -> KVStore:
@@ -94,19 +103,20 @@ async def kvstore_impl(reference: KVStoreReference) -> KVStore:
94103
config = backend_config.model_copy()
95104
config.namespace = reference.namespace
96105

97-
if config.type == StorageBackendType.KV_REDIS.value:
106+
impl: KVStore
107+
if isinstance(config, RedisKVStoreConfig):
98108
from .redis import RedisKVStoreImpl
99109

100110
impl = RedisKVStoreImpl(config)
101-
elif config.type == StorageBackendType.KV_SQLITE.value:
111+
elif isinstance(config, SqliteKVStoreConfig):
102112
from .sqlite import SqliteKVStoreImpl
103113

104114
impl = SqliteKVStoreImpl(config)
105-
elif config.type == StorageBackendType.KV_POSTGRES.value:
115+
elif isinstance(config, PostgresKVStoreConfig):
106116
from .postgres import PostgresKVStoreImpl
107117

108118
impl = PostgresKVStoreImpl(config)
109-
elif config.type == StorageBackendType.KV_MONGODB.value:
119+
elif isinstance(config, MongoDBKVStoreConfig):
110120
from .mongodb import MongoDBKVStoreImpl
111121

112122
impl = MongoDBKVStoreImpl(config)

src/llama_stack/providers/utils/kvstore/mongodb/mongodb.py renamed to src/llama_stack/core/storage/kvstore/mongodb/mongodb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from pymongo import AsyncMongoClient
1010
from pymongo.asynchronous.collection import AsyncCollection
1111

12+
from llama_stack.core.storage.kvstore import KVStore
1213
from llama_stack.log import get_logger
13-
from llama_stack.providers.utils.kvstore import KVStore
1414

1515
from ..config import MongoDBKVStoreConfig
1616

0 commit comments

Comments
 (0)