Skip to content

Commit d17b278

Browse files
Some PR fixes
1 parent 0056bc3 commit d17b278

File tree

4 files changed

+117
-167
lines changed

4 files changed

+117
-167
lines changed

redisai/client.py

+23-16
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ def scriptdel(self, key: AnyStr) -> str:
622622
res = self.execute_command(*args)
623623
return res if not self.enable_postprocess else processor.scriptdel(res)
624624

625+
@deprecated(version="1.2.0", reason="Use scriptexecute instead")
625626
def scriptrun(
626627
self,
627628
key: AnyStr,
@@ -642,7 +643,7 @@ def scriptrun(
642643
Tensor(s) which is already saved in the RedisAI using a tensorset call. These
643644
tensors will be used as the input for the modelrun
644645
outputs : Union[AnyStr, List[AnyStr]]
645-
keys on which the outputs to be saved. If those keys exist already, modelrun
646+
keys on which the outputs to be saved. If those keys exist already, scriptrun
646647
will overwrite them with new values
647648
648649
Returns
@@ -662,37 +663,38 @@ def scriptrun(
662663
def scriptexecute(
663664
self,
664665
key: AnyStr,
665-
function: AnyStr,
666+
function: str,
666667
keys: Union[AnyStr, Sequence[AnyStr]],
667-
inputs: Union[AnyStr, Sequence[AnyStr]] = None,
668-
list_inputs: Sequence[Sequence[AnyStr]] = None,
668+
inputs: Union[AnyStr, Sequence[Union[AnyStr, Sequence[AnyStr]]]] = None,
669669
outputs: Union[AnyStr, Sequence[AnyStr]] = None,
670670
timeout: int = None,
671671
) -> str:
672672
"""
673-
Run an already set script. Similar to modelrun
673+
Run an already set script. Similar to modelexecute
674674
675675
Parameters
676676
----------
677677
key : AnyStr
678678
Script key
679-
function : AnyStr
679+
function : str
680680
Name of the function in the ``script``
681681
keys : Union[AnyStr, Sequence[AnyStr]]
682682
Either a squence of key names that the script will access before, during and
683683
after its execution, or a tag which all those keys share.
684-
inputs : Union[AnyStr, List[AnyStr]]
685-
Tensor(s) which is already saved in the RedisAI using a tensorset call. These
686-
tensors will be used as the input for the modelrun
687-
list_inputs : Sequence[Sequence[AnyStr]]
688-
list of inputs.
684+
inputs : Union[AnyStr, Sequence[Union[AnyStr, Sequence[AnyStr]]]]
685+
The inputs can be tensor key name, string , int or float.
686+
These inputs will be used as the input for the scriptexecute function.
687+
The order of the input should be aligned with the order of their respected
688+
parameter at the function signature.
689+
When one of the elements in the inputs list is a list (or a tuple), that element
690+
will be treated as LIST_INPUTS in the command executaion.
689691
outputs : Union[AnyStr, List[AnyStr]]
690-
keys on which the outputs to be saved. If those keys exist already, modelrun
691-
will overwrite them with new values
692+
keys on which the outputs to be saved. If those keys exist already, scriptexecute
693+
will overwrite them with new values.
692694
timeout : int
693695
The max number on milisecinds that may pass before the request is prossced
694696
(meaning that the result will not be computed after that time and TIMEDOUT
695-
is returned in that case)
697+
is returned in that case).
696698
697699
Returns
698700
-------
@@ -703,10 +705,15 @@ def scriptexecute(
703705
-------
704706
>>> con.scriptexecute('ket', 'bar', keys=['a', 'b', 'c'], inputs=['a', 'b'], outputs=['c'])
705707
'OK'
708+
>>> con.scriptexecute('myscript{tag}', 'addn',
709+
>>> keys=['{tag}'],
710+
>>> inputs=['mytensor1{tag}', ['mytensor2{tag}', 'mytensor3{tag}']],
711+
>>> outputs=['result{tag}'])
712+
'OK'
706713
"""
707-
args = builder.scriptexecute(key, function, keys, inputs, list_inputs, outputs, timeout)
714+
args = builder.scriptexecute(key, function, keys, inputs, outputs, timeout)
708715
res = self.execute_command(*args)
709-
return res if not self.enable_postprocess else processor.scriptrun(res)
716+
return res if not self.enable_postprocess else processor.scriptexecute(res)
710717

711718
def scriptscan(self) -> List[List[AnyStr]]:
712719
"""

redisai/command_builder.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,12 @@ def scriptdel(name: AnyStr) -> Sequence:
228228

229229
def scriptrun(
230230
name: AnyStr,
231-
function: AnyStr,
231+
function: str,
232232
inputs: Union[AnyStr, Sequence[AnyStr]],
233233
outputs: Union[AnyStr, Sequence[AnyStr]],
234234
) -> Sequence:
235+
if name is None or function is None:
236+
raise ValueError("Missing required arguments for script run command")
235237
args = (
236238
"AI.SCRIPTRUN",
237239
name,
@@ -245,13 +247,14 @@ def scriptrun(
245247

246248
def scriptexecute(
247249
name: AnyStr,
248-
function: AnyStr,
250+
function: str,
249251
keys: Union[AnyStr, Sequence[AnyStr]],
250-
inputs: Union[AnyStr, Sequence[AnyStr]],
251-
list_inputs: Sequence[Sequence[AnyStr]],
252+
inputs: Union[AnyStr, Sequence[Union[AnyStr, Sequence[AnyStr]]]],
252253
outputs: Union[AnyStr, Sequence[AnyStr]],
253254
timeout: int,
254255
) -> Sequence:
256+
if name is None or function is None or keys is None:
257+
raise ValueError("Missing required arguments for script execute command")
255258
args = [
256259
"AI.SCRIPTEXECUTE",
257260
name,
@@ -262,10 +265,20 @@ def scriptexecute(
262265
]
263266

264267
if inputs is not None:
265-
args += ["INPUTS", len(utils.listify(inputs)), *utils.listify(inputs)]
266-
if list_inputs is not None:
267-
for li in list_inputs:
268-
args += ["LIST_INPUTS", len(li), *li]
268+
temp_inputs = []
269+
if not isinstance(inputs, (list, tuple)):
270+
args += ["INPUTS", 1, inputs]
271+
else:
272+
for elem in inputs:
273+
if isinstance(elem, (list, tuple)):
274+
if temp_inputs:
275+
args += ["INPUTS", len(temp_inputs), *temp_inputs]
276+
temp_inputs = []
277+
args += ["LIST_INPUTS", len(utils.listify(elem)), *utils.listify(elem)]
278+
else:
279+
temp_inputs.append(elem)
280+
if temp_inputs:
281+
args += ["INPUTS", len(temp_inputs), *temp_inputs]
269282
if outputs is not None:
270283
args += ["OUTPUTS", len(utils.listify(outputs)), *utils.listify(outputs)]
271284
if timeout is not None:

redisai/postprocessor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def infoget(res):
7070
"scriptset",
7171
"scriptdel",
7272
"scriptrun",
73-
"scriptexecute"
73+
"scriptexecute",
7474
"inforeset",
7575
)
7676
for fn in decoding_functions:

0 commit comments

Comments
 (0)