oracle-ads 2.11.19__py3-none-any.whl → 2.12.1__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.
- ads/aqua/config/evaluation/evaluation_service_config.py +1 -0
- ads/aqua/extension/model_handler.py +17 -21
- ads/aqua/model/constants.py +3 -1
- ads/llm/__init__.py +10 -4
- ads/llm/chat_template.py +31 -0
- ads/llm/guardrails/base.py +3 -2
- ads/llm/guardrails/huggingface.py +1 -1
- ads/llm/langchain/plugins/chat_models/__init__.py +5 -0
- ads/llm/langchain/plugins/chat_models/oci_data_science.py +924 -0
- ads/llm/langchain/plugins/llms/__init__.py +5 -0
- ads/llm/langchain/plugins/llms/oci_data_science_model_deployment_endpoint.py +939 -0
- ads/llm/requirements.txt +2 -2
- ads/llm/serialize.py +3 -6
- ads/llm/templates/tool_chat_template_hermes.jinja +130 -0
- ads/llm/templates/tool_chat_template_mistral_parallel.jinja +94 -0
- ads/opctl/operator/lowcode/anomaly/const.py +7 -2
- ads/opctl/operator/lowcode/anomaly/model/autots.py +30 -35
- ads/opctl/operator/lowcode/anomaly/model/factory.py +9 -8
- ads/opctl/operator/lowcode/anomaly/schema.yaml +8 -2
- ads/opctl/operator/lowcode/forecast/MLoperator +3 -3
- ads/opctl/operator/lowcode/forecast/model/automlx.py +1 -1
- ads/opctl/operator/lowcode/forecast/model/forecast_datasets.py +1 -1
- {oracle_ads-2.11.19.dist-info → oracle_ads-2.12.1.dist-info}/METADATA +6 -4
- {oracle_ads-2.11.19.dist-info → oracle_ads-2.12.1.dist-info}/RECORD +27 -25
- ads/llm/langchain/plugins/base.py +0 -118
- ads/llm/langchain/plugins/contant.py +0 -44
- ads/llm/langchain/plugins/embeddings.py +0 -64
- ads/llm/langchain/plugins/llm_gen_ai.py +0 -301
- ads/llm/langchain/plugins/llm_md.py +0 -316
- {oracle_ads-2.11.19.dist-info → oracle_ads-2.12.1.dist-info}/LICENSE.txt +0 -0
- {oracle_ads-2.11.19.dist-info → oracle_ads-2.12.1.dist-info}/WHEEL +0 -0
- {oracle_ads-2.11.19.dist-info → oracle_ads-2.12.1.dist-info}/entry_points.txt +0 -0
@@ -1,316 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8 -*--
|
3
|
-
|
4
|
-
# Copyright (c) 2023 Oracle and/or its affiliates.
|
5
|
-
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
6
|
-
|
7
|
-
import logging
|
8
|
-
from typing import Any, Dict, List, Optional
|
9
|
-
|
10
|
-
import requests
|
11
|
-
from langchain.callbacks.manager import CallbackManagerForLLMRun
|
12
|
-
from langchain.pydantic_v1 import root_validator
|
13
|
-
from langchain.utils import get_from_dict_or_env
|
14
|
-
from oci.auth import signers
|
15
|
-
|
16
|
-
from ads.llm.langchain.plugins.base import BaseLLM
|
17
|
-
from ads.llm.langchain.plugins.contant import (
|
18
|
-
DEFAULT_CONTENT_TYPE_JSON,
|
19
|
-
DEFAULT_TIME_OUT,
|
20
|
-
)
|
21
|
-
|
22
|
-
logger = logging.getLogger(__name__)
|
23
|
-
|
24
|
-
|
25
|
-
class ModelDeploymentLLM(BaseLLM):
|
26
|
-
"""Base class for LLM deployed on OCI Model Deployment."""
|
27
|
-
|
28
|
-
endpoint: str = ""
|
29
|
-
"""The uri of the endpoint from the deployed Model Deployment model."""
|
30
|
-
|
31
|
-
best_of: int = 1
|
32
|
-
"""Generates best_of completions server-side and returns the "best"
|
33
|
-
(the one with the highest log probability per token).
|
34
|
-
"""
|
35
|
-
|
36
|
-
@root_validator()
|
37
|
-
def validate_environment( # pylint: disable=no-self-argument
|
38
|
-
cls, values: Dict
|
39
|
-
) -> Dict:
|
40
|
-
"""Fetch endpoint from environment variable or arguments."""
|
41
|
-
values["endpoint"] = get_from_dict_or_env(
|
42
|
-
values,
|
43
|
-
"endpoint",
|
44
|
-
"OCI_LLM_ENDPOINT",
|
45
|
-
)
|
46
|
-
return values
|
47
|
-
|
48
|
-
@property
|
49
|
-
def _default_params(self) -> Dict[str, Any]:
|
50
|
-
"""Default parameters for the model."""
|
51
|
-
raise NotImplementedError()
|
52
|
-
|
53
|
-
@property
|
54
|
-
def _identifying_params(self) -> Dict[str, Any]:
|
55
|
-
"""Get the identifying parameters."""
|
56
|
-
return {
|
57
|
-
**{"endpoint": self.endpoint},
|
58
|
-
**self._default_params,
|
59
|
-
}
|
60
|
-
|
61
|
-
def _construct_json_body(self, prompt, params):
|
62
|
-
"""Constructs the request body as a dictionary (JSON)."""
|
63
|
-
raise NotImplementedError
|
64
|
-
|
65
|
-
def _invocation_params(self, stop: Optional[List[str]], **kwargs: Any) -> dict:
|
66
|
-
"""Combines the invocation parameters with default parameters."""
|
67
|
-
params = self._default_params
|
68
|
-
if self.stop is not None and stop is not None:
|
69
|
-
raise ValueError("`stop` found in both the input and default params.")
|
70
|
-
elif self.stop is not None:
|
71
|
-
params["stop"] = self.stop
|
72
|
-
elif stop is not None:
|
73
|
-
params["stop"] = stop
|
74
|
-
else:
|
75
|
-
# Don't set "stop" in param as None. It should be a list.
|
76
|
-
params["stop"] = []
|
77
|
-
|
78
|
-
return {**params, **kwargs}
|
79
|
-
|
80
|
-
def _process_response(self, response_json: dict):
|
81
|
-
return response_json
|
82
|
-
|
83
|
-
def _call(
|
84
|
-
self,
|
85
|
-
prompt: str,
|
86
|
-
stop: Optional[List[str]] = None,
|
87
|
-
run_manager: Optional[CallbackManagerForLLMRun] = None,
|
88
|
-
**kwargs: Any,
|
89
|
-
) -> str:
|
90
|
-
"""Call out to OCI Data Science Model Deployment endpoint.
|
91
|
-
|
92
|
-
Parameters
|
93
|
-
----------
|
94
|
-
prompt (str):
|
95
|
-
The prompt to pass into the model.
|
96
|
-
stop (List[str], Optional):
|
97
|
-
List of stop words to use when generating.
|
98
|
-
|
99
|
-
Returns
|
100
|
-
-------
|
101
|
-
The string generated by the model.
|
102
|
-
|
103
|
-
Example
|
104
|
-
-------
|
105
|
-
|
106
|
-
.. code-block:: python
|
107
|
-
|
108
|
-
response = oci_md("Tell me a joke.")
|
109
|
-
|
110
|
-
"""
|
111
|
-
params = self._invocation_params(stop, **kwargs)
|
112
|
-
body = self._construct_json_body(prompt, params)
|
113
|
-
self._print_request(prompt, params)
|
114
|
-
response = self.send_request(data=body, endpoint=self.endpoint)
|
115
|
-
completion = self._process_response(response)
|
116
|
-
self._print_response(completion, response)
|
117
|
-
return completion
|
118
|
-
|
119
|
-
def send_request(
|
120
|
-
self,
|
121
|
-
data,
|
122
|
-
endpoint: str,
|
123
|
-
header: dict = None,
|
124
|
-
**kwargs,
|
125
|
-
) -> Dict:
|
126
|
-
"""Sends request to the model deployment endpoint.
|
127
|
-
|
128
|
-
Parameters
|
129
|
-
----------
|
130
|
-
data (Json serializable):
|
131
|
-
data need to be sent to the endpoint.
|
132
|
-
endpoint (str):
|
133
|
-
The model HTTP endpoint.
|
134
|
-
header (dict, optional):
|
135
|
-
A dictionary of HTTP headers to send to the specified url. Defaults to {}.
|
136
|
-
|
137
|
-
Raises
|
138
|
-
------
|
139
|
-
Exception:
|
140
|
-
Raise when invoking fails.
|
141
|
-
|
142
|
-
Returns
|
143
|
-
-------
|
144
|
-
A JSON representation of a requests.Response object.
|
145
|
-
"""
|
146
|
-
if not header:
|
147
|
-
header = {}
|
148
|
-
header["Content-Type"] = (
|
149
|
-
header.pop("content_type", DEFAULT_CONTENT_TYPE_JSON)
|
150
|
-
or DEFAULT_CONTENT_TYPE_JSON
|
151
|
-
)
|
152
|
-
timeout = kwargs.pop("timeout", DEFAULT_TIME_OUT)
|
153
|
-
request_kwargs = {"json": data}
|
154
|
-
request_kwargs["headers"] = header
|
155
|
-
signer = self.auth.get("signer")
|
156
|
-
|
157
|
-
attempts = 0
|
158
|
-
while attempts < 2:
|
159
|
-
request_kwargs["auth"] = signer
|
160
|
-
response = requests.post(
|
161
|
-
endpoint, timeout=timeout, **request_kwargs, **kwargs
|
162
|
-
)
|
163
|
-
if response.status_code == 401 and self.is_principal_signer(signer):
|
164
|
-
signer.refresh_security_token()
|
165
|
-
attempts += 1
|
166
|
-
continue
|
167
|
-
break
|
168
|
-
|
169
|
-
try:
|
170
|
-
response.raise_for_status()
|
171
|
-
response_json = response.json()
|
172
|
-
|
173
|
-
except Exception:
|
174
|
-
logger.error(
|
175
|
-
"DEBUG INFO: request_kwargs=%s, status_code=%s, content=%s",
|
176
|
-
request_kwargs,
|
177
|
-
response.status_code,
|
178
|
-
response.content,
|
179
|
-
)
|
180
|
-
raise
|
181
|
-
|
182
|
-
return response_json
|
183
|
-
|
184
|
-
@staticmethod
|
185
|
-
def is_principal_signer(signer):
|
186
|
-
"""Checks if the signer is instance principal or resource principal signer."""
|
187
|
-
if (
|
188
|
-
isinstance(signer, signers.InstancePrincipalsSecurityTokenSigner)
|
189
|
-
or isinstance(signer, signers.ResourcePrincipalsFederationSigner)
|
190
|
-
or isinstance(signer, signers.EphemeralResourcePrincipalSigner)
|
191
|
-
or isinstance(signer, signers.EphemeralResourcePrincipalV21Signer)
|
192
|
-
or isinstance(signer, signers.NestedResourcePrincipals)
|
193
|
-
or isinstance(signer, signers.OkeWorkloadIdentityResourcePrincipalSigner)
|
194
|
-
):
|
195
|
-
return True
|
196
|
-
else:
|
197
|
-
return False
|
198
|
-
|
199
|
-
|
200
|
-
class ModelDeploymentTGI(ModelDeploymentLLM):
|
201
|
-
"""OCI Data Science Model Deployment TGI Endpoint.
|
202
|
-
|
203
|
-
Example
|
204
|
-
-------
|
205
|
-
|
206
|
-
.. code-block:: python
|
207
|
-
|
208
|
-
from ads.llm import ModelDeploymentTGI
|
209
|
-
|
210
|
-
oci_md = ModelDeploymentTGI(endpoint="<url_of_model_deployment_endpoint>")
|
211
|
-
|
212
|
-
"""
|
213
|
-
|
214
|
-
do_sample: bool = True
|
215
|
-
"""if set to True, this parameter enables decoding strategies such as
|
216
|
-
multi-nominal sampling, beam-search multi-nominal sampling, Top-K sampling and Top-p sampling.
|
217
|
-
"""
|
218
|
-
|
219
|
-
watermark = True
|
220
|
-
"""Watermarking with `A Watermark for Large Language Models <https://arxiv.org/abs/2301.10226>`_.
|
221
|
-
Defaults to True."""
|
222
|
-
|
223
|
-
return_full_text = False
|
224
|
-
"""Whether to prepend the prompt to the generated text. Defaults to False."""
|
225
|
-
|
226
|
-
@property
|
227
|
-
def _llm_type(self) -> str:
|
228
|
-
"""Return type of llm."""
|
229
|
-
return "oci_model_deployment_tgi_endpoint"
|
230
|
-
|
231
|
-
@property
|
232
|
-
def _default_params(self) -> Dict[str, Any]:
|
233
|
-
"""Get the default parameters for invoking OCI model deployment TGI endpoint."""
|
234
|
-
return {
|
235
|
-
"best_of": self.best_of,
|
236
|
-
"max_new_tokens": self.max_tokens,
|
237
|
-
"temperature": self.temperature,
|
238
|
-
"top_k": self.k
|
239
|
-
if self.k > 0
|
240
|
-
else None, # `top_k` must be strictly positive'
|
241
|
-
"top_p": self.p,
|
242
|
-
"do_sample": self.do_sample,
|
243
|
-
"return_full_text": self.return_full_text,
|
244
|
-
"watermark": self.watermark,
|
245
|
-
}
|
246
|
-
|
247
|
-
def _construct_json_body(self, prompt, params):
|
248
|
-
return {
|
249
|
-
"inputs": prompt,
|
250
|
-
"parameters": params,
|
251
|
-
}
|
252
|
-
|
253
|
-
def _process_response(self, response_json: dict):
|
254
|
-
return str(response_json.get("generated_text", response_json))
|
255
|
-
|
256
|
-
|
257
|
-
class ModelDeploymentVLLM(ModelDeploymentLLM):
|
258
|
-
"""VLLM deployed on OCI Model Deployment"""
|
259
|
-
|
260
|
-
model: str
|
261
|
-
"""Name of the model."""
|
262
|
-
|
263
|
-
n: int = 1
|
264
|
-
"""Number of output sequences to return for the given prompt."""
|
265
|
-
|
266
|
-
k: int = -1
|
267
|
-
"""Number of most likely tokens to consider at each step."""
|
268
|
-
|
269
|
-
frequency_penalty: float = 0.0
|
270
|
-
"""Penalizes repeated tokens according to frequency. Between 0 and 1."""
|
271
|
-
|
272
|
-
presence_penalty: float = 0.0
|
273
|
-
"""Penalizes repeated tokens. Between 0 and 1."""
|
274
|
-
|
275
|
-
use_beam_search: bool = False
|
276
|
-
"""Whether to use beam search instead of sampling."""
|
277
|
-
|
278
|
-
ignore_eos: bool = False
|
279
|
-
"""Whether to ignore the EOS token and continue generating tokens after
|
280
|
-
the EOS token is generated."""
|
281
|
-
|
282
|
-
logprobs: Optional[int] = None
|
283
|
-
"""Number of log probabilities to return per output token."""
|
284
|
-
|
285
|
-
@property
|
286
|
-
def _llm_type(self) -> str:
|
287
|
-
"""Return type of llm."""
|
288
|
-
return "oci_model_deployment_vllm_endpoint"
|
289
|
-
|
290
|
-
@property
|
291
|
-
def _default_params(self) -> Dict[str, Any]:
|
292
|
-
"""Get the default parameters for calling vllm."""
|
293
|
-
return {
|
294
|
-
"n": self.n,
|
295
|
-
"best_of": self.best_of,
|
296
|
-
"max_tokens": self.max_tokens,
|
297
|
-
"top_k": self.k,
|
298
|
-
"top_p": self.p,
|
299
|
-
"temperature": self.temperature,
|
300
|
-
"presence_penalty": self.presence_penalty,
|
301
|
-
"frequency_penalty": self.frequency_penalty,
|
302
|
-
"stop": self.stop,
|
303
|
-
"ignore_eos": self.ignore_eos,
|
304
|
-
"use_beam_search": self.use_beam_search,
|
305
|
-
"logprobs": self.logprobs,
|
306
|
-
"model": self.model,
|
307
|
-
}
|
308
|
-
|
309
|
-
def _construct_json_body(self, prompt, params):
|
310
|
-
return {
|
311
|
-
"prompt": prompt,
|
312
|
-
**params,
|
313
|
-
}
|
314
|
-
|
315
|
-
def _process_response(self, response_json: dict):
|
316
|
-
return response_json["choices"][0]["text"]
|
File without changes
|
File without changes
|
File without changes
|