select-ai 1.0.0.dev4__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.

Potentially problematic release.


This version of select-ai might be problematic. Click here for more details.

select_ai/__init__.py ADDED
@@ -0,0 +1,52 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Copyright (c) 2025, Oracle and/or its affiliates.
3
+ #
4
+ # Licensed under the Universal Permissive License v 1.0 as shown at
5
+ # http://oss.oracle.com/licenses/upl.
6
+ # -----------------------------------------------------------------------------
7
+
8
+ from .action import Action
9
+ from .admin import (
10
+ create_credential,
11
+ disable_provider,
12
+ enable_provider,
13
+ )
14
+ from .async_profile import AsyncProfile
15
+ from .base_profile import BaseProfile, ProfileAttributes
16
+ from .conversation import (
17
+ AsyncConversation,
18
+ Conversation,
19
+ ConversationAttributes,
20
+ )
21
+ from .db import (
22
+ async_connect,
23
+ async_cursor,
24
+ async_is_connected,
25
+ connect,
26
+ cursor,
27
+ is_connected,
28
+ )
29
+ from .profile import Profile
30
+ from .provider import (
31
+ AnthropicProvider,
32
+ AWSProvider,
33
+ AzureProvider,
34
+ CohereProvider,
35
+ GoogleProvider,
36
+ HuggingFaceProvider,
37
+ OCIGenAIProvider,
38
+ OpenAIProvider,
39
+ Provider,
40
+ )
41
+ from .synthetic_data import (
42
+ SyntheticDataAttributes,
43
+ SyntheticDataParams,
44
+ )
45
+ from .vector_index import (
46
+ AsyncVectorIndex,
47
+ OracleVectorIndexAttributes,
48
+ VectorDistanceMetric,
49
+ VectorIndex,
50
+ VectorIndexAttributes,
51
+ )
52
+ from .version import __version__ as __version__
select_ai/_abc.py ADDED
@@ -0,0 +1,74 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Copyright (c) 2025, Oracle and/or its affiliates.
3
+ #
4
+ # Licensed under the Universal Permissive License v 1.0 as shown at
5
+ # http://oss.oracle.com/licenses/upl.
6
+ # -----------------------------------------------------------------------------
7
+
8
+ import json
9
+ import typing
10
+ from abc import ABC
11
+ from dataclasses import dataclass, fields
12
+ from typing import Any, List, Mapping
13
+
14
+ __all__ = ["SelectAIDataClass"]
15
+
16
+
17
+ def _bool(value: Any) -> bool:
18
+ if isinstance(value, bool):
19
+ return value
20
+ if isinstance(value, int):
21
+ return bool(value)
22
+ if value.lower() in ('yes', 'true', 't', 'y', '1'):
23
+ return True
24
+ elif value.lower() in ('no', 'false', 'f', 'n', '0'):
25
+ return False
26
+ else:
27
+ raise ValueError(f"Invalid boolean value: {value}")
28
+
29
+ @dataclass
30
+ class SelectAIDataClass(ABC):
31
+ """SelectAIDataClass is an abstract container for all data
32
+ models defined in the select_ai Python module
33
+ """
34
+
35
+ def __getitem__(self, item):
36
+ return getattr(self, item)
37
+
38
+ def __setitem__(self, key, value):
39
+ setattr(self, key, value)
40
+
41
+ @classmethod
42
+ def keys(cls):
43
+ return set([field.name for field in fields(cls)])
44
+
45
+ def dict(self, exclude_null=True):
46
+ attributes = {}
47
+ for k, v in self.__dict__.items():
48
+ if v is not None or not exclude_null:
49
+ attributes[k] = v
50
+ return attributes
51
+
52
+ def json(self, exclude_null=True):
53
+ return json.dumps(self.dict(exclude_null=exclude_null))
54
+
55
+ def __post_init__(self):
56
+ for field in fields(self):
57
+ value = getattr(self, field.name)
58
+ if value is not None:
59
+ if field.type is typing.Optional[int]:
60
+ setattr(self, field.name, int(value))
61
+ elif field.type is typing.Optional[str]:
62
+ setattr(self, field.name, str(value))
63
+ elif field.type is typing.Optional[bool]:
64
+ setattr(self, field.name, _bool(value))
65
+ elif field.type is typing.Optional[float]:
66
+ setattr(self, field.name, float(value))
67
+ elif field.type is typing.Optional[Mapping] and isinstance(
68
+ value, (str, bytes, bytearray)
69
+ ):
70
+ setattr(self, field.name, json.loads(value))
71
+ elif field.type is typing.Optional[
72
+ List[typing.Mapping]
73
+ ] and isinstance(value, (str, bytes, bytearray)):
74
+ setattr(self, field.name, json.loads(value))
select_ai/_enums.py ADDED
@@ -0,0 +1,14 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Copyright (c) 2025, Oracle and/or its affiliates.
3
+ #
4
+ # Licensed under the Universal Permissive License v 1.0 as shown at
5
+ # http://oss.oracle.com/licenses/upl.
6
+ # -----------------------------------------------------------------------------
7
+
8
+ import enum
9
+
10
+
11
+ class StrEnum(str, enum.Enum):
12
+
13
+ def __str__(self):
14
+ return self.value
select_ai/action.py ADDED
@@ -0,0 +1,21 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Copyright (c) 2025, Oracle and/or its affiliates.
3
+ #
4
+ # Licensed under the Universal Permissive License v 1.0 as shown at
5
+ # http://oss.oracle.com/licenses/upl.
6
+ # -----------------------------------------------------------------------------
7
+
8
+ from select_ai._enums import StrEnum
9
+
10
+ __all__ = ["Action"]
11
+
12
+
13
+ class Action(StrEnum):
14
+ """Supported Select AI actions"""
15
+
16
+ RUNSQL = "runsql"
17
+ SHOWSQL = "showsql"
18
+ EXPLAINSQL = "explainsql"
19
+ NARRATE = "narrate"
20
+ CHAT = "chat"
21
+ SHOWPROMPT = "showprompt"
select_ai/admin.py ADDED
@@ -0,0 +1,108 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Copyright (c) 2025, Oracle and/or its affiliates.
3
+ #
4
+ # Licensed under the Universal Permissive License v 1.0 as shown at
5
+ # http://oss.oracle.com/licenses/upl.
6
+ # -----------------------------------------------------------------------------
7
+
8
+ from typing import List, Mapping
9
+
10
+ import oracledb
11
+
12
+ from .db import cursor
13
+ from .sql import (
14
+ DISABLE_AI_PROFILE_DOMAIN_FOR_USER,
15
+ ENABLE_AI_PROFILE_DOMAIN_FOR_USER,
16
+ GRANT_PRIVILEGES_TO_USER,
17
+ REVOKE_PRIVILEGES_FROM_USER,
18
+ )
19
+
20
+ __all__ = [
21
+ "create_credential",
22
+ "disable_provider",
23
+ "enable_provider",
24
+ ]
25
+
26
+
27
+ def create_credential(credential: Mapping, replace: bool = False):
28
+ """
29
+ Creates a credential object using DBMS_CLOUD.CREATE_CREDENTIAL
30
+
31
+ if replace is True, credential will be replaced if it "already exists"
32
+
33
+ """
34
+ valid_keys = {
35
+ "credential_name",
36
+ "username",
37
+ "password",
38
+ "user_ocid",
39
+ "tenancy_ocid",
40
+ "private_key",
41
+ "fingerprint",
42
+ "comments",
43
+ }
44
+ for k in credential.keys():
45
+ if k.lower() not in valid_keys:
46
+ raise ValueError(
47
+ f"Invalid value {k}: {credential[k]} for credential object"
48
+ )
49
+
50
+ with cursor() as cr:
51
+ try:
52
+ cr.callproc(
53
+ "DBMS_CLOUD.CREATE_CREDENTIAL", keyword_parameters=credential
54
+ )
55
+ except oracledb.DatabaseError as e:
56
+ (error,) = e.args
57
+ # If already exists and replace is True then drop and recreate
58
+ if "already exists" in error.message.lower() and replace:
59
+ cr.callproc(
60
+ "DBMS_CLOUD.DROP_CREDENTIAL",
61
+ keyword_parameters={
62
+ "credential_name": credential["credential_name"]
63
+ },
64
+ )
65
+ cr.callproc(
66
+ "DBMS_CLOUD.CREATE_CREDENTIAL",
67
+ keyword_parameters=credential,
68
+ )
69
+ else:
70
+ raise
71
+
72
+
73
+ def enable_provider(users: List[str], provider_endpoint: str = None):
74
+ """
75
+ Enables AI profile for the user. This method grants execute privilege
76
+ on the packages DBMS_CLOUD, DBMS_CLOUD_AI and DBMS_CLOUD_PIPELINE. It
77
+ also enables the user to invoke the AI(LLM) endpoint hosted at a
78
+ certain domain
79
+ """
80
+
81
+ with cursor() as cr:
82
+ for user in users:
83
+ cr.execute(GRANT_PRIVILEGES_TO_USER.format(user))
84
+ if provider_endpoint:
85
+ cr.execute(
86
+ ENABLE_AI_PROFILE_DOMAIN_FOR_USER,
87
+ user=user,
88
+ host=provider_endpoint,
89
+ )
90
+
91
+
92
+ def disable_provider(users: List[str], provider_endpoint: str = None):
93
+ """
94
+ Disables AI provider for the user. This method revokes execute privilege
95
+ on the packages DBMS_CLOUD, DBMS_CLOUD_AI and DBMS_CLOUD_PIPELINE. It
96
+ also disables the user to invoke the AI(LLM) endpoint hosted at a
97
+ certain domain
98
+ """
99
+
100
+ with cursor() as cr:
101
+ for user in users:
102
+ cr.execute(REVOKE_PRIVILEGES_FROM_USER.format(user))
103
+ if provider_endpoint:
104
+ cr.execute(
105
+ DISABLE_AI_PROFILE_DOMAIN_FOR_USER,
106
+ user=user,
107
+ host=provider_endpoint,
108
+ )