mirascope 1.25.5__py3-none-any.whl → 1.25.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mirascope/beta/rag/chroma/types.py +11 -6
- mirascope/beta/rag/chroma/vectorstores.py +26 -2
- mirascope/core/mistral/_utils/_setup_call.py +11 -1
- mirascope/retries/fallback.py +15 -12
- {mirascope-1.25.5.dist-info → mirascope-1.25.6.dist-info}/METADATA +1 -1
- {mirascope-1.25.5.dist-info → mirascope-1.25.6.dist-info}/RECORD +8 -8
- {mirascope-1.25.5.dist-info → mirascope-1.25.6.dist-info}/WHEEL +0 -0
- {mirascope-1.25.5.dist-info → mirascope-1.25.6.dist-info}/licenses/LICENSE +0 -0
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
from typing import Any, Literal
|
|
4
4
|
|
|
5
|
-
from chromadb import CollectionMetadata
|
|
5
|
+
from chromadb import CollectionMetadata
|
|
6
6
|
from chromadb.api.types import URI, Document, IDs, Loadable, Metadata
|
|
7
|
-
from chromadb.config import DEFAULT_DATABASE, DEFAULT_TENANT
|
|
7
|
+
from chromadb.config import DEFAULT_DATABASE, DEFAULT_TENANT, Settings
|
|
8
8
|
from chromadb.types import Vector
|
|
9
9
|
from pydantic import BaseModel, ConfigDict
|
|
10
10
|
|
|
@@ -29,7 +29,7 @@ class ChromaQueryResult(BaseModel):
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
class ChromaSettings(BaseModel):
|
|
32
|
-
mode: Literal["http", "persistent", "ephemeral"] = "persistent"
|
|
32
|
+
mode: Literal["http", "persistent", "ephemeral", "cloud"] = "persistent"
|
|
33
33
|
path: str = "./chroma"
|
|
34
34
|
host: str = "localhost"
|
|
35
35
|
port: int = 8000
|
|
@@ -38,17 +38,22 @@ class ChromaSettings(BaseModel):
|
|
|
38
38
|
settings: Settings | None = None
|
|
39
39
|
tenant: str = DEFAULT_TENANT
|
|
40
40
|
database: str = DEFAULT_DATABASE
|
|
41
|
+
api_key: str | None = None
|
|
41
42
|
|
|
42
43
|
model_config = ConfigDict(extra="allow", arbitrary_types_allowed=True)
|
|
43
44
|
|
|
44
45
|
def kwargs(self) -> dict[str, Any]:
|
|
45
46
|
"""Returns all parameters for the index as a keyword arguments dictionary."""
|
|
46
47
|
if self.mode == "http":
|
|
47
|
-
exclude = {"mode", "path"}
|
|
48
|
+
exclude = {"mode", "path", "api_key"}
|
|
48
49
|
elif self.mode == "persistent":
|
|
49
|
-
exclude = {"mode", "host", "port", "ssl", "headers"}
|
|
50
|
+
exclude = {"mode", "host", "port", "ssl", "headers", "api_key"}
|
|
50
51
|
elif self.mode == "ephemeral":
|
|
51
|
-
exclude = {"mode", "host", "port", "ssl", "headers", "path"}
|
|
52
|
+
exclude = {"mode", "host", "port", "ssl", "headers", "path", "api_key"}
|
|
53
|
+
elif self.mode == "cloud":
|
|
54
|
+
exclude = {"mode", "path", "host", "port", "ssl", "headers"}
|
|
55
|
+
else:
|
|
56
|
+
exclude = {"mode"}
|
|
52
57
|
kwargs = {
|
|
53
58
|
key: value
|
|
54
59
|
for key, value in self.model_dump(exclude=exclude).items()
|
|
@@ -3,7 +3,14 @@
|
|
|
3
3
|
from functools import cached_property
|
|
4
4
|
from typing import Any, ClassVar, cast
|
|
5
5
|
|
|
6
|
-
from chromadb import
|
|
6
|
+
from chromadb import (
|
|
7
|
+
CloudClient,
|
|
8
|
+
Collection,
|
|
9
|
+
EphemeralClient,
|
|
10
|
+
HttpClient,
|
|
11
|
+
Metadata,
|
|
12
|
+
PersistentClient,
|
|
13
|
+
)
|
|
7
14
|
from chromadb.api import ClientAPI
|
|
8
15
|
|
|
9
16
|
from ..base.document import Document
|
|
@@ -22,12 +29,25 @@ class ChromaVectorStore(BaseVectorStore):
|
|
|
22
29
|
from mirascope.beta.rag import TextChunker
|
|
23
30
|
|
|
24
31
|
|
|
32
|
+
# Local persistent storage
|
|
25
33
|
class MyStore(ChromaVectorStore):
|
|
26
34
|
embedder = OpenAIEmbedder()
|
|
27
35
|
chunker = TextChunker(chunk_size=1000, chunk_overlap=200)
|
|
28
36
|
index_name = "my-store-0001"
|
|
29
37
|
client_settings = ChromaSettings()
|
|
30
38
|
|
|
39
|
+
# Cloud mode with CloudClient authentication
|
|
40
|
+
class MyCloudStore(ChromaVectorStore):
|
|
41
|
+
embedder = OpenAIEmbedder()
|
|
42
|
+
chunker = TextChunker(chunk_size=1000, chunk_overlap=200)
|
|
43
|
+
index_name = "my-cloud-store-0001"
|
|
44
|
+
client_settings = ChromaSettings(
|
|
45
|
+
mode="cloud",
|
|
46
|
+
api_key="your-api-key",
|
|
47
|
+
tenant="your-tenant",
|
|
48
|
+
database="your-database",
|
|
49
|
+
)
|
|
50
|
+
|
|
31
51
|
my_store = MyStore()
|
|
32
52
|
with open(f"{PATH_TO_FILE}") as file:
|
|
33
53
|
data = file.read()
|
|
@@ -82,6 +102,10 @@ class ChromaVectorStore(BaseVectorStore):
|
|
|
82
102
|
return HttpClient(**self.client_settings.kwargs())
|
|
83
103
|
elif self.client_settings.mode == "ephemeral":
|
|
84
104
|
return EphemeralClient(**self.client_settings.kwargs())
|
|
105
|
+
elif self.client_settings.mode == "cloud":
|
|
106
|
+
return CloudClient(**self.client_settings.kwargs())
|
|
107
|
+
else:
|
|
108
|
+
raise ValueError(f"Unsupported client mode: {self.client_settings.mode}")
|
|
85
109
|
|
|
86
110
|
@cached_property
|
|
87
111
|
def _index(self) -> Collection:
|
|
@@ -93,5 +117,5 @@ class ChromaVectorStore(BaseVectorStore):
|
|
|
93
117
|
|
|
94
118
|
return self._client.create_collection(
|
|
95
119
|
**vectorstore_params.kwargs(),
|
|
96
|
-
embedding_function=self.embedder,
|
|
120
|
+
embedding_function=self.embedder, # type: ignore[arg-type]
|
|
97
121
|
)
|
|
@@ -39,6 +39,16 @@ from ..tool import MistralTool
|
|
|
39
39
|
from ._convert_common_call_params import convert_common_call_params
|
|
40
40
|
from ._convert_message_params import convert_message_params
|
|
41
41
|
|
|
42
|
+
global_client: Mistral | None = None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _get_default_client() -> Mistral:
|
|
46
|
+
"""Get or create the default Mistral client."""
|
|
47
|
+
global global_client
|
|
48
|
+
if global_client is None:
|
|
49
|
+
global_client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
|
|
50
|
+
return global_client
|
|
51
|
+
|
|
42
52
|
|
|
43
53
|
@overload
|
|
44
54
|
def setup_call(
|
|
@@ -144,7 +154,7 @@ def setup_call(
|
|
|
144
154
|
call_kwargs |= {"model": model, "messages": messages}
|
|
145
155
|
|
|
146
156
|
if client is None:
|
|
147
|
-
client =
|
|
157
|
+
client = _get_default_client()
|
|
148
158
|
if fn_is_async(fn):
|
|
149
159
|
create_or_stream = get_async_create_fn(
|
|
150
160
|
client.chat.complete_async, client.chat.stream_async
|
mirascope/retries/fallback.py
CHANGED
|
@@ -4,6 +4,7 @@ import inspect
|
|
|
4
4
|
from collections.abc import Callable, Coroutine
|
|
5
5
|
from typing import Any, ParamSpec, Protocol, TypeVar, overload
|
|
6
6
|
|
|
7
|
+
from pydantic import BaseModel
|
|
7
8
|
from typing_extensions import NotRequired, Required, TypedDict
|
|
8
9
|
|
|
9
10
|
from .. import llm
|
|
@@ -75,8 +76,8 @@ def fallback(
|
|
|
75
76
|
def decorator(
|
|
76
77
|
fn: Callable[_P, _R] | Callable[_P, Coroutine[_R, Any, Any]],
|
|
77
78
|
) -> Callable[_P, _R] | Callable[_P, Coroutine[_R, Any, Any]]:
|
|
78
|
-
|
|
79
|
-
if inspect.iscoroutinefunction(
|
|
79
|
+
fn_to_check = fn._original_fn if hasattr(fn, "_original_fn") else fn # pyright: ignore [reportFunctionMemberAccess]
|
|
80
|
+
if inspect.iscoroutinefunction(fn_to_check):
|
|
80
81
|
|
|
81
82
|
async def inner_async(*args: _P.args, **kwargs: _P.kwargs) -> _R:
|
|
82
83
|
caught: list[Exception] = []
|
|
@@ -86,15 +87,16 @@ def fallback(
|
|
|
86
87
|
caught.append(e)
|
|
87
88
|
for backup in fallbacks:
|
|
88
89
|
try:
|
|
89
|
-
|
|
90
|
-
fn,
|
|
90
|
+
with llm.context(
|
|
91
91
|
provider=backup["provider"],
|
|
92
92
|
model=backup["model"],
|
|
93
93
|
call_params=backup.get("call_params", None),
|
|
94
94
|
client=backup.get("client", None),
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
):
|
|
96
|
+
response = await fn(*args, **kwargs) # pyright: ignore [reportGeneralTypeIssues]
|
|
97
|
+
if isinstance(response, BaseModel):
|
|
98
|
+
response._caught = caught # pyright: ignore [reportAttributeAccessIssue]
|
|
99
|
+
return response # pyright: ignore [reportReturnType]
|
|
98
100
|
except backup["catch"] as be:
|
|
99
101
|
caught.append(be)
|
|
100
102
|
raise FallbackError(f"All fallbacks failed:\n{caught}")
|
|
@@ -110,15 +112,16 @@ def fallback(
|
|
|
110
112
|
caught.append(e)
|
|
111
113
|
for backup in fallbacks:
|
|
112
114
|
try:
|
|
113
|
-
|
|
114
|
-
fn,
|
|
115
|
+
with llm.context(
|
|
115
116
|
provider=backup["provider"],
|
|
116
117
|
model=backup["model"],
|
|
117
118
|
call_params=backup.get("call_params", None),
|
|
118
119
|
client=backup.get("client", None),
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
):
|
|
121
|
+
response = fn(*args, **kwargs)
|
|
122
|
+
if isinstance(response, BaseModel):
|
|
123
|
+
response._caught = caught # pyright: ignore [reportAttributeAccessIssue]
|
|
124
|
+
return response # pyright: ignore [reportReturnType]
|
|
122
125
|
except backup["catch"] as be:
|
|
123
126
|
caught.append(be)
|
|
124
127
|
raise FallbackError(f"All fallbacks failed:\n{caught}")
|
|
@@ -23,8 +23,8 @@ mirascope/beta/rag/base/chunkers/__init__.py,sha256=DFSBx6sNnnfR0nua74T1SGuRcwQo
|
|
|
23
23
|
mirascope/beta/rag/base/chunkers/base_chunker.py,sha256=hLK9iZ7_QYnc3HEN0j4nEv-JTaRFnswJESrFNsioOtY,958
|
|
24
24
|
mirascope/beta/rag/base/chunkers/text_chunker.py,sha256=C9o-gYytXoCBeMxOQtjCTBSu3JDkSxDAR_AI9KZG7Ek,913
|
|
25
25
|
mirascope/beta/rag/chroma/__init__.py,sha256=iYH8JKfNz6DrvR9c_z_YdzT5qdfMx9rg4SP4okISyRg,276
|
|
26
|
-
mirascope/beta/rag/chroma/types.py,sha256=
|
|
27
|
-
mirascope/beta/rag/chroma/vectorstores.py,sha256=
|
|
26
|
+
mirascope/beta/rag/chroma/types.py,sha256=cfqLoM5bqyAPcVRQC7KZ34cIQpwo8P_GXhgm-TZa-LY,2179
|
|
27
|
+
mirascope/beta/rag/chroma/vectorstores.py,sha256=iBgOezpyVbwLou1aQrKEkoapH8ZcikoDcZ3EHkc8f60,4089
|
|
28
28
|
mirascope/beta/rag/cohere/__init__.py,sha256=hZfZKIn1B7NdfaUJARWFppDwXAW93p2cHM2uB0OyMtk,300
|
|
29
29
|
mirascope/beta/rag/cohere/embedders.py,sha256=0V8o147p_nxiWt5nkfiUvtbeWNUH9En81yrv1AJJSJQ,2966
|
|
30
30
|
mirascope/beta/rag/cohere/embedding_params.py,sha256=TTT_oDFe22lzjcm8wIPU3snzklHtlWbh_o-Ks73XSaM,1020
|
|
@@ -273,7 +273,7 @@ mirascope/core/mistral/_utils/_convert_message_params.py,sha256=nW18Bh4wQ-Nc00hu
|
|
|
273
273
|
mirascope/core/mistral/_utils/_get_json_output.py,sha256=WxZqpaVec8J5hRYemEHjCK-VhQeAyZ2c-ipWMArXM4o,1243
|
|
274
274
|
mirascope/core/mistral/_utils/_handle_stream.py,sha256=9HowP742tvtXDuq8jO3KGPEnOL92xSP3fMP4SqkjC9E,5083
|
|
275
275
|
mirascope/core/mistral/_utils/_message_param_converter.py,sha256=CCkL4iTei5Ce5ke0h_QnFOdjxulx4Vmyw3a0wDK_T0E,6889
|
|
276
|
-
mirascope/core/mistral/_utils/_setup_call.py,sha256=
|
|
276
|
+
mirascope/core/mistral/_utils/_setup_call.py,sha256=bVTkWZMVIRKRD-L4ptOxy1QF-KSnlfrveOEYwYqjhqY,5057
|
|
277
277
|
mirascope/core/openai/__init__.py,sha256=lOzSimt1AaWyFW2s_w1So5lIn7K2rpj3bEFicjoiyjM,882
|
|
278
278
|
mirascope/core/openai/_call.py,sha256=ExXdY3rjBbil0ija2HlGMRvcOE2zOOj13rgliw8nmFc,2260
|
|
279
279
|
mirascope/core/openai/_call_kwargs.py,sha256=x53EZmxqroNewR194M_JkRP1Ejuh4BTtDL-b7XNSo2Q,435
|
|
@@ -350,7 +350,7 @@ mirascope/mcp/client.py,sha256=ZK88o4UelR9htFWAWDbw084ZTrRL8tONdxlIX62adnM,5608
|
|
|
350
350
|
mirascope/mcp/server.py,sha256=weXBk9ZmUcfZ5SZcR-dGRxvVXRMpn5UsE6ancnK1HZk,12402
|
|
351
351
|
mirascope/mcp/tools.py,sha256=IT7CEqbBBiFc7mkaRpWIepUpuy_oSdcEa4cwGopEYWc,3079
|
|
352
352
|
mirascope/retries/__init__.py,sha256=xw3jJm-vL4kR10VaKN6A8KGoP2CsAg5_Gy1eWVMgYhQ,249
|
|
353
|
-
mirascope/retries/fallback.py,sha256=
|
|
353
|
+
mirascope/retries/fallback.py,sha256=yT-vg7QkDwLHidTenq0HoX0RzbPc2G6IXILGluhzdGc,5063
|
|
354
354
|
mirascope/retries/tenacity.py,sha256=stBJPjEpUzP53IBVBFtqY2fUSgmOV1-sIIXZZJ9pvLY,1387
|
|
355
355
|
mirascope/tools/__init__.py,sha256=wsMYzSvGlFblPcsIF2YV92eZlDHSraWbjB5TicORUyA,959
|
|
356
356
|
mirascope/tools/base.py,sha256=Bdnf9Te2tnPnvBS-dEeXVPv_jn5-z9FY_MQmBwP1ijU,3429
|
|
@@ -372,7 +372,7 @@ mirascope/v0/base/ops_utils.py,sha256=1Qq-VIwgHBaYutiZsS2MUQ4OgPC3APyywI5bTiTAmA
|
|
|
372
372
|
mirascope/v0/base/prompts.py,sha256=FM2Yz98cSnDceYogiwPrp4BALf3_F3d4fIOCGAkd-SE,1298
|
|
373
373
|
mirascope/v0/base/types.py,sha256=ZfatJoX0Yl0e3jhv0D_MhiSVHLYUeJsdN3um3iE10zY,352
|
|
374
374
|
mirascope/v0/base/utils.py,sha256=XREPENRQTu8gpMhHU8RC8qH_am3FfGUvY-dJ6x8i-mw,681
|
|
375
|
-
mirascope-1.25.
|
|
376
|
-
mirascope-1.25.
|
|
377
|
-
mirascope-1.25.
|
|
378
|
-
mirascope-1.25.
|
|
375
|
+
mirascope-1.25.6.dist-info/METADATA,sha256=u7K4te7sbm5FJ_Z4RRn_5wEplYHymZJzjwqROENuNgw,8542
|
|
376
|
+
mirascope-1.25.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
377
|
+
mirascope-1.25.6.dist-info/licenses/LICENSE,sha256=LAs5Q8mdawTsVdONpDGukwsoc4KEUBmmonDEL39b23Y,1072
|
|
378
|
+
mirascope-1.25.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|