MCPcopy
hub / github.com/SqueezeAILab/LLMCompiler / run

Method run

src/chains/chain.py:444–512  ·  view source on GitHub ↗

Convenience method for executing chain. The main difference between this method and `Chain.__call__` is that this method expects inputs to be passed directly in as positional arguments or keyword arguments, whereas `Chain.__call__` expects a single input dictionary w

(
        self,
        *args: Any,
        callbacks: Callbacks = None,
        tags: Optional[List[str]] = None,
        metadata: Optional[Dict[str, Any]] = None,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

442 return self.output_keys[0]
443
444 def run(
445 self,
446 *args: Any,
447 callbacks: Callbacks = None,
448 tags: Optional[List[str]] = None,
449 metadata: Optional[Dict[str, Any]] = None,
450 **kwargs: Any,
451 ) -> Any:
452 """Convenience method for executing chain.
453
454 The main difference between this method and `Chain.__call__` is that this
455 method expects inputs to be passed directly in as positional arguments or
456 keyword arguments, whereas `Chain.__call__` expects a single input dictionary
457 with all the inputs
458
459 Args:
460 *args: If the chain expects a single input, it can be passed in as the
461 sole positional argument.
462 callbacks: Callbacks to use for this chain run. These will be called in
463 addition to callbacks passed to the chain during construction, but only
464 these runtime callbacks will propagate to calls to other objects.
465 tags: List of string tags to pass to all callbacks. These will be passed in
466 addition to tags passed to the chain during construction, but only
467 these runtime tags will propagate to calls to other objects.
468 **kwargs: If the chain expects multiple inputs, they can be passed in
469 directly as keyword arguments.
470
471 Returns:
472 The chain output.
473
474 Example:
475 .. code-block:: python
476
477 # Suppose we have a single-input chain that takes a 'question' string:
478 chain.run("What's the temperature in Boise, Idaho?")
479 # -> "The temperature in Boise is..."
480
481 # Suppose we have a multi-input chain that takes a 'question' string
482 # and 'context' string:
483 question = "What's the temperature in Boise, Idaho?"
484 context = "Weather report for Boise, Idaho on 07/03/23..."
485 chain.run(question=question, context=context)
486 # -> "The temperature in Boise is..."
487 """
488 # Run at start to make sure this is possible/defined
489 _output_key = self._run_output_key
490
491 if args and not kwargs:
492 if len(args) != 1:
493 raise ValueError("`run` supports only one positional argument.")
494 return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
495 _output_key
496 ]
497
498 if kwargs and not args:
499 return self(kwargs, callbacks=callbacks, tags=tags, metadata=metadata)[
500 _output_key
501 ]

Callers 3

run_llm_math_chainFunction · 0.80
run_llm_math_chainFunction · 0.80
_take_next_stepMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected