Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HISTORY.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
==========

13.4.0 (2025-02-11)
---------------------

* Initial release for DSS 13.4.0

13.3.3 (2025-01-27)
---------------------
Expand Down
77 changes: 75 additions & 2 deletions dataikuapi/dss/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,31 @@ def remove_plugin_credential(self, plugin_id, param_set_id, preset_id, param_nam
del self.settings["credentials"][name]


class DSSUserPreferences(object):
"""
Preferences for a DSS user.

.. important::

Do not instantiate directly, use :meth:`DSSUserSettings.preferences` instead.
"""
def __init__(self, preferences):
self.preferences = preferences

@property
def ui_language(self):
"""
Get or set the language used in the Web User Interface for this user. Valid values are "en" (English) and "ja" (Japanese)

:rtype: str
"""
return self.preferences['uiLanguage']

@ui_language.setter
def ui_language(self, new_value):
self.preferences["uiLanguage"] = new_value


class DSSUserSettings(DSSUserSettingsBase):
"""
Settings for a DSS user.
Expand Down Expand Up @@ -866,6 +891,16 @@ def creation_date(self):
timestamp = self.settings["creationDate"] if "creationDate" in self.settings else None
return _timestamp_ms_to_zoned_datetime(timestamp)

@property
def preferences(self):
"""
Get the preferences for this user

:return: user preferences
:rtype: :class:`DSSUserPreferences`
"""
return DSSUserPreferences(self.settings["preferences"])

def save(self):
"""
Saves the settings
Expand Down Expand Up @@ -1460,7 +1495,7 @@ def set_jupyter_support(self, active):
raise Exception('Env update failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {}))))
return resp

def update_packages(self, force_rebuild_env=False):
def update_packages(self, force_rebuild_env=False, version=None):
"""
Update the code env packages so that it matches its spec

Expand All @@ -1469,6 +1504,7 @@ def update_packages(self, force_rebuild_env=False):
This call requires an API key with `Create code envs` or `Manage all code envs` permission

:param boolean force_rebuild_env: whether to rebuild the code env from scratch
:param boolean version: version to rebuild (applies only to version code envs on automation nodes)

:return: list of messages collected during the operation. Fields are:

Expand All @@ -1480,7 +1516,7 @@ def update_packages(self, force_rebuild_env=False):
"""
resp = self.client._perform_json(
"POST", "/admin/code-envs/%s/%s/packages" % (self.env_lang, self.env_name),
params={"forceRebuildEnv": force_rebuild_env})
params={"forceRebuildEnv": force_rebuild_env, "versionToUpdate": version})
if resp is None:
raise Exception('Env update returned no data')
if resp.get('messages', {}).get('error', False):
Expand Down Expand Up @@ -2690,3 +2726,40 @@ def save(self):
"""
self.client._perform_empty("PUT", "/admin/code-studios/%s" % (self.template_id), body=self.settings)

class DSSLLMCostLimitingCounters(object):
"""
The LLM cost limiting counters of the instance
"""
def __init__(self, data):
self._data = data

def get_raw(self):
"""
Gets counters as a raw dictionary.

:return: a dictionary containing raw counters
:rtype: dict
"""
return self._data

@property
def counters(self):
"""
Get the list of counters

:return: a list of counters
:rtype: list
"""
return self._data['counters']

def get_counter(self, id):
"""
Retrieve the counters from a quota id

:param id identifier of the quota to retrieve

:return: a dictionary containing the counter
:rtype: dict
"""
return next((counter for counter in self.counters if counter["id"] == id), None)

73 changes: 73 additions & 0 deletions dataikuapi/dss/agent_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from .utils import DSSTaggableObjectListItem
import json

class DSSAgentToolListItem(DSSTaggableObjectListItem):
"""
.. important::
Do not instantiate this class directly, instead use :meth:`dataikuapi.dss.project.DSSProject.list_agent_tools`.
"""
def __init__(self, client, project_key, data):
super(DSSAgentToolListItem, self).__init__(data)
self.project_key = project_key
self.client = client

def to_agent_tool(self):
"""
Convert the current item.
"""
return DSSAgentTool(self.client, self.project_key, self._data["id"], "descriptor" in self._data and self._data["desciptor"] or None)

@property
def id(self):
"""
:returns: The id of the tool.
:rtype: string
"""
return self._data["id"]

@property
def type(self):
"""
:returns: The type of the tool
:rtype: string
"""
return self._data["type"]

@property
def description(self):
"""
:returns: The description of the LLM (name, description, input schema)
:rtype: string
"""
return self._data["description"]



class DSSAgentTool(object):
def __init__(self, client, project_key, tool_id, descriptor=None):
self.client = client
self.project_key = project_key
self.tool_id = tool_id
self._descriptor = descriptor

def get_descriptor(self):
if self._descriptor is None:
self._descriptor = self.client._perform_json("GET", "/projects/%s/agents/tools/%s/descriptor" % (self.project_key, self.tool_id))
return self._descriptor


def as_langchain_structured_tool(self, context = None):
from dataikuapi.dss.langchain.tool import convert_to_langchain_structured_tool
return convert_to_langchain_structured_tool(self, context)

def run(self, input, context=None):
invocation = {
"toolId" : self.tool_id,
"input" : {
"input" : input
}
}
if context is not None:
invocation["input"]["context"] = context

return self.client._perform_json("POST", "/projects/%s/agents/tools/%s/invocations" % (self.project_key, self.tool_id), body=invocation)
Loading