uncertainty-engine-types 0.0.2__py3-none-any.whl → 0.0.4__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.
- uncertainty_engine_types/__init__.py +17 -15
- uncertainty_engine_types/context.py +12 -0
- uncertainty_engine_types/conversation.py +7 -0
- uncertainty_engine_types/llm.py +4 -94
- uncertainty_engine_types/message.py +24 -3
- uncertainty_engine_types/model.py +0 -30
- uncertainty_engine_types/node_info.py +14 -3
- uncertainty_engine_types/sensor_designer.py +0 -14
- uncertainty_engine_types/sql.py +2 -66
- uncertainty_engine_types/tabular_data.py +0 -8
- uncertainty_engine_types/vector_store.py +2 -211
- uncertainty_engine_types/version.py +1 -0
- {uncertainty_engine_types-0.0.2.dist-info → uncertainty_engine_types-0.0.4.dist-info}/METADATA +2 -6
- uncertainty_engine_types-0.0.4.dist-info/RECORD +19 -0
- {uncertainty_engine_types-0.0.2.dist-info → uncertainty_engine_types-0.0.4.dist-info}/WHEEL +1 -1
- uncertainty_engine_types-0.0.2.dist-info/RECORD +0 -16
|
@@ -1,42 +1,44 @@
|
|
|
1
|
+
from .context import Context
|
|
2
|
+
from .conversation import Conversation
|
|
1
3
|
from .execution_error import ExecutionError
|
|
2
4
|
from .graph import Graph, NodeElement, NodeId, SourceHandle, TargetHandle
|
|
3
5
|
from .handle import Handle
|
|
4
|
-
from .llm import
|
|
6
|
+
from .llm import LLMConfig, LLMProvider
|
|
5
7
|
from .message import Message
|
|
6
|
-
from .model import TwinLabModel
|
|
7
|
-
from .node_info import NodeInfo, NodeInputInfo, NodeOutputInfo
|
|
8
|
-
from .sensor_designer import SensorDesigner
|
|
9
|
-
from .sql import
|
|
8
|
+
from .model import TwinLabModel
|
|
9
|
+
from .node_info import NodeInfo, NodeInputInfo, NodeOutputInfo, Versions
|
|
10
|
+
from .sensor_designer import SensorDesigner
|
|
11
|
+
from .sql import SQLConfig, SQLKind
|
|
10
12
|
from .tabular_data import TabularData
|
|
11
13
|
from .token import Token
|
|
12
|
-
from .vector_store import
|
|
14
|
+
from .vector_store import VectorStoreConfig, VectorStoreProvider
|
|
15
|
+
from .version import __version__
|
|
16
|
+
|
|
13
17
|
|
|
14
18
|
__all__ = [
|
|
19
|
+
"__version__",
|
|
20
|
+
"Context",
|
|
21
|
+
"Conversation",
|
|
15
22
|
"ExecutionError",
|
|
16
23
|
"Graph",
|
|
17
24
|
"Handle",
|
|
18
|
-
"
|
|
19
|
-
"LLMManager",
|
|
25
|
+
"LLMConfig",
|
|
20
26
|
"LLMProvider",
|
|
21
27
|
"Message",
|
|
22
|
-
"Message",
|
|
23
28
|
"NodeElement",
|
|
24
29
|
"NodeId",
|
|
25
30
|
"NodeInfo",
|
|
26
31
|
"NodeInputInfo",
|
|
27
32
|
"NodeOutputInfo",
|
|
28
|
-
"save_model",
|
|
29
|
-
"save_sensor_designer",
|
|
30
33
|
"SensorDesigner",
|
|
31
34
|
"SourceHandle",
|
|
32
|
-
"
|
|
35
|
+
"SQLConfig",
|
|
33
36
|
"SQLKind",
|
|
34
|
-
"SQLManager",
|
|
35
37
|
"TabularData",
|
|
36
38
|
"TargetHandle",
|
|
37
39
|
"Token",
|
|
38
40
|
"TwinLabModel",
|
|
39
|
-
"
|
|
40
|
-
"VectorStoreManager",
|
|
41
|
+
"VectorStoreConfig",
|
|
41
42
|
"VectorStoreProvider",
|
|
43
|
+
"Versions",
|
|
42
44
|
]
|
uncertainty_engine_types/llm.py
CHANGED
|
@@ -1,111 +1,21 @@
|
|
|
1
|
-
from abc import ABC, abstractmethod
|
|
2
1
|
from enum import Enum
|
|
3
2
|
from typing import Optional
|
|
4
3
|
|
|
5
4
|
from pydantic import BaseModel
|
|
6
|
-
from typeguard import typechecked
|
|
7
5
|
|
|
8
6
|
|
|
9
|
-
@typechecked
|
|
10
|
-
class LLM(ABC):
|
|
11
|
-
|
|
12
|
-
@property
|
|
13
|
-
def temperature(self) -> float:
|
|
14
|
-
return self._temperature
|
|
15
|
-
|
|
16
|
-
@temperature.setter
|
|
17
|
-
def temperature(self, value: float) -> None:
|
|
18
|
-
if not 0.0 <= value <= 1.0:
|
|
19
|
-
raise ValueError("Temperature must be between 0.0 and 1.0")
|
|
20
|
-
self._temperature = value
|
|
21
|
-
|
|
22
|
-
@abstractmethod
|
|
23
|
-
def get_langchain_llm(self, query: str) -> "LLM":
|
|
24
|
-
"""
|
|
25
|
-
Return a BaseLLM object from Langchain according to the provider type.
|
|
26
|
-
"""
|
|
27
|
-
pass
|
|
28
|
-
|
|
29
|
-
def run_query(self, query: str) -> str:
|
|
30
|
-
"""
|
|
31
|
-
Call the LLM with a query.
|
|
32
|
-
"""
|
|
33
|
-
llm = self.get_langchain_llm()
|
|
34
|
-
return llm.invoke(query).content
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
@typechecked
|
|
38
|
-
class OpenAILLM(LLM):
|
|
39
|
-
|
|
40
|
-
def __init__(self, api_key: str, model: str, temperature: float = 0.0):
|
|
41
|
-
self.api_key = api_key
|
|
42
|
-
self.model = model
|
|
43
|
-
self.temperature = temperature
|
|
44
|
-
|
|
45
|
-
def get_langchain_llm(self):
|
|
46
|
-
from langchain_openai import ChatOpenAI
|
|
47
|
-
|
|
48
|
-
return ChatOpenAI(
|
|
49
|
-
model=self.model,
|
|
50
|
-
temperature=self.temperature,
|
|
51
|
-
api_key=self.api_key,
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
@typechecked
|
|
56
|
-
class OllamaLLM(LLM):
|
|
57
|
-
def __init__(self, url: str, model: str, temperature: float = 0.0):
|
|
58
|
-
self.url = url
|
|
59
|
-
self.model = model
|
|
60
|
-
self.temperature = temperature
|
|
61
|
-
|
|
62
|
-
def get_langchain_llm(self):
|
|
63
|
-
from langchain_ollama import ChatOllama
|
|
64
|
-
|
|
65
|
-
return ChatOllama(
|
|
66
|
-
base_url=self.url,
|
|
67
|
-
model=self.model,
|
|
68
|
-
temperature=self.temperature,
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
@typechecked
|
|
73
7
|
class LLMProvider(Enum):
|
|
74
8
|
OPENAI = "openai"
|
|
75
9
|
OLLAMA = "ollama"
|
|
76
10
|
|
|
77
11
|
|
|
78
|
-
|
|
79
|
-
class LLMManager(BaseModel):
|
|
12
|
+
class LLMConfig(BaseModel):
|
|
80
13
|
"""
|
|
81
|
-
Connection
|
|
14
|
+
Connection configuration for Language Learning Models (LLMs).
|
|
82
15
|
"""
|
|
83
16
|
|
|
84
|
-
url: str
|
|
85
17
|
provider: str
|
|
86
18
|
model: str
|
|
87
19
|
temperature: float = 0.0
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def connect(self) -> LLM:
|
|
91
|
-
"""
|
|
92
|
-
Connect to the LLM.
|
|
93
|
-
"""
|
|
94
|
-
|
|
95
|
-
match self.provider:
|
|
96
|
-
case LLMProvider.OPENAI.value:
|
|
97
|
-
if self.api_key is None:
|
|
98
|
-
raise ValueError("API key is required for OpenAI LLM")
|
|
99
|
-
return OpenAILLM(
|
|
100
|
-
api_key=self.api_key,
|
|
101
|
-
model=self.model,
|
|
102
|
-
temperature=self.temperature,
|
|
103
|
-
)
|
|
104
|
-
case LLMProvider.OLLAMA.value:
|
|
105
|
-
return OllamaLLM(
|
|
106
|
-
url=self.url,
|
|
107
|
-
model=self.model,
|
|
108
|
-
temperature=self.temperature,
|
|
109
|
-
)
|
|
110
|
-
case _:
|
|
111
|
-
raise ValueError(f"Unknown LLM provider: {self.provider}")
|
|
20
|
+
ollama_url: Optional[str] = None
|
|
21
|
+
openai_api_key: Optional[str] = None
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
|
+
from typing import Dict, Literal, Sequence, Union
|
|
2
3
|
|
|
3
|
-
from pydantic import BaseModel
|
|
4
|
+
from pydantic import BaseModel, model_validator
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Value = Union[str, float, int]
|
|
8
|
+
StructuredOutput = Dict[str, Union[Value, Sequence[Value], Dict[str, Value]]]
|
|
4
9
|
|
|
5
10
|
|
|
6
11
|
class Message(BaseModel):
|
|
7
|
-
role:
|
|
8
|
-
content: str
|
|
12
|
+
role: Literal["instruction", "user", "engine"]
|
|
13
|
+
content: Union[str, StructuredOutput]
|
|
9
14
|
timestamp: datetime
|
|
15
|
+
|
|
16
|
+
@model_validator(mode="before")
|
|
17
|
+
@classmethod
|
|
18
|
+
def validate(cls, values: Dict) -> Dict:
|
|
19
|
+
role = values.get("role")
|
|
20
|
+
content = values.get("content")
|
|
21
|
+
|
|
22
|
+
if role in ["instruction", "user"]:
|
|
23
|
+
if not isinstance(content, str):
|
|
24
|
+
raise ValueError(f"Content must be a string when role is {role}")
|
|
25
|
+
elif role == "engine":
|
|
26
|
+
if not isinstance(content, StructuredOutput):
|
|
27
|
+
raise ValueError(
|
|
28
|
+
"Content must be a structured output when role is engine"
|
|
29
|
+
)
|
|
30
|
+
return values
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
from typing import Any, Dict, Tuple
|
|
2
|
-
import json
|
|
3
|
-
import tempfile
|
|
4
|
-
|
|
5
1
|
from pydantic import BaseModel, ConfigDict
|
|
6
2
|
|
|
7
3
|
|
|
@@ -11,29 +7,3 @@ class TwinLabModel(BaseModel):
|
|
|
11
7
|
metadata: dict
|
|
12
8
|
|
|
13
9
|
model_config = ConfigDict(protected_namespaces=())
|
|
14
|
-
|
|
15
|
-
def load_model(self) -> Tuple[Any, Dict]:
|
|
16
|
-
|
|
17
|
-
from twinlab_models.models import model_type_from_str # type: ignore
|
|
18
|
-
|
|
19
|
-
model_type = self.model_type
|
|
20
|
-
tl_model = model_type_from_str(model_type)
|
|
21
|
-
|
|
22
|
-
with tempfile.NamedTemporaryFile(mode="w", suffix=".json") as f:
|
|
23
|
-
# Write the JSON to the temporary file
|
|
24
|
-
json.dump(self.model_dump(), f) # Changed dumps to dump
|
|
25
|
-
f.flush()
|
|
26
|
-
tl_model, meta_data = tl_model.load(f.name)
|
|
27
|
-
|
|
28
|
-
return tl_model, meta_data
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
# TODO: Should this be a method of the type?
|
|
32
|
-
def save_model(model, meta_data: dict) -> TwinLabModel:
|
|
33
|
-
|
|
34
|
-
with tempfile.NamedTemporaryFile(mode="r", suffix=".json") as f:
|
|
35
|
-
model.save(f.name, meta_data)
|
|
36
|
-
f.seek(0)
|
|
37
|
-
config = json.load(f)
|
|
38
|
-
|
|
39
|
-
return TwinLabModel(**config)
|
|
@@ -2,10 +2,18 @@ from typing import Any, Optional
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel
|
|
4
4
|
|
|
5
|
+
from .version import __version__
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Versions(BaseModel):
|
|
9
|
+
base_image: str
|
|
10
|
+
types_lib: str = __version__
|
|
11
|
+
node: str
|
|
12
|
+
|
|
5
13
|
|
|
6
14
|
class NodeInputInfo(BaseModel):
|
|
7
|
-
label: str
|
|
8
15
|
type: str
|
|
16
|
+
label: str
|
|
9
17
|
description: str
|
|
10
18
|
required: bool = True
|
|
11
19
|
set_in_node: bool = True
|
|
@@ -13,18 +21,21 @@ class NodeInputInfo(BaseModel):
|
|
|
13
21
|
|
|
14
22
|
|
|
15
23
|
class NodeOutputInfo(BaseModel):
|
|
16
|
-
label: str
|
|
17
24
|
type: str
|
|
25
|
+
label: str
|
|
18
26
|
description: str
|
|
19
27
|
|
|
20
28
|
|
|
21
29
|
class NodeInfo(BaseModel):
|
|
22
30
|
id: str
|
|
23
|
-
version: int
|
|
24
31
|
label: str
|
|
25
32
|
category: str
|
|
26
33
|
description: str
|
|
27
34
|
long_description: str
|
|
35
|
+
image_name: str
|
|
28
36
|
cost: int
|
|
29
37
|
inputs: dict[str, NodeInputInfo]
|
|
30
38
|
outputs: dict[str, NodeOutputInfo] = {}
|
|
39
|
+
queue_url: Optional[str] = None
|
|
40
|
+
cache_url: Optional[str] = None
|
|
41
|
+
versions: Versions
|
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
import json
|
|
2
|
-
|
|
3
1
|
from pydantic import BaseModel
|
|
4
2
|
|
|
5
3
|
|
|
6
4
|
class SensorDesigner(BaseModel):
|
|
7
5
|
bed: dict
|
|
8
|
-
|
|
9
|
-
def load_sensor_designer(self):
|
|
10
|
-
|
|
11
|
-
from twinlab_bed.BED import BED
|
|
12
|
-
|
|
13
|
-
bed = BED.from_json(json.dumps(self.bed))
|
|
14
|
-
|
|
15
|
-
return bed
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def save_sensor_designer(bed) -> SensorDesigner:
|
|
19
|
-
return SensorDesigner(bed=json.loads(bed.to_json()))
|
uncertainty_engine_types/sql.py
CHANGED
|
@@ -1,61 +1,15 @@
|
|
|
1
|
-
from abc import ABC, abstractmethod
|
|
2
1
|
from enum import Enum
|
|
3
|
-
from typing import Any
|
|
4
2
|
|
|
5
3
|
from pydantic import BaseModel
|
|
6
|
-
from typeguard import typechecked
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class SQLDatabase(ABC):
|
|
10
|
-
@abstractmethod
|
|
11
|
-
def execute(self, query: str) -> list[tuple[Any, ...]]:
|
|
12
|
-
"""
|
|
13
|
-
Execute the given query.
|
|
14
|
-
|
|
15
|
-
Parameters:
|
|
16
|
-
query (str): The SQL query to execute.
|
|
17
|
-
|
|
18
|
-
Returns:
|
|
19
|
-
str: The result of the query.
|
|
20
|
-
"""
|
|
21
|
-
pass
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class PostgreSQL(SQLDatabase):
|
|
25
|
-
@typechecked
|
|
26
|
-
def __init__(
|
|
27
|
-
self, host: str, username: str, password: str, port: int, database: str
|
|
28
|
-
):
|
|
29
|
-
import psycopg2
|
|
30
|
-
|
|
31
|
-
self.connection = psycopg2.connect(
|
|
32
|
-
host=host, user=username, password=password, port=port, database=database
|
|
33
|
-
)
|
|
34
|
-
self.cursor = self.connection.cursor()
|
|
35
|
-
|
|
36
|
-
@typechecked
|
|
37
|
-
def execute(self, query: str) -> list[tuple[Any, ...]]:
|
|
38
|
-
"""
|
|
39
|
-
Execute the given query.
|
|
40
|
-
|
|
41
|
-
Parameters:
|
|
42
|
-
query (str): The SQL query to execute.
|
|
43
|
-
|
|
44
|
-
Returns:
|
|
45
|
-
str: The result of the query.
|
|
46
|
-
"""
|
|
47
|
-
|
|
48
|
-
self.cursor.execute(query)
|
|
49
|
-
return self.cursor.fetchall()
|
|
50
4
|
|
|
51
5
|
|
|
52
6
|
class SQLKind(Enum):
|
|
53
7
|
POSTGRES = "POSTGRES"
|
|
54
8
|
|
|
55
9
|
|
|
56
|
-
class
|
|
10
|
+
class SQLConfig(BaseModel):
|
|
57
11
|
"""
|
|
58
|
-
Connection
|
|
12
|
+
Connection configuration for SQL databases.
|
|
59
13
|
"""
|
|
60
14
|
|
|
61
15
|
kind: SQLKind
|
|
@@ -64,21 +18,3 @@ class SQLManager(BaseModel):
|
|
|
64
18
|
password: str
|
|
65
19
|
port: int
|
|
66
20
|
database: str
|
|
67
|
-
|
|
68
|
-
@typechecked
|
|
69
|
-
def connect(self) -> SQLDatabase:
|
|
70
|
-
"""
|
|
71
|
-
Connect to the SQL database.
|
|
72
|
-
"""
|
|
73
|
-
|
|
74
|
-
match self.kind:
|
|
75
|
-
case SQLKind.POSTGRES:
|
|
76
|
-
return PostgreSQL(
|
|
77
|
-
host=self.host,
|
|
78
|
-
username=self.username,
|
|
79
|
-
password=self.password,
|
|
80
|
-
port=self.port,
|
|
81
|
-
database=self.database,
|
|
82
|
-
)
|
|
83
|
-
case _:
|
|
84
|
-
raise ValueError("Unsupported SQL kind")
|
|
@@ -1,108 +1,15 @@
|
|
|
1
|
-
from abc import ABC, abstractmethod
|
|
2
1
|
from enum import Enum
|
|
3
|
-
from typing import Optional, Literal, List, Dict
|
|
4
2
|
|
|
5
3
|
from pydantic import BaseModel
|
|
6
|
-
from typeguard import typechecked
|
|
7
4
|
|
|
8
5
|
|
|
9
6
|
class VectorStoreProvider(Enum):
|
|
10
7
|
WEAVIATE = "weaviate"
|
|
11
8
|
|
|
12
9
|
|
|
13
|
-
class
|
|
14
|
-
@abstractmethod
|
|
15
|
-
def ingest(self, texts, metadatas):
|
|
16
|
-
pass
|
|
17
|
-
|
|
18
|
-
@abstractmethod
|
|
19
|
-
def retrieve(self, query, k):
|
|
20
|
-
pass
|
|
21
|
-
|
|
22
|
-
@abstractmethod
|
|
23
|
-
def get_vector_store(self):
|
|
24
|
-
pass
|
|
25
|
-
|
|
26
|
-
@abstractmethod
|
|
27
|
-
def close(self):
|
|
28
|
-
pass
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
@typechecked
|
|
32
|
-
class WeaviateVectorStoreConnection(VectorStoreConnection):
|
|
33
|
-
|
|
34
|
-
def __init__(
|
|
35
|
-
self,
|
|
36
|
-
host: str,
|
|
37
|
-
port: str,
|
|
38
|
-
collection: str,
|
|
39
|
-
embedding_type: str,
|
|
40
|
-
embedding_model: str,
|
|
41
|
-
embedding_api_key: str,
|
|
42
|
-
):
|
|
43
|
-
|
|
44
|
-
self.host = host
|
|
45
|
-
self.port = port
|
|
46
|
-
self.collection = collection
|
|
47
|
-
self.embedding_type = embedding_type
|
|
48
|
-
self.embedding_model = embedding_model
|
|
49
|
-
self.embedding_api_key = embedding_api_key
|
|
50
|
-
self.vector_store = get_persistent_vector_store(
|
|
51
|
-
host, port, collection, embedding_type, embedding_model, embedding_api_key
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
def ingest(self, texts: List[str], metadatas: List[Dict]) -> List[str]:
|
|
55
|
-
"""
|
|
56
|
-
Ingest a list of texts into the vector store.
|
|
57
|
-
|
|
58
|
-
Args:
|
|
59
|
-
texts (List[str]): The texts to ingest.
|
|
60
|
-
metadatas (List[Dict]): The metadata associated with each text.
|
|
61
|
-
|
|
62
|
-
Returns:
|
|
63
|
-
List[str]: The IDs of the ingested texts.
|
|
64
|
-
|
|
65
|
-
"""
|
|
66
|
-
|
|
67
|
-
return self.vector_store.add_texts(texts=texts, metadatas=metadatas)
|
|
68
|
-
|
|
69
|
-
def retrieve(self, query: Optional[str], k: int) -> List[Dict]:
|
|
70
|
-
"""
|
|
71
|
-
Retrieve the k most relevant documents to a query.
|
|
72
|
-
|
|
73
|
-
Args:
|
|
74
|
-
query (Optional[str]): The query to retrieve documents for.
|
|
75
|
-
k (int): The number of documents to retrieve.
|
|
76
|
-
|
|
77
|
-
Returns:
|
|
78
|
-
List[str]: The IDs of the retrieved documents.
|
|
79
|
-
|
|
80
|
-
"""
|
|
81
|
-
|
|
82
|
-
docs = self.vector_store.max_marginal_relevance_search(query=query, k=k)
|
|
83
|
-
docs_list = [
|
|
84
|
-
{"content": doc.page_content, "metadata": doc.metadata} for doc in docs
|
|
85
|
-
]
|
|
86
|
-
return docs_list
|
|
87
|
-
|
|
88
|
-
def get_vector_store(self):
|
|
89
|
-
"""
|
|
90
|
-
Get the underlying vector store.
|
|
91
|
-
|
|
92
|
-
Returns:
|
|
93
|
-
LangcahinWeaviateVectorStore: The underlying vector store.
|
|
94
|
-
|
|
95
|
-
"""
|
|
96
|
-
|
|
97
|
-
return self.vector_store
|
|
98
|
-
|
|
99
|
-
def close(self):
|
|
100
|
-
self.vector_store._client.close()
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
class VectorStoreManager(BaseModel):
|
|
10
|
+
class VectorStoreConfig(BaseModel):
|
|
104
11
|
"""
|
|
105
|
-
Connection
|
|
12
|
+
Connection configuration for a vector store.
|
|
106
13
|
"""
|
|
107
14
|
|
|
108
15
|
provider: str
|
|
@@ -112,119 +19,3 @@ class VectorStoreManager(BaseModel):
|
|
|
112
19
|
embedding_type: str
|
|
113
20
|
embedding_model: str
|
|
114
21
|
embedding_api_key: str
|
|
115
|
-
|
|
116
|
-
@typechecked
|
|
117
|
-
def connect(self) -> WeaviateVectorStoreConnection:
|
|
118
|
-
"""
|
|
119
|
-
Connect to the vector store.
|
|
120
|
-
|
|
121
|
-
Returns:
|
|
122
|
-
VectorStoreConnection: The vector store connection.
|
|
123
|
-
"""
|
|
124
|
-
|
|
125
|
-
match self.provider:
|
|
126
|
-
case VectorStoreProvider.WEAVIATE.value:
|
|
127
|
-
return WeaviateVectorStoreConnection(
|
|
128
|
-
host=self.host,
|
|
129
|
-
port=self.port,
|
|
130
|
-
collection=self.collection,
|
|
131
|
-
embedding_type=self.embedding_type,
|
|
132
|
-
embedding_model=self.embedding_model,
|
|
133
|
-
embedding_api_key=self.embedding_api_key,
|
|
134
|
-
)
|
|
135
|
-
case _:
|
|
136
|
-
raise ValueError(f"Unknown vector store provider: {self.provider}")
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
@typechecked
|
|
140
|
-
def get_persistent_vector_store(
|
|
141
|
-
host: str,
|
|
142
|
-
port: str,
|
|
143
|
-
collection: str,
|
|
144
|
-
embedding_type: str,
|
|
145
|
-
embedding_model: str,
|
|
146
|
-
embedding_api_key: Optional[str] = None,
|
|
147
|
-
):
|
|
148
|
-
"""
|
|
149
|
-
Get a database client connected to a deployed Weaviate vector store
|
|
150
|
-
"""
|
|
151
|
-
|
|
152
|
-
from langchain_weaviate import WeaviateVectorStore
|
|
153
|
-
from weaviate.connect import ConnectionParams
|
|
154
|
-
import weaviate
|
|
155
|
-
|
|
156
|
-
try:
|
|
157
|
-
client = weaviate.WeaviateClient(
|
|
158
|
-
connection_params=ConnectionParams.from_params(
|
|
159
|
-
http_host=host,
|
|
160
|
-
http_port=port,
|
|
161
|
-
http_secure=False,
|
|
162
|
-
grpc_host=host,
|
|
163
|
-
grpc_port="50051",
|
|
164
|
-
grpc_secure=False,
|
|
165
|
-
),
|
|
166
|
-
skip_init_checks=True,
|
|
167
|
-
)
|
|
168
|
-
client.connect()
|
|
169
|
-
except Exception as e:
|
|
170
|
-
raise ValueError(f"Failed to connect to Weaviate: {e}")
|
|
171
|
-
|
|
172
|
-
embedding_function = get_embedding_function(
|
|
173
|
-
embedding_type, embedding_model, embedding_api_key
|
|
174
|
-
)
|
|
175
|
-
|
|
176
|
-
# check if a collection exists and makes one if it doesn't
|
|
177
|
-
if not client.collections.exists(collection):
|
|
178
|
-
client.collections.create(collection)
|
|
179
|
-
|
|
180
|
-
try:
|
|
181
|
-
vector_store = WeaviateVectorStore(
|
|
182
|
-
client=client,
|
|
183
|
-
index_name=collection,
|
|
184
|
-
text_key="text",
|
|
185
|
-
embedding=embedding_function,
|
|
186
|
-
)
|
|
187
|
-
except Exception as e:
|
|
188
|
-
raise ValueError(f"Failed to initialize Weaviate vector store: {e}")
|
|
189
|
-
|
|
190
|
-
return vector_store
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
@typechecked
|
|
194
|
-
def get_embedding_function(
|
|
195
|
-
embedding_type: Literal["huggingface", "openai"],
|
|
196
|
-
embedding_model: str,
|
|
197
|
-
embedding_api_key: Optional[str] = None,
|
|
198
|
-
):
|
|
199
|
-
"""
|
|
200
|
-
Get an embedding function based on the specified type and configuration.
|
|
201
|
-
"""
|
|
202
|
-
|
|
203
|
-
from langchain_huggingface import HuggingFaceEmbeddings
|
|
204
|
-
from langchain_openai import OpenAIEmbeddings
|
|
205
|
-
|
|
206
|
-
match embedding_type:
|
|
207
|
-
case "huggingface":
|
|
208
|
-
try:
|
|
209
|
-
return HuggingFaceEmbeddings(model_name=embedding_model)
|
|
210
|
-
except Exception as e:
|
|
211
|
-
raise ValueError(
|
|
212
|
-
f"Failed to initialize HuggingFace embedding model: {str(e)}"
|
|
213
|
-
) from e
|
|
214
|
-
|
|
215
|
-
case "openai":
|
|
216
|
-
if not embedding_api_key:
|
|
217
|
-
raise ValueError("OpenAI embeddings require an API key")
|
|
218
|
-
try:
|
|
219
|
-
return OpenAIEmbeddings(
|
|
220
|
-
model=embedding_model, api_key=embedding_api_key
|
|
221
|
-
)
|
|
222
|
-
except Exception as e:
|
|
223
|
-
raise ValueError(
|
|
224
|
-
f"Failed to initialize OpenAI embedding model: {str(e)}"
|
|
225
|
-
) from e
|
|
226
|
-
|
|
227
|
-
case _:
|
|
228
|
-
raise ValueError(
|
|
229
|
-
f"Embedding type must be one of ['huggingface', 'openai']. Got {embedding_type}"
|
|
230
|
-
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.4"
|
{uncertainty_engine_types-0.0.2.dist-info → uncertainty_engine_types-0.0.4.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: uncertainty-engine-types
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
4
4
|
Summary: Common type definitions for the Uncertainty Engine
|
|
5
5
|
Author: Freddy Wordingham
|
|
6
6
|
Author-email: freddy@digilab.ai
|
|
@@ -10,14 +10,10 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.11
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.12
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
-
Requires-Dist: pandas (>=2.2.3,<3.0.0)
|
|
14
13
|
Requires-Dist: pydantic (>=2.10.5,<3.0.0)
|
|
15
|
-
Requires-Dist: typeguard (>=2.13.3,<2.14.0)
|
|
16
14
|
Description-Content-Type: text/markdown
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
<img src="./assets/images/uncertainty-engine-logo.png">
|
|
20
|
-
</div>
|
|
16
|
+

|
|
21
17
|
|
|
22
18
|
# Types
|
|
23
19
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
uncertainty_engine_types/__init__.py,sha256=AbQ7nlKUqTMJ7MuFWBLrUGPnnz-KeNxjRjw_mlud6wU,1104
|
|
2
|
+
uncertainty_engine_types/context.py,sha256=k9rlArn-L2x1P5vWy5khfuqJW5tJOqr3NlhubZCbyG4,209
|
|
3
|
+
uncertainty_engine_types/conversation.py,sha256=uDHTr4uPzjkcflhyFAanfiQ1KbEIs4C9jogrwzOEt_s,122
|
|
4
|
+
uncertainty_engine_types/execution_error.py,sha256=tvIBuZPM8UhFUERHCEqoW8blAYYuBq1ZqidO0i_BCGs,105
|
|
5
|
+
uncertainty_engine_types/graph.py,sha256=ii2YT2jxoRB7UhcceI2k_ArKmlUXEwBCRBpsEUjL2Qg,265
|
|
6
|
+
uncertainty_engine_types/handle.py,sha256=DEu3aCwJsOuinQ2Gxdy6dZbwnCHAXkplIT4WNL6o7oQ,444
|
|
7
|
+
uncertainty_engine_types/llm.py,sha256=oivoY3aDv5Rsk8FWA-vOPEFfK9a6-SqSyu01AlEuO7o,406
|
|
8
|
+
uncertainty_engine_types/message.py,sha256=KncFJQHL_ko8nfOuso_eh7i2gB0y4nXI6gBW9U8lAEY,971
|
|
9
|
+
uncertainty_engine_types/model.py,sha256=sVP4e25uV114XOGbcDxvvngcI6bMXRaM3zLRLKP30C0,188
|
|
10
|
+
uncertainty_engine_types/node_info.py,sha256=5_t18hKJ4ZOhB-64DzPzr7Teq9S1HeB7VXHL2J8UVeA,784
|
|
11
|
+
uncertainty_engine_types/sensor_designer.py,sha256=hr3ek4_dRjRK0-78uaT6h8-bGUCm7Mfs6mxJSWxE64c,80
|
|
12
|
+
uncertainty_engine_types/sql.py,sha256=SBzmgMEZ-sa-OBRoZbmKiOqddop4zJixgxx-JCus9fY,298
|
|
13
|
+
uncertainty_engine_types/tabular_data.py,sha256=i_1LfgQqxDanPRWuDkP3Hd8-9eVet6FbPIlPZlAi1n0,76
|
|
14
|
+
uncertainty_engine_types/token.py,sha256=4tQQkvl-zsYoVk8ZEx0cB2JiU0VDRJ6uUe76XBXEpBY,178
|
|
15
|
+
uncertainty_engine_types/vector_store.py,sha256=9fYPJ04jWcy2DruyUSjiKQAgmqq-wgeAi5dBIrAOm30,392
|
|
16
|
+
uncertainty_engine_types/version.py,sha256=1mptEzQihbdyqqzMgdns_j5ZGK9gz7hR2bsgA_TnjO4,22
|
|
17
|
+
uncertainty_engine_types-0.0.4.dist-info/METADATA,sha256=f2-J06g-f0RHmgs30Q0GEzxlrCQMG5OOxt0B19YFzZs,3596
|
|
18
|
+
uncertainty_engine_types-0.0.4.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
19
|
+
uncertainty_engine_types-0.0.4.dist-info/RECORD,,
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
uncertainty_engine_types/__init__.py,sha256=jWiOjdxBRqGT1tjnKA0oEFc9xp9rDCKmZIDgt0jxFr4,1123
|
|
2
|
-
uncertainty_engine_types/execution_error.py,sha256=tvIBuZPM8UhFUERHCEqoW8blAYYuBq1ZqidO0i_BCGs,105
|
|
3
|
-
uncertainty_engine_types/graph.py,sha256=ii2YT2jxoRB7UhcceI2k_ArKmlUXEwBCRBpsEUjL2Qg,265
|
|
4
|
-
uncertainty_engine_types/handle.py,sha256=DEu3aCwJsOuinQ2Gxdy6dZbwnCHAXkplIT4WNL6o7oQ,444
|
|
5
|
-
uncertainty_engine_types/llm.py,sha256=n85oICjqxFoa6S9BzrSAydu6giRDbq8-dCTRn41pzzI,2796
|
|
6
|
-
uncertainty_engine_types/message.py,sha256=On9n0S4U6nOMKmJfQDOnlBSF8MhHjiuekQEKVH84kj0,145
|
|
7
|
-
uncertainty_engine_types/model.py,sha256=TzOZt0np3ECdzfxewZfTX93k1FrPBh25D6BJaEIJ9v8,1070
|
|
8
|
-
uncertainty_engine_types/node_info.py,sha256=Xh9NQKwSc3V4IkESF5-RcOPTkzQcOveYR7J1nvKBjFI,556
|
|
9
|
-
uncertainty_engine_types/sensor_designer.py,sha256=_91bBp0k2OnFN9QuDkHhfbhCalVfxCtH6lGciazYZdI,350
|
|
10
|
-
uncertainty_engine_types/sql.py,sha256=rNpGqCe1BMvYiJIv_z9kk6BhVa_1Qn30HZcIfYA1vuo,1914
|
|
11
|
-
uncertainty_engine_types/tabular_data.py,sha256=y56F_Np-qPij9ioACcAobNna_Dwm3rfad3PKpdhRSkM,209
|
|
12
|
-
uncertainty_engine_types/token.py,sha256=4tQQkvl-zsYoVk8ZEx0cB2JiU0VDRJ6uUe76XBXEpBY,178
|
|
13
|
-
uncertainty_engine_types/vector_store.py,sha256=lsWEzjVvOsfUy2qmoI4ZEF9ieukMi1Z6Mt0XYTcq-f0,6370
|
|
14
|
-
uncertainty_engine_types-0.0.2.dist-info/METADATA,sha256=nWPZIPTswNUrVaMlQYe5G3swFp_ccQLEnkCKs0dWWaA,3665
|
|
15
|
-
uncertainty_engine_types-0.0.2.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
|
|
16
|
-
uncertainty_engine_types-0.0.2.dist-info/RECORD,,
|