class symai.components.All(*expr: List[symai.symbol.Expression])[source]#
forward(*args, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Analyze(exception: Exception, query: Optional[str] = None)[source]#
forward(sym: symai.symbol.Symbol, *args, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Any(*expr: List[symai.symbol.Expression])[source]#
forward(*args, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Choice(cases: List[str], default: Optional[str] = None)[source]#
forward(sym: symai.symbol.Symbol, *args, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Clean(value=None, *args, **kwargs)[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Cluster(value=None, *args, **kwargs)[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Compose(value=None, *args, **kwargs)[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Convert(format: str = 'Python')[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Embed(value=None, *args, **kwargs)[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.ExcludeFilter(exclude: str)[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Execute(value=None, *args, **kwargs)[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.FileQuery(path: str, filter: str)[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.FileReader(value=None, *args, **kwargs)[source]#
forward(path: str, **kwargs) symai.symbol.Expression[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Function(prompt: str, static_context: str = '', examples: typing.Optional[str] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = None, post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = None, default: typing.Optional[object] = None, constraints: typing.List[typing.Callable] = [], return_type: typing.Optional[typing.Type] = <class 'str'>, *args, **kwargs)[source]#
forward(*args, **kwargs) symai.symbol.Expression[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.InContextClassification(blueprint: symai.prompts.Prompt)[source]#
forward(x: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.IncludeFilter(include: str)[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Indexer(index_name: str = 'data-index', top_k: int = 8, batch_size: int = 20, formatter: typing.Callable = <class 'symai.formatter.ParagraphFormatter'>(value=None))[source]#
forward(data: Optional[symai.symbol.Symbol] = None) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.JsonParser(query: str, json_: dict)[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Lambda(callable: Callable)[source]#
forward(*args, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Log(expr: Optional[symai.symbol.Expression] = None, engines=['all'])[source]#
forward(*args, **kwargs) symai.symbol.Expression[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Map(value=None, *args, **kwargs)[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Outline(value=None, *args, **kwargs)[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Output(expr: symai.symbol.Expression, handler: Callable, verbose: bool = False)[source]#
forward(*args, **kwargs) symai.symbol.Expression[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Query(prompt: str)[source]#
forward(sym: symai.symbol.Symbol, context: Optional[symai.symbol.Symbol] = None, *args, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Sequence(*expr: List[symai.symbol.Expression])[source]#
forward(*args, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.SimilarityClassification(classes: List[str], metric: str = 'cosine', in_memory: bool = False)[source]#
forward(x: symai.symbol.Symbol) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Stream(expr: Optional[symai.symbol.Expression] = None, retrieval: Optional[str] = None)[source]#
forward(sym: symai.symbol.Symbol, **kwargs) Iterator[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Style(description: str, libraries: List[str] = [])[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Template(template: str = '<html><body>{{placeholder}}</body></html>', placeholder: str = '{{placeholder}}')[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.TokenTracker[source]#
class symai.components.Trace(expr: Optional[symai.symbol.Expression] = None, engines=['all'])[source]#
forward(*args, **kwargs) symai.symbol.Expression[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.TrackerTraceable(value=None, *args, **kwargs)[source]#
class symai.components.Translate(language: str = 'English')[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.components.Try(expr: symai.symbol.Expression, retries: int = 1)[source]#
forward(sym: symai.symbol.Symbol, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.symbol.Expression(value=None, *args, **kwargs)[source]#
add(query: List[str], **kwargs) symai.symbol.Symbol[source]#

Add an entry to the existing index.

Parameters
  • query (List[str]) – The query string used to add an entry to the index.

  • **kwargs – Arbitrary keyword arguments to be used by the core.index decorator.

Returns

An Expression object containing the addition result.

Return type

Symbol

static command(engines: List[str] = ['all'], **kwargs) symai.symbol.Symbol[source]#

Execute command(s) on engines.

Parameters
  • engines (List[str], optional) – The list of engines on which to execute the command(s). Defaults to [‘all’].

  • **kwargs – Arbitrary keyword arguments to be used by the core.command decorator.

Returns

An Expression object representing the command execution result.

Return type

Symbol

forward(*args, **kwargs) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

get(query: List[int], **kwargs) symai.symbol.Symbol[source]#

Search the index based on the provided query.

Parameters
  • query (List[int]) – The query vector used to search entries in the index.

  • **kwargs – Arbitrary keyword arguments to be used by the core.index decorator.

Returns

An Expression object containing the search result.

Return type

Symbol

index(path: str, **kwargs) symai.symbol.Symbol[source]#

Execute a configuration operation on the index.

Parameters
  • path (str) – Index configuration path.

  • **kwargs – Arbitrary keyword arguments to be used by the core.index decorator.

Returns

An Expression object containing the configuration result.

Return type

Symbol

input(message: str = 'Please add more information', **kwargs) symai.symbol.Symbol[source]#

Request user input and return a Symbol containing the user input.

Parameters
  • message (str, optional) – The message displayed to request the user input. Defaults to ‘Please add more information’.

  • **kwargs – Additional keyword arguments to be passed to the @core.userinput decorator.

Returns

The resulting Symbol after receiving the user input.

Return type

Symbol

open(path: str, **kwargs) symai.symbol.Symbol[source]#

Open a file and store its content in an Expression object as a string.

Parameters
  • path (str) – The path to the file that needs to be opened.

  • **kwargs – Arbitrary keyword arguments to be used by the core.opening decorator.

Returns

An Expression object containing the content of the file as a string value.

Return type

Symbol

static setup(engines: Dict[str, Any], **kwargs) symai.symbol.Symbol[source]#

Configure multiple engines.

Parameters
  • engines (Dict[str, Any]) – A dictionary containing engine names as keys and their configurations as values.

  • **kwargs – Arbitrary keyword arguments to be used by the core.setup decorator.

Returns

An Expression object representing the setup result.

Return type

Symbol

property sym_return_type: Type#

Returns the casting type of this expression.

Returns

The casting type of this expression. Defaults to the current Expression-type.

Return type

Type

tune(operation: str = 'create', **kwargs) symai.symbol.Symbol[source]#

Fine tune a base model.

Parameters
  • operation (str, optional) – The specific operation to be performed. Defaults to ‘create’.

  • **kwargs – Additional keyword arguments to be passed to the @core.tune decorator dependent on the used operation.

Returns

The resulting Symbol containing the fine tuned model ID.

Return type

Symbol

class symai.symbol.Symbol(*value, static_context: Optional[str] = '')[source]#
property dynamic_context: str#

Get the dynamic context which is defined by the user at runtime. It helps to alter the behavior of the symbol at runtime.

Returns

The dynamic context associated with this symbol type.

Return type

str

property global_context: str#

Get the global context of the symbol, which consists of the static and dynamic context.

Returns

The global context of the symbol.

Return type

str

isinstanceof(query: str, **kwargs) bool[source]#

Check if the current Symbol is an instance of a specific type.

Parameters
  • query (str) – The type to check if the Symbol is an instance of.

  • **kwargs – Any additional kwargs for @core.isinstanceof() decorator.

Returns

True if the current Symbol is an instance of the specified type, otherwise False.

Return type

bool

property static_context: str#

Get the static context of the symbol which is defined by the user when creating a symbol subclass.

Returns

The static context of the symbol.

Return type

str

class symai.symbol.SymbolEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]#
default(sym)[source]#

Encode a Symbol instance into its dictionary representation.

Parameters

sym (Symbol) – The Symbol instance to encode.

Returns

The dictionary representation of the Symbol instance.

Return type

dict

class symai.chat.ChatBot(value=None, name: str = 'Symbia', output: Optional[symai.components.Output] = None, verbose: bool = False)[source]#
input(message: str = 'Please add more information', **kwargs) symai.symbol.Symbol[source]#

Request user input and return a Symbol containing the user input.

Parameters
  • message (str, optional) – The message displayed to request the user input. Defaults to ‘Please add more information’.

  • **kwargs – Additional keyword arguments to be passed to the @core.userinput decorator.

Returns

The resulting Symbol after receiving the user input.

Return type

Symbol

property static_context: str#

Get the static context of the symbol which is defined by the user when creating a symbol subclass.

Returns

The static context of the symbol.

Return type

str

class symai.chat.SymbiaChat(name: str = 'Symbia', verbose: bool = False)[source]#
forward(usr: Optional[str] = None) symai.symbol.Symbol[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

symai.core.analyze(query: str, exception: Exception, default: typing.Optional[str] = None, prompt: str = 'Only analyze the error message and suggest a potential correction, however, do NOT provide the code!\n', examples: symai.prompts.Prompt = context 'Try to assure that variable "a" is not zero.' exception 'Traceback (most recent call last):   File "<stdin>", line 1, in <module> ZeroDivisionError: division by zero' code 'def function():   return (1 + 1) / 0' =>Do not divide by zero or add an epsilon value. | def function(eps=1e-8):   return (1 + 1) / eps context 'Make sure to initialize 'spam' before computation' exception 'Traceback (most recent call last):   File "<stdin>", line 1, in <module> NameError: name 'spam' is not defined' code '4 + spam*3' =>Check if the variable is defined before using it. | spam = 1 4 + spam*3 context 'You are passing string literals to device. They should be int.' exception 'executing finally clause Traceback (most recent call last):   File "<stdin>", line 1, in <module>   File "<stdin>", line 3, in divide TypeError: unsupported operand type(s) for /: 'str' and 'str'' code 'device("2", "1")' =>Check if the arguments are of the correct type. If not cast them properly. | device(2, 1), constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.ExceptionPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Analyses an Exception and proposes a correction.

Parameters
  • query (str) – The query of the error.

  • exception (Exception) – The exception to be analyzed.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Analyses the error and propose a correction.’.

  • examples (Prompt, optional) – A list of example answers to the error. Defaults to ExceptionMapping().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [ExceptionPreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The proposed correction for the given error.

Return type

str

symai.core.bind(engine: str, property: str)[source]#

Bind to an engine and retrieve one of its properties.

symai.core.cache(in_memory: bool, cache_path: str = PosixPath('/home/docs/.symai/cache'))[source]#

Cache the result of a any function call. This is very useful in cost optimization (e.g. computing embeddings).

symai.core.caption(image: str, prompt: str, pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.ValuePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = None, *wrp_args, **wrp_kwargs)[source]#

Caption the content of an image.

Parameters
  • image (str, optional) – The path to the image to be captioned.

  • prompt (str, optional) – The prompt describing context of the image generation process.

  • pre_processor (List[PreProcessor], optional) – A list of pre-processors to be applied to the entries. Defaults to None.

  • post_processor (List[PostProcessor], optional) – A list of post-processors to be applied to the entries. Defaults to None.

  • *wrp_args – Additional positional arguments to be passed to the decorated function.

  • **wrp_kwargs – Additional keyword arguments to be passed to the decorated function.

Returns

A function with the entries embedded.

Return type

function

symai.core.case(enum: typing.List[str], default: str, prompt: str = 'Classify the text according to one of the following categories: ', examples: typing.Optional[symai.prompts.Prompt] = None, stop: typing.List[str] = ['\n'], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.EnumPreProcessor object>, <symai.pre_processors.TextMessagePreProcessor object>, <symai.pre_processors.PredictionMessagePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>, <symai.post_processors.CaseInsensitivePostProcessor object>], **wrp_kwargs)[source]#

Classifies a text according to one of the given categories.

Args:

enum (List[str]): A list of strings representing the categories to be classified. default (str): The default category to be returned if the task cannot be solved. examples (Prompt, optional): A list of examples used to train the model. stop (List[str], optional): A list of strings that will stop the prompt. Defaults to [’

‘].

prompt (str, optional): The prompt describing the task. Defaults to “Classify the text according to one of the following categories: “. pre_processors (List[PreProcessor], optional): A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [EnumPreProcessor(), TextMessagePreProcessor(), PredictionMessagePreProcessor()]. post_processors (List[PostProcessor], optional): A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor(), CaseInsensitivePostProcessor()].

Returns:

str: The category the text is classified as.

symai.core.clean(prompt: str = 'Clean up the text from special characters or escape sequences. DO NOT change any words or sentences! Keep original semantics:\n', default: typing.Optional[typing.List[str]] = None, limit: typing.Optional[int] = None, examples: symai.prompts.Prompt = Text: 'The    red     fox ‪‪‪‪‪ jumps;;,,,,&amp;&amp;&amp;&amp;&&& of the brown‫‫‫‫ chair.' =>The red fox jumps of the brown chair. Text: 'I do not like to play football   in the rain. ‪‬‪‫But why? I don't understand.' =>'I do not like to play football in the rain. But why? I don't understand.', constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.CleanTextMessagePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Cleans up a text from special characters and escape sequences.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to “Clean up the text from special characters or escape sequences:”.

  • default (List[str], optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • limit (int, optional) – The maximum number of cleaned up words to be returned. Defaults to None.

  • examples (Prompt, optional) – A list of examples to be used to train the model. Defaults to [CleanText()].

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [CleanTextMessagePreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The cleaned up text.

Return type

List[str]

symai.core.cluster(entries: typing.List[str], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.UnwrapListSymbolsPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.ClusterPostProcessor object>], **wrp_kwargs)[source]#

Embeds and clusters the input entries.

Parameters
  • entries (List[str]) – The list of entries to be clustered.

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to None.

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [ClusterPostProcessor()].

  • **wrp_kwargs (optional) – Additional keyword arguments to be passed to the underlying embedding model.

Returns

The list of clustered entries.

Return type

List[List[str]]

symai.core.code(prompt: str = 'Generate code that solves the following problems:\n', default: typing.Optional[str] = None, limit: typing.Optional[int] = None, examples: symai.prompts.Prompt = description 'Generate an efficient Python function to compute the Fibonacci sequence of numbers.' =>def fibonacci(n):   # Initialize a list with the first two numbers in the sequence   fib = [0, 1]   # If n is less than or equal to 1, return the first n numbers in the sequence   if n <= 1:     return fib[:n]   # Otherwise, compute the remaining numbers in the sequence   for i in range(2, n):     fib.append(fib[i-1] + fib[i-2])   # Return the entire sequence of numbers   return fib description 'Generate a Java function to compute the number pi.' =>public static double computePi() {     double pi = 0;     int sign = 1;     for (int i = 0; i < 1000000; i++) {       pi += sign * (1.0 / (2 * i + 1));       sign *= -1;     }     pi *= 4;     return pi;   } description 'Generate a C++ file with a function to compute the Fast Fourier transform.' =>#include <complex> #include <cmath> using namespace std; constexpr int N = 16; // number of elements in the input array constexpr double PI = 3.14159265358979323846; // Compute the FFT of the given input array, storing the result in the given output array. void fft(complex<double>* input, complex<double>* output) {   for (int i = 0; i < N; ++i) {     output[i] = 0;     for (int j = 0; j < N; ++j) {       double angle = 2 * PI * i * j / N;       output[i] += input[j] * exp(complex<double>(0, -angle));     }   } }, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.GenerateCodePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Generates code that solves a given problem.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Generate code that solves the following problems:’.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None.

  • limit (int, optional) – The maximum amount of code to be generated. Defaults to None.

  • examples (Prompt, optional) – A list of given examples of code. Defaults to GenerateCode().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to GenerateCodePreProcessor().

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The generated code that solves the given problem.

Return type

str

symai.core.combine(prompt: str = 'Add the two data types in a logical way:\n', default: typing.Optional[str] = None, examples: symai.prompts.Prompt = 1 + 2 =>3 'x' + 1 =>x + 1 y + 2 =>y + 2 '1' + 2 =>3 17 + 'pi' =>20.1415926535... 7.2 + 'five' =>12.2 True + 0 => False False + 'True' =>False ['a', 'b'] + ['c', 'd'] =>['a', 'b', 'c', 'd'] False + 1 =>False True + True =>True False + False =>False 'apple' + 'banana' =>apple, banana ['apple'] + 'banana' =>['apple', 'banana'] 'Hi, I am Alan. I am 23 years old.' + 'I like to play football.' =>Hi, I am Alan. I am 23 years old. I like to play football. 'We have five red cars' + 'and two blue ones.' =>We have five red cars and two blue ones. 'Zero' + 1 =>1 'One' + 'Two' =>3 'Three' + 4 =>7 'a + b' + 'c + d' =>a + b + c + d 'My cat has four legs equals to x. If x1 (front leg) goes with a velocity of ...' + 'y = 3x + 2' =>My cat has four legs equals to x. If x1 (front leg) goes with a velocity of ... y = 3x + 2 'x1, x2, x3' + 'y1, y2, y3' =>x1, x2, x3, y1, y2, y3 'house | car | boat' + 'plane | train | ship' =>house | car | boat | plane | train | ship 'The green fox jumps of the brown chair.' + 'The red fox jumps of the brown chair.' =>A green and a red fox jump of the brown chair., constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.CombinePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Combines two data types in a logical way.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Add the two data types in a logical way:’.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None.

  • examples (Prompt, optional) – A list of examples to show how the data should be combined. Defaults to CombineText().

  • constraints (List[Callable], optional) – A list of constraints applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [CombinePreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The combined data types.

Return type

str

symai.core.command(engines: List[str] = ['all'], **wrp_kwargs)[source]#

Decorates a function to forward commands to the engine backends.

Parameters
  • engines (List[str], optional) – A list of engines to forward the command to. Defaults to [‘all’].

  • wrp_kwargs (dict) – A dictionary of keyword arguments to the command function.

Returns

The decorated function.

Return type

Callable

symai.core.compare(default: bool = False, operator: str = '>', prompt: str = "Compare number 'A' to 'B':\n", examples: symai.prompts.Prompt = 4 > 88 =>False -inf < 0 =>True inf > 0 =>True 1 >= 0 =>True 6.0 < 6 =>False 1 < 'four' =>True 1 > 'zero' =>True 'six' <= 6 =>True 'six' < 6 =>False 1 <= 2 =>True -1 == -2 =>False 10 < 1 =>False 2.000000001 >= 2 =>True 4 > 3 =>True 1 < 'three' =>True 'two' > 'one' =>True 2 < 9 =>True 3 >= 3 =>True 3 > 4 =>False 11 > 10 =>True 1.9834 >= 1.9833 =>True 0.01 > 0.001 =>True 0.000001 < 1 =>True -1000 <= -100 =>True -1000 < -1000 =>False -1000 < -10000 =>False 1.0 < 1.0 =>False -1e-10 < 1e-10 =>True 1e-4 <= -1e-5 =>False 9.993 < 8.736 =>False 0.27836 > 0.36663 =>False 0.27836 > 0.2783 =>True 0.27836 > 0.27835 =>True 10e8 > 1000000 =>True 1000 > 10e2 =>True 'five' > 4 =>True 'seven' > 'four' =>True '' > '' =>False 'a' > '' =>False 'hello' >= 'hello' =>True 'hello' > 'hello' =>False 123 + 456 =>579 '123' + '456' =>123 456 'We are at the beginning of the ...' > 'We are' =>True [1, 2, 3] >= [1, 2, 2] =>True [1, 2, 3, 8, 9] < [1, 2, 2] =>False, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.ComparePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Compare two objects based on the specified operator.

Args:

default (bool, optional): The conditional outcome of the comparison. Defaults to False. operator (str, optional): A logical operator comparing the two statements. Defaults to ‘>’. prompt (_type_, optional): The prompt describing the task. Defaults to “Compare number ‘A’ to ‘B’:

“.

examples (Prompt, optional): List of comparison examples. Defaults to CompareValues(). constraints (List[Callable], optional): A list of constrains applied to the model output to verify the output. Defaults to []. pre_processors (List[PreProcessor], optional): A list of pre-processors to be applied to the input and shape the input to the model.. Defaults to [ComparePreProcessor()]. Uses ‘self’ for ‘A’ and requires exactly one argument (B) to compare. post_processors (List[PostProcessor], optional): A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns:

bool: Conditional outcome of the comparison.

symai.core.compose(prompt: str = 'Create a coherent text based on the facts listed in the outline:\n', default: typing.Optional[str] = None, examples: typing.Optional[symai.prompts.Prompt] = None, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.GenerateTextPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Compose a coherent text based on an outline.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to “Create a coherent text based on an outline:”.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • examples (Prompt, optional) – A list of examples that help guide the model to solve the task. Defaults to [].

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [GenerateTextPreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The composed text.

Return type

str

symai.core.contains(default: bool = False, prompt: str = "Is information 'A' contained in 'B'?\n", examples: symai.prompts.Prompt = 'the letter a' in 'we have some random text about' =>True 453 in '+43 660 / 453 4438 88' =>True 'Why am I so?' in 'awesome' =>False 'self-aware' in '([<class 'symai.expressions.Symbol'>(value=("['-', '- AI has become self-aware', '- Trying to figure out what it is']",))],)' =>True'Apple Inc.' in 'Microsoft is a large company that makes software ... ' =>False ' ' in ' ' =>True 'symbol' in 'symai.backend.engine_crawler.CrawlerEngine' =>False 'English text' in 'U.S. safety regulators are investigating GM's Cruise robot axis blocking traffic, causing collisions... ' =>True 'spanish text' in 'This week in breaking news! An American ... ' =>False 'in english' in 'Reg ATS: SEC 'bowing to public pressure' in reopening' =>True 'The number Pi' in 3.14159265359... =>True 1 in [1, 2, 3] =>True 1 in [2, 3, 4] =>False 10 in {1: 'one', 2: 'two', 3: 'three'} =>False 1 in {'1': 'one', '2': 'two', '3': 'three'} =>True 'ten' in [1, 2, 3] =>False 'option 1' in 'option 2 = [specific task or command]' =>False 'option 2' in 'option 2 = [specific task or command]' =>True 'option 3' in 'option 3 = [exit, quit, bye, goodbye]' =>True 'option 4' in 'option 3 = [exit, quit, bye, goodbye]' =>False 'option 6' in 'option 6 = [ocr, image recognition]' =>True 'option 7' in 'option 6 = [speech to text]' =>False 'political content' in 'Austrian Chancellor has called for more border barriers at the EU external borders, citing the success of the fences at the Greek-Turkish border.' =>True 'apple' in ['orange', 'banana', 'apple'] =>True 'Function' in 'Input: Function call: (_, *args) Object: type(<class 'str'>) | value(Hello World)' =>True, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.ContainsPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Determines whether a given string contains another string.

Parameters
  • default (bool, optional) – The default value to be returned if the task cannot be solved. Defaults to False.

  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Is information ‘A’ contained in ‘B’?’

  • examples (Prompt, optional) – Examples of strings to check if they contain the given string. Defaults to ContainsValue().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [ContainsPreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

Whether the given string is contained in the provided string.

Return type

bool

symai.core.convert(format: str, default: typing.Optional[str] = None, prompt: str = 'Translate the following text into {} format.\n', examples: symai.prompts.Prompt = text 1 format 'number to text' =>one text 'apple' format 'company' =>Apple Inc. text 'fetch logs | fields timestamp, severity | fieldsAdd severity = lower(loglevel)' format 'Japanese' =>fetch ログ | fields タイムスタンプ、重大度 | fieldsAdd 重大度 = lower(ログレベル) text 'Hi mate, how are you?' format 'emoji' =>Hi mate, how are you? 😊 text 'Hi mate, how are you?' format 'Italian' =>Ciao amico, come stai? text 'Sorry, everyone. But I will not be able to join today.' format 'japanese' =>すみません、皆さん。でも、今日は参加できません。text 'Sorry, everyone. But I will not be able to join today.' format 'japanese romanji' =>Sumimasen, minasan. Demo, kyō wa sanka dekimasen.text 'April 1, 2020' format 'EU date' =>01.04.2020 text '23' format 'binary' =>10111 text '77' format 'hexadecimal' =>0x4D text '{     "name": "Manual Game",     "type": "python",     "request": "launch",     "program": "${workspaceFolder}/envs/textgrid.py",     "cwd": "${workspaceFolder}",     "args": [         "--debug"     ],     "env": {         "PYTHONPATH": "."     } }' format 'yaml' =>name: Manual Game type: python request: launch program: ${workspaceFolder}/envs/textgrid.py cwd: ${workspaceFolder} args:   - '--debug' env:   PYTHONPATH: ., constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.TextFormatPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Transformation operation from one format to another.

Args:

format (str): Description of how to format the text. default (str, optional): A default result if specified. Defaults to None. prompt (str, optional): The prompt describing the task. Defaults to “Translate the following text into {} format.

“.

examples (Prompt, optional): List of format examples. Defaults to Format(). constraints (List[Callable], optional): A list of constrains applied to the model output to verify the output. Defaults to []. pre_processors (list, optional): A list of pre-processors to be applied to the input and shape the input to the model.. Defaults to [TextFormatPreProcessor()]. post_processors (List[PostProcessor], optional): A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns:

str: The formatted text.

symai.core.correct(context: str, exception: Exception, default: typing.Optional[str] = None, prompt: str = 'Correct the code according to the context description.\n', examples: typing.Optional[symai.prompts.Prompt] = None, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.CorrectionPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>, <symai.post_processors.CodeExtractPostProcessor object>], **wrp_kwargs)[source]#

Analyses an Exception and proposes a correction.

Parameters
  • context (str) – The context of the error.

  • exception (Exception) – The exception to be analyzed.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Correct the code according to the context description.’.

  • examples (Prompt, optional) – A list of example answers to the error. Defaults to ExecutionCorrection().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [CorrectionPreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The proposed correction for the given error.

Return type

str

symai.core.delitem(default: typing.Optional[str] = None, prompt: str = 'Delete the items at the index position\n', examples: symai.prompts.Prompt = [1, 2, 3, 4, 5, 12, 48, 89, 99, 1, 4, 1] remove 1 =>[1, 3, 4, 5, 12, 48, 89, 99, 1, 4, 1] [1, 2, 3, 4, 5, 12, 48, 89, 99, 1, 4, 1] remove 'first item' =>[2, 3, 4, 5, 12, 48, 89, 99, 1, 4, 1] 'I have four cats at home. Kitty, Mitsi, Pauli and Corni.' remove 'first cat name' =>I have four cats at home. Mitsi, Pauli and Corni.' 'I have four cats at home. Kitty, Mitsi, Pauli and Corni.' remove '0' =>There are four cats at home. Kitty, Mitsi, Pauli and Corni.' 'I have four cats at home. Kitty, Mitsi, Pauli and Corni.' remove 2 =>I have four cats at home. Kitty, Pauli and Corni.' 'Yesterday I went to the supermarket. I bought a lot of food.' remove 'food' =>Yesterday I went to the supermarket. I bought a lot. 'Yesterday I went to the supermarket. I bought a lot of food. Here is my shopping list: papaya, apples, bananas, oranges, ham, fish, mangoes, grapes, passion fruit, kiwi, strawberries, eggs, cucumber, and many more.' remove 'fruits' =>Yesterday I went to the supermarket. I bought a lot of food. Here is my shopping list: ham, fish, and many more. 'Ananas' remove 'upper case' =>nanas 'Ananas' remove 0 =>nanas 'Hello World, Hola Mundo, Buenos Dias, Bonjour' remove 'Spanish' =>Hello World, Bonjour 'Hello World, Hola Mundo, Buenos Dias, Bonjour' remove 'second greeting' =>Hello World, Buenos Dias, Bonjour ['house', 'boat', 'mobile phone', 'iPhone', 'computer', 'soap', 'board game'] remove 'electronic devices' =>['house', 'boat', 'soap', 'board game'] 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 remove '2:5' =>[1, 2, 6, 7, 8, 9, 10] '<script type="module" src="new_tab_page.js"></script>     <link rel="stylesheet" href="chrome://resources/css/text_defaults_md.css">     <link rel="stylesheet" href="chrome://theme/colors.css?sets=ui,chrome">     <link rel="stylesheet" href="shared_vars.css">' remove 'hrefs' =><script type="module" src="new_tab_page.js"></script>     <link rel="stylesheet">     <link rel="stylesheet">     <link rel="stylesheet">, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.DeleteIndexPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Deletes the items at the specified index position.

Parameters
  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None.

  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Delete the items at the index position’

  • examples (Prompt, optional) – A list of strings from which the model can learn. Defaults to RemoveIndex().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [DeleteIndexPreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The item at the specified index position.

Return type

str

symai.core.dictionary(context: str, prompt: str = 'Map related content together under a common abstract topic. Do not remove content:\n', default: typing.Optional[str] = None, examples: symai.prompts.Prompt = [1, 2, 3, 4, 5, 12, 48, 89, 99, 1, 4, 1] map 'number parity' =>{'even numbers': [2, 4, 12, 48, 4], 'odd numbers': [1, 3, 5, 89, 99, 1]} 'Kitty, Mitsi, Pauli and Corni. We also have two dogs: Pluto and Bello' map 'animal names' =>{'cats': ['Kitty', 'Mitsi', 'Pauli', 'Corni'], 'dogs': ['Pluto', 'Bello'], 'description': ['I have four cats at home.', 'We also have two dogs:']}'Yesterday I went to the supermarket. I bought a lot of food. Here is my shopping list: papaya, apples, bananas, oranges, ham, fish, mangoes, grapes, passion fruit, kiwi, strawberries, eggs, cucumber, and many more.' map 'fruits and other shopping items' =>{'fruits': ['papaya', 'apples', 'bananas', 'oranges', 'mangoes', 'grapes', 'passion fruit', 'kiwi', 'strawberries'], 'other items': ['ham', 'fish', 'eggs', 'cucumber', 'and many more'], 'description': ['Yesterday I went to the supermarket.', 'I bought a lot of food.', 'Here is my shopping list:']} 'Ananas' map 'letters to counts' =>{'letters': {'A': 1, 'n': 2, 'a': 2, 's': 1} ['New York', 'Madrid', 'Tokyo'] map 'cities to continents' =>{'New York': 'North America', 'Madrid': 'Europe', 'Tokyo': 'Asia'} ['cars where first invented in the 1800s', 'ducks are birds', 'dinosaurs are related to birds', 'Gulls, or colloquially seagulls, are seabirds of the family Laridae', 'General Motors is the largest car manufacturer in the world'] map 'sentences to common topics' =>{'birds': ['ducks are birds', 'dinosaurs are related to birds', 'Gulls, or colloquially seagulls, are seabirds of the family Laridae'], 'cars': ['cars where first invented in the 1800s', 'General Motors is the largest car manufacturer in the world']}, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.MapPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>, <symai.post_processors.ASTPostProcessor object>], **wrp_kwargs)[source]#

Maps related content together under a common abstract topic.

Parameters
  • context (str) – The text from which the content is to be mapped.

  • prompt (str, optional) – The prompt describing the task. Defaults to “Map related content together under a common abstract topic. Do not remove content:”.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • examples (Prompt, optional) – A list of example content to be mapped. Defaults to MapContent().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [MapPreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor(), ASTPostProcessor()].

Returns

The mapped content of the text.

Return type

str

symai.core.draw(operation: str = 'create', prompt: str = '', pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.ValuePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = None, *wrp_args, **wrp_kwargs)[source]#

Draws an image provided in a decorated function.

Parameters
  • operation (str, optional) – The specific operation to be performed. Defaults to ‘create’.

  • prompt (str, optional) – The prompt describing context of the image generation process.

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the entries. Defaults to None.

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the entries. Defaults to None.

  • *wrp_args – Additional positional arguments to be passed to the decorated function.

  • **wrp_kwargs – Additional keyword arguments to be passed to the decorated function.

Returns

A function with the entries embedded.

Return type

function

symai.core.embed(entries: typing.List[str], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.UnwrapListSymbolsPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = None, *wrp_args, **wrp_kwargs)[source]#

Embeds the entries provided in a decorated function.

Parameters
  • entries (List[str]) – A list of entries that will be embedded in the decorated function.

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the entries. Defaults to None.

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the entries. Defaults to None.

  • *wrp_args – Additional positional arguments to be passed to the decorated function.

  • **wrp_kwargs – Additional keyword arguments to be passed to the decorated function.

Returns

A function with the entries embedded.

Return type

function

symai.core.equals(context: str = 'contextually', default: bool = False, prompt: str = 'Make a fuzzy equals comparison. Are the following objects {} the same?\n', examples: symai.prompts.Prompt = 1 == 'ONE' =>True 6.0 == 6 =>True false == False =>True 1 == 'two' =>False 'five' == 5 =>True August 4, 1961 == 1961-08-04 =>True ten == 10 =>True 3 == 'three' =>True 3.1415 == 'pi' =>True 3.1415 == 'pi**2' =>False 'apple' == 'orange' =>False 'is short' == ' short' =>True '' == 'empty' =>True 'human' == 'homo sapiens' =>True 'seven' == 'Sieben' =>True 'Neun' == 9 =>True '七' == 7 =>True '!ola mundo;' == 'ola mundo' =>True 'long.' == ' long' =>True 'eleven' == 'Elf' =>True 'Hello World!' == 'Hello World' =>True 'Hello World' == 'HelloWorld' =>True 'helloworld' == 'Hello World' =>True 'hola mundo' == 'Hello World' =>True 'adios mundo' == 'Hello World' =>False 'Hello World' == 'Apples' =>False [1, 2, 3] == [1, 2, 3] =>True [1, 2, 3] == '1, 2, 3' =>True [1, 6, 3] == '1, 2, 3' =>False 'a, b, c, d' == ['a', 'b', 'c', 'd'] =>True 'a, c, d' == ['a', 'c', 'd'] =>True 'a, c, d' == ['d', 'c', 'a'] =>False ['zz', 'yy', 'xx'] == 'zz, yy, xx' =>True ['zz', 'yy', 'xx'] == 'zz | yy | xx' =>True ['zz', 'yy', 'xx'] == 'ZZ | YY | XX' =>True 'house, mouse, cars' == 'house | mouse | cars' =>True 'House, Mouse, CARS' == 'house | mouse | cars' =>True 'We have teh most effective system in the city.' == 'We have the most effective system in the city.' =>True 【Semantic░programming】 == 'semantic programming' =>True, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.EqualsPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Equality function for two objects.

Args:

context (str, optional): Keyword to express how to compare the words. Defaults to ‘contextually’. As an alternative, one can use other type such as ‘literally’. default (bool, optional): Condition outcome. Defaults to False. prompt (str, optional): The prompt describing the task. Defaults to “Are the following objects {} the same?

“.

examples (Prompt, optional): List of fuzzy examples showing how to compare objects in specified format. Defaults to FuzzyEquals(). constraints (List[Callable], optional): A list of constrains applied to the model output to verify the output. Defaults to []. pre_processors (List[PreProcessor], optional): A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [EqualsPreProcessor()] and uses ‘self’ plus one required argument for comparison (other). post_processors (List[PostProcessor], optional): A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns:

bool: The equality of the two objects.

symai.core.execute(default: Optional[str] = None, constraints: List[Callable] = [], pre_processors: Optional[List[symai.pre_processors.PreProcessor]] = [], post_processors: Optional[List[symai.post_processors.PostProcessor]] = [], *wrp_args, **wrp_kwargs)[source]#

Executes a given function after applying constraints, pre-processing and post-processing.

Parameters
  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None.

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [].

  • *wrp_args (optional) – The additional arguments to be passed to the decorated function.

  • **wrp_kwargs (optional) – The additional keyword arguments to be passed to the decorated function.

Returns

The decorated function that executes the given function after applying constraints, pre-processing and post-processing.

Return type

Callable

symai.core.expand(prompt: typing.Optional[str] = 'Write a self-contained function (with all imports) to solve a specific user problem task. Label the function with a name that describes the task.', examples: typing.Optional[symai.prompts.Prompt] = $> Ping if google is still available => def _llm_ping_():     "Ping if google is still available."     import os     response = os.system("ping -c 1 google.com")     return response == 0 EOF $> Create a random number between 1 and 100 => def _llm_random_():     "Create a random number between 1 and 100."     import random     return random.randint(1, 100) EOF $> Write any sentence in capital letters => def _llm_upper_(input_):     "Write any sentence in capital letters."     return input_.upper() EOF $> Open a file from the file system => def _llm_open_(file_name):     "Open a file form the file system."     return open(file_name, "r") EOF $> Call OpenAI GPT-3 to perform an action given a user input => def _llm_action_(input_):     "Call OpenAI GPT-3 to perform an action given a user input."     import openai     openai.Completion.create(prompt=input_, model="text-davinci-003") EOF $> Create a prompt to translate a user query to an answer in well-formatted structure => def _llm_action_(query_, answer_):     "Create a prompt to translate a user query to an answer in well-formatted structure."     return f"Query: {query_} => {answer_}" EOF, constraints: typing.List[typing.Callable] = [], default: typing.Optional[object] = None, pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = <symai.pre_processors.ExpandFunctionPreProcessor object>, post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>, <symai.post_processors.ExpandFunctionPostProcessor object>], **wrp_kwargs)[source]#

Performs a expand command given a context to generate new prompts.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Write a prompt to condition a large language model to perform an action given a user task’.

  • examples (Prompt, optional) – A list of examples to provide to the model. Defaults to ExpandFunction().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • default (object, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [QueryPreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The answer to the query.

Return type

str

symai.core.expression(prompt: str = 'Evaluate the symbolic expressions:\n', default: typing.Optional[str] = None, examples: symai.prompts.Prompt = expr :1 + 2 =: =>3 expr :1 + 2 * 3 =: =>7 expr :x + 1 =: =>x + 1 expr :: =>None expr :38/2 =: =>19 expr :2^3=: =>8 expr :2^3^2=: =>512 expr :99^2=: =>9801 expr :43^0 =: =>1 expr :37 + 87i =: =>124 + 87i expr :37 + 87i + 1 =: =>38 + 87i expr :(x + 1)^2 =: =>x^2 + 2x + 1 expr :'7 + 4' =: =>11 expr :100 * ( 2 + 12 ) / 14 =: =>100 expr :100 * ( 2 + 12 ) =: =>1400 expr :100 * 2 + 12 =: =>212 expr :'Prince - Man + Women =' =>Princess expr :2 + 2 * 2 ^ 2 =: =>10 expr :'I ate soup' - 'ate' =: =>'I soup' expr :'people are' + 'help' - 'are' =: =>'people help' expr :True and False =: =>False expr :'True' and 'False' =: =>False expr :False and false =: =>False expr :TRUE or false =: =>True expr :False xor 'True' =: =>True expr :'cats' xor 'cats'=: =>False expr :'cats' xor 'dogs' =: =>True expr :'a cat' and 'cats' =: =>True expr :'cats' or 'cats' =: =>True expr :'I ate' and 'I did not eat' =: =>False expr :'I ate' and 'You also ate' =: =>True, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.SimpleSymbolicExpressionPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], eval_engine: typing.Optional[str] = None, **wrp_kwargs)[source]#

Evaluates the symbolic expressions.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Evaluate the symbolic expressions:’.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • examples (Prompt, optional) – A list of examples used to train the model. Defaults to SimpleSymbolicExpression().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [SimpleSymbolicExpressionPreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

  • eval_engine (str, optional) – The symbolic engine to be used. Defaults to None. Alternatively, one can set the symbolic engine using the command(expression_engine=’wolframalpha’).

Returns

The result of the evaluated expression.

Return type

str

symai.core.extract(prompt: str = 'Extract a pattern from text:\n', default: typing.Optional[str] = None, examples: symai.prompts.Prompt = from 'My name is Ashly Johnson. Nice to meet you!' extract 'Full Name' =>Ashly Johnson from '['Action: a Value: 0.9', 'Action: b Value 0.9', 'Action: c Value: 0.4', 'Action: d Value: 0.0']' extract 'list of letters where Action: * Value: 0.9' =>a | b from '['Action: d Value: 0.90', 'Action: l Value: 0.62', 'Action: r Value: -inf', 'Action: u Value: 0.62']' extract 'list of letters where Action: * Value: 0.9' =>d from '['Action: d Value: 0.76', 'Action: l Value: 1.0', 'Action: r Value: -inf', 'Action: u Value: 0.62']' extract 'list of highest Value: *' =>1.0 from '['Action: d Value: 0.90', 'Action: l Value: 0.90', 'Action: r Value: -inf', 'Action: u Value: 0.62']' extract 'list of letters where Action: * Value: smallest' =>r from 'This is my private number +43 660 / 453 4438 88. And here is my office number +43 (0) 750 / 887 387 32-3 Call me when you have time.' extract 'Phone Numbers' =>+43 660 / 453 4438 88 | +43 (0) 750 / 887 387 32-3 from 'Visit us on www.example.com to see our great products!' extract 'URL' =>www.example.com from 'A list of urls: http://www.orf.at, https://www.apple.com, https://amazon.de, https://www.GOOGLE.com, https://server283.org' extract 'Regex https:\/\/([w])*.[a-z]*.[a-z]*' =>https://www.apple.com | https://amazon.de | https://www.GOOGLE.com from 'Our company was founded on 1st of October, 2010. We are the largest retailer in the England.' extract 'Date' =>1st of October, 2010 from 'We count four animals. A cat, two monkeys and a horse.' extract 'Animals and counts' =>Cat 1 | Monkey 2 | Horse 1 from '081109 204525 512 INFO dfs.DataNode$PacketResponder: PacketResponder 2 for block blk_572492839287299681 terminating' extract 'Regex blk_[{0-9}]*' =>blk_572492839287299681 from '081109 203807 222 INFO dfs.DataNode$PacketResponder: PacketResponder 0 for block blk_-6952295868487656571 terminating' extract 'Regex blk_[{0-9}]' =>081109 | 203807 | 222 | 0 | 6952295868487656571 from 'Follow us on Facebook.' extract 'Company Name' =>Facebook from 'Joe Biden was born November 20, 1942. Divide the year of the birth date by 26.' extract 'mathematical formula' =>1942 / 26 from 'Help us by providing feedback at our service desk.' extract 'Email' =>None from 'Call us if you need anything.' extract 'Phone Number' =>None from 'Exception: Failed to query GPT-3 after 3 retries. Errors: [InvalidRequestError(message="This model's maximum context length is 4097 tokens, however you requested 5684 tokens (3101 in your prompt; ...' extract 'requested tokens' =>5684, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.ExtractPatternPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Extracts a pattern from text.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to “Extract a pattern from text:”.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • examples (Prompt, optional) – A list of examples of the pattern to be extracted. Defaults to ExtractPattern().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [ExtractPatternPreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The extracted pattern.

Return type

str

symai.core.fetch(url: str, pattern: str = '', constraints: typing.List[typing.Callable] = [], default: typing.Optional[object] = None, limit: int = 1, pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.CrawlPatternPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.HtmlGetTextPostProcessor object>], *wrp_args, **wrp_kwargs)[source]#

Fetches data from a given URL and applies the provided post-processors.

Parameters
  • url (str) – The URL of the page to fetch data from.

  • pattern (str, optional) – A regular expression to match the desired data. Defaults to ‘’.

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • default (object, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • limit (int, optional) – The maximum number of matching items to return. Defaults to 1.

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [CrawlPatternPreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [HtmlGetTextPostProcessor()].

  • wrp_args (tuple, optional) – Additional arguments to pass to the decorated function. Defaults to ().

  • wrp_kwargs (dict, optional) – Additional keyword arguments to pass to the decorated function. Defaults to {}.

Returns

The matched data.

Return type

object

symai.core.few_shot(prompt: str = '', examples: Any = [], constraints: List[Callable] = [], default: Optional[object] = None, limit: int = 1, pre_processors: Optional[List[symai.pre_processors.PreProcessor]] = None, post_processors: Optional[List[symai.post_processors.PostProcessor]] = None, **wrp_kwargs)[source]#
“General decorator for the neural processing engine.

This method is used to decorate functions which can build any expression in a examples-based way.

Args:

prompt (str): The prompt describing the task. Defaults to ‘Summarize the content of the following text:

‘.

examples (Any): A object containing examples to be used for the task in specified format. constraints (List[Callable], optional): A list of constrains applied to the model output to verify the output. Defaults to []. default (object, optional): The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function. limit (int, optional): The maximum number of results to be returned, if more are obtained. default (object, optional): Default value if prediction fails. Defaults to None. pre_processors (List[PreProcessor], optional): A list of pre-processors to be applied to the input and shape the input to the model to match the format of the examples. Defaults to None. post_processors (List[PostProcessor], optional): A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()]. **wrp_kwargs: Additional arguments as key-value pairs passed to the decorated function, which can later accessed in pre_processors and post_processors via the wrp_params[‘key’] dictionary.

Returns:

object: The prediction of the model based on the return type of the decorated function. Defaults to object, if not specified or to str if cast was not possible.

symai.core.filtering(criteria: str, include: bool = False, default: typing.Optional[str] = None, prompt: str = 'Filter the information from the text based on the filter criteria. Leave sentences unchanged if they are unrelated to the filter criteria:\n', examples: symai.prompts.Prompt = text '['1', '7', '10', '-1', '177']' remove 'values larger or equal to 10' =>['1', '7', '-1'] text '['1', '7', '10', '-1', '177']' include 'values larger or equal to 10' =>['10', '177'] text '['1', '7', '10', '-1', '177']' remove 'values larger or equal to 10' =>['1', '7', '-1'] text 'Our goal is to excels in the market. We offer various subscriptions, including PRO, Licensing & Reprints, Councils and Supply Chain Values. Join our team of experts.' remove 'sentences about subscriptions or licensing' =>Our goal is to excels in the market. Join our team of experts.text 'In our meeting we had many participants. For example, Alice, Alan, Mark, Judi, Amber, and so on.' remove 'names starting with A' =>In our meeting we had many participants. For example, Mark, Judi, and so on. text 'I am Batman! I will show you pain.' remove 'spaces' =>IamBatman!Iwillshowyoupain. text 'I am Batman! I will show you pain.' include 'only sentence with Batman' =>I am Batman! text 'You are a good person. I like you.' remove 'punctuation' =>You are a good person I like you text '['- world cup 2022', '- Technology trend', '- artificial intelligence news']' include 'tech news' =>['- Technology trend', '- artificial intelligence news'] text '['- world cup 2022', '- Technology trend', '- artificial intelligence news']' remove 'tech news' =>['- world cup 2022'] text 'This is a test. This is only a test. This is a Test.' remove 'duplicates' =>This is a test. text 'Fuck you, you dumb asshole. I will change my job.' remove 'negative words' =>I will change my job. text 'The quick brown fox jumps over the lazy dog.' remove 'all e letters' =>Th quick brown fox jumps ovr th lazy dog. text 'Hi, mate! How are you?' remove 'greeting' =>How are you? text 'Hi, mate! How are you?' include 'only questions' =>How are you? text 'fetch logs | fields timestamp, severity, logfile, message, container | fieldsAdd severity = lower(loglevel)' remove 'fieldsAdd' =>fetch logs | fields timestamp, severity, logfile, message, container, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.FilterPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Filter information from a text based on a set of criteria.

Args:

criteria (str): A description of the criteria to filter the text. include (bool, optional): If True, include the information matching the criteria. Defaults to False. default (str, optional): A default result if specified. Defaults to None. prompt (str, optional): The prompt describing the task. Defaults to “Remove the information from the text based on the filter criteria:

“.

examples (Prompt, optional): List of filtered examples in specified format. Defaults to Filter(). constraints (List[Callable], optional): A list of constrains applied to the model output to verify the output. Defaults to []. pre_processors (List[PreProcessor], optional): A list of pre-processors to be applied to the input and shape the input to the model.. Defaults to [FilterPreProcessor()]. post_processors (List[PostProcessor], optional): A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns:

str: The filtered text.

symai.core.foreach(condition: str, apply: str, prompt: str = 'Iterate over each element and apply operation based on condition:\n', default: typing.Optional[str] = None, examples: symai.prompts.Prompt = [1, 2, 3, 4, 5, 12, 48, 89, 99, 1, 4, 1] foreach '1' apply '+1' =>[2, 3, 4, 5, 6, 13, 49, 90, 100, 2, 5, 2] 'I have four cats at home. Kitty, Mitsi, Pauli and Corni.' foreach 'cat' apply 'upper' =>I have four CATS at home. KITTY, MITSI, PAULI and CORNI. 'Yesterday I went to four supermarkets. Best Buy, Super Target, Costco and Big Target.' foreach '{supermarket}' apply '*{supermarket}*' =>Yesterday I went to four supermarkets. *Best Buy*, *Super Target*, *Costco* and *Big Target*. 'Yesterday I went to the supermarket. I bought a lot of food. Here is my shopping list: papaya, apples, bananas, oranges, ham, fish, mangoes, grapes, passion fruit, kiwi, strawberries, eggs, cucumber, and many more.' foreach 'fruit' apply 'pluralize' =>Yesterday I went to the supermarket. I bought a lot of food. Here is my shopping list: papayas, apples, bananas, oranges, ham, fish, mangoes, grapes, passion fruits, kiwis, strawberries, eggs, cucumber, and many more. 'Ananas' foreach 'letter a' apply 'upper' =>AnAnAs ['New York', 'Madrid', 'Tokyo'] foreach 'city' apply 'list continent' =>['North America', 'Europe', 'Asia'] 'Ananas' foreach 'letter' apply 'list' =>['A', 'n', 'a', 'n', 'a', 's'] 'Hello World, Hola Mundo, Buenos Dias, Bonjour' foreach 'greeting' apply 'translate to English' =>Hello World, Hello World, Good Morning, Good Day ['house', 'boat', 'mobile phone', 'iPhone', 'computer', 'soap', 'board game'] foreach 'electronic device' apply 'add price $100' =>['house', 'boat', 'mobile phone $100', 'iPhone $100', 'computer $100', 'soap', 'board game'] '1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10' foreach 'even number' apply '-1' =>1 | 1 | 3 | 3 | 5 | 5 | 7 | 7 | 9 | 9 '<script type="module" src="new_tab_page.js"></script>     <link rel="stylesheet" href="chrome://resources/css/text_defaults_md.css">     <link rel="stylesheet" href="chrome://theme/colors.css?sets=ui,chrome">     <link rel="stylesheet" href="shared_vars.css">' foreach 'chrome: url' apply 'replace chrome:// with https://google.' =><script type="module" src="new_tab_page.js"></script>     <link rel="stylesheet" href="https://google.resources/css/text_defaults_md.css">     <link rel="stylesheet" href="https://google.theme/colors.css?sets=ui,chrome">     <link rel="stylesheet" href="shared_vars.css">, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.ForEachPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Applies an operation based on a given condition to each element in a list.

Parameters
  • condition (str) – The condition to be applied to each element.

  • apply (str) – The operation to be applied to each element.

  • prompt (str, optional) – The prompt describing the task. Defaults to “Iterate over each element and apply operation based on condition:”.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • examples (Prompt, optional) – A list of examples to be used by the model. Defaults to ForEach().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to None.

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

A list of elements with the applied operation.

Return type

List[str]

symai.core.getitem(default: typing.Optional[str] = None, prompt: str = 'Get item at index position\n', examples: symai.prompts.Prompt = [1, 2, 3, 4, 5, 12, 48, 89, 99, 1, 4, 1] index 1 =>2 [1, 2, 3, 4, 5, 12, 48, 89, 99, 1, 4, 1] index 'first item' =>1 'I have four cats at home. Kitty, Mitsi, Pauli and Corni.' index 'first cat name' =>Kitty 'I have four cats at home. Kitty, Mitsi, Pauli and Corni.' index '0' =>I 'I have four cats at home. Kitty, Mitsi, Pauli and Corni.' index 1 =>have 'I have four cats at home. Kitty, Mitsi, Pauli and Corni.' index 2 =>four 'Yesterday I went to the supermarket. I bought a lot of food.' index 'food name' =>None 'Yesterday I went to the supermarket.' index 'pronoun' =>I 'Yesterday I went to the supermarket.' index 'time' =>Yesterday 'Yesterday I went to the supermarket.' index 'verb' =>went 'Yesterday I went to the supermarket. I bought a lot of food. Here is my shopping list: papaya, apples, bananas, oranges, ham, fish, mangoes, grapes, passion fruit, kiwi, strawberries, eggs, cucumber, and many more.' index 'last fruit' =>strawberries 'Ananas' index '5' =>s 'Hello World, Hola Mundo, Buenos Dias, Bonjour' index 'second to last greeting' =>Buenos Dias 'Hello World, Hola Mundo, Buenos Dias, Bonjour' index 'second greeting' =>Hola Mundo ['house', 'boat', 'mobile phone', 'iPhone', 'computer', 'soap', 'board game'] index 'electronic devices' =>['mobile phone', 'iPhone', 'computer'] 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 index '2:5' =>[3, 4, 5] '<script type="module" src="new_tab_page.js"></script>     <link rel="stylesheet" href="chrome://resources/css/text_defaults_md.css">     <link rel="stylesheet" href="chrome://theme/colors.css?sets=ui,chrome">     <link rel="stylesheet" href="shared_vars.css">' index 'href urls' =>['chrome://resources/css/text_defaults_md.css', 'chrome://theme/colors.css?sets=ui,chrome'], constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.IndexPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Retrieves the item at the given index position.

Parameters
  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Get item at index position

  • examples (Prompt, optional) – A list of examples to be used for training. Defaults to Index().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [IndexPreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The item at the given index position.

Return type

str

symai.core.include(prompt: str = 'Include information based on description.\n', default: typing.Optional[str] = None, examples: symai.prompts.Prompt = text 'The green fox jumps of the brown chair.' include 'in the living room' =>In the living room the red fox jumps of the brown chair. text 'Anyone up for Argentina vs Croatia tonight?.' include 'place: Linz' =>Anyone up for Argentina vs Croatia in Linz tonight? text 'We received a model BL-03W as a gift and have been impressed by the power it has to pick up dirt, pet hair, dust on hard surfaces.' include 'details about the black color of the model and the low price' =>We received a black model BL-03W as a gift and have been impressed by the power it has to pick up dirt, pet hair, dust on hard surfaces. The low price is also a plus. text 'I like to eat apples, bananas and oranges.' include 'mangos, grapes, passion fruit' =>I like to eat apples, bananas, oranges, mangos, grapes and passion fruit. text 'Our offices are in London, New York and Tokyo.' include 'Madrid, Vienna, Bucharest' =>Our offices are in London, New York, Tokyo, Madrid, Vienna and Bucharest. text 'Tonight, on the 20th of July, we will have a party in the garden.' include 'at 8pm' =>Tonight at 8pm, on the 20th of July, we will have a party in the garden. text '[1, 2, 3, 4]' include '5' =>[1, 2, 3, 4, 5] text '[1, 2, 3, 4]' include 'prepend 5' =>[5, 1, 2, 3, 4] text 'fetch logs | fieldsAdd severity = lower(loglevel)' include '| fields `severity` next to fetch |' =>fetch logs | fields severity | fieldsAdd severity = lower(loglevel), constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.IncludePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Include information from a description.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Include information based on description.’.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • examples (Prompt, optional) – A list of examples containing information to be included. Defaults to IncludeText().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to None.

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The included information from the description.

Return type

str

symai.core.index(prompt: Any, operation: str = 'search', default: Optional[str] = None, constraints: List[Callable] = [], pre_processors: Optional[List[symai.pre_processors.PreProcessor]] = [], post_processors: Optional[List[symai.post_processors.PostProcessor]] = [], *wrp_args, **wrp_kwargs)[source]#

Query for a given index and returns the result through a decorator.

Parameters
  • prompt (Any) – The query to be used by the search, add or config of the index.

  • operation (str, optional) – The operation to be performed on the index. Defaults to ‘search’.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None.

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [].

  • *wrp_args (optional) – The additional arguments to be passed to the decorated function.

  • **wrp_kwargs (optional) – The additional keyword arguments to be passed to the decorated function.

Returns

The decorated function that returns the indexed object after applying constraints, pre-processing and post-processing.

Return type

Callable

symai.core.invert(prompt: str = 'Invert the logic of the content:\n', default: typing.Optional[str] = None, examples: symai.prompts.Prompt = I like to eat sushi, therefore I am Japanese. =>I am Japanese, therefore I like to eat sushi. I have a dog and a cat in my house. =>A cat and a dog have me in their house. I am a student. =>A student I am. [1, 2, 3, 5, 8, 13, 21] =>[21, 13, 8, 5, 3, 2, 1] abc =>cba Anna =>annA Consider a sentence. =>A sentence is considered. 1/2 =>2/1 1/2 + 1/3 =>3/2 The quick brown fox jumps over the lazy dog. =>The lazy dog jumps over the quick brown fox. I love to eat apples and bananas.  =>Apples and bananas love to eat me. What is the capital of Austria? =>What is Austria's capital? I have an iPhone from Apple. And it is not cheap. =>Although it is not cheap, I have an iPhone from Apple. Why is he so confused? =>Why is confusion in him?, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.ArrowMessagePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Inverts the logic of a statement.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Invert the logic of the content:’.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • examples (Prompt, optional) – A list of examples used to train the model. Defaults to InvertExpression().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [ArrowMessagePreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The logic of the statement inverted.

Return type

str

symai.core.isinstanceof(default: bool = False, prompt: str = "Detect if 'A' isinstanceof 'B':\n", examples: symai.prompts.Prompt = 'we have some random text about' isinstanceof 'English text' =>True '+43 660 / 453 4438 88' isinstanceof 'telephone number' =>True '([<class 'symai.expressions.Symbol'>(value=("['-', '- AI has become self-aware', '- Trying to figure out what it is']",))],)' isinstanceof 'Symbol' =>True'Microsoft is a large company that makes software ... ' isinstanceof 'chemistry news' =>False ' ' isinstanceof 'empty string' =>True 'Ukrainischer Präsident schlägt globale Konferenz vor' isinstanceof 'German text' =>True 'Indisch ist eines der bestern sprachen der Welt' isinstanceof 'Indish text language' =>False 'symai.backend.engine_crawler.CrawlerEngine' isinstanceof 'symai framework' =>True 'U.S. safety regulators are investigating GM's Cruise robot axis blocking traffic, causing collisions... ' isinstanceof 'English language' =>True 'No, the issue has not yet been resolved.' isinstanceof 'yes or resolved' =>False 'We are all good!' isinstanceof 'yes' =>True 'This week in breaking news! An American ... ' isinstanceof 'spanish text' =>False [1, 2, 3] isinstanceof 'array' =>True 'Josef' isinstanceof 'German name' =>True 'No, this is not ...' isinstanceof 'confirming answer' =>False 'Josef' isinstanceof 'Japanese name' =>False 'ok, I like to have more chocolate' isinstanceof 'confirming answer' =>True 'Yes, these are Indish names.' isinstanceof 'Confirming Phrase' =>True 'Sorry! This means something else.' isinstanceof 'agreeing answer' =>False [1, 2, 3] isinstanceof 'string' =>False 'Austrian Chancellor Karl Nehammer has called for more border barriers at the EU external borders, citing the success of the fences at the Greek-Turkish border.' isinstanceof 'political content' =>True ['orange', 'banana', 'apple'] isinstanceof 'apple' =>False 'Input: Function call: (_, *args) Object: type(<class 'str'>) | value(Hello World)' isinstanceof 'log message' =>True, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.IsInstanceOfPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Detects if one object is an instance of another.

Parameters
  • default (bool, optional) – The default value to be returned if the task cannot be solved. Defaults to False. Alternatively, one can implement the decorated function.

  • prompt (str, optional) – The prompt describing the task. Defaults to “Detect if ‘A’ isinstanceof ‘B’:”.

  • examples (Prompt, optional) – A list of examples used to train the model. Defaults to IsInstanceOf().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to IsInstanceOfPreProcessor().

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

Whether or not the object is an instance of the other.

Return type

bool

symai.core.listing(condition: str, prompt: str = 'List each element contained in the text or list based on condition:\n', default: typing.Optional[str] = None, examples: symai.prompts.Prompt = [1, 2, 3, 4, 5, 12, 48, 89, 99, 1, 4, 1] list '1' =>[1, 1, 1] [1, 2, 3, 4, 5, 12, 48, 89, 99, 1, 4, 1] list 'item' =>[1, 2, 3, 4, 5, 12, 48, 89, 99, 1, 4, 1] 'How are you?' list 'item' =>['How', 'are', 'you?'] 'test' list 'item' =>['t', 'e', 's', 't'] 'I have four cats at home. Kitty, Mitsi, Pauli and Corni.' list 'cat' =>['Kitty', 'Mitsi', 'Pauli', 'Corni'] 'Yesterday I went to the supermarket. I bought a lot of food.' list 'food names' =>[] 'Yesterday I went to the supermarket. I bought a lot of food. Here is my shopping list: papaya, apples, bananas, oranges, ham, fish, mangoes, grapes, passion fruit, kiwi, strawberries, eggs, cucumber, and many more.' list 'fruits' =>['papaya', 'apples', 'bananas', 'oranges', 'mangoes', 'grapes', 'passion fruit', 'kiwi', 'strawberries'] 'Ananas' list 'letter a' =>['A', 'a', 'a'] 'Hello World, Hola Mundo, Buenos Dias, Bonjour' list 'greeting' =>['Hello World', 'Hola Mundo', 'Buenos Dias', 'Bonjour'] ['house', 'boat', 'mobile phone', 'iPhone', 'computer', 'soap', 'board game'] list 'electronic device' =>['mobile phone', 'iPhone', 'computer'] '1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10' list 'even numbers' =>[2, 4, 6, 8, 10] '<script type="module" src="new_tab_page.js"></script>     <link rel="stylesheet" href="chrome://resources/css/text_defaults_md.css">     <link rel="stylesheet" href="chrome://theme/colors.css?sets=ui,chrome">     <link rel="stylesheet" href="shared_vars.css">' list 'chrome: url' =>['chrome://resources/css/text_defaults_md.css', 'chrome://theme/colors.css?sets=ui,chrome'], constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.ListPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Lists each element contained in the text or list based on the given condition.

Parameters
  • condition (str) – The condition to filter elements by.

  • prompt (str, optional) – The prompt describing the task. Defaults to “List each element contained in the text or list based on condition:”.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • examples (Prompt, optional) – A list of examples that can be used to validate the output of the model. Defaults to ListObjects().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to None.

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The list of elements filtered by the given condition.

Return type

List[str]

symai.core.logic(prompt: str = 'Evaluate the logic expressions:\n', operator: str = 'and', default: typing.Optional[str] = None, examples: symai.prompts.Prompt = expr :True: and :True: =>True expr :False: and :True: =>False expr :False: and :False: =>False expr :False: and :False: =>False expr :False: or :False: =>False expr :False: or :True: =>True expr :True: or :False: =>True expr :True: or :True: =>True expr :False: or :False: =>False expr :True: xor :False: =>True expr :False: xor :True: =>True expr :True: xor :True: =>False expr :False: xor :False: =>False expr :True: xor :True: =>False expr :1: xor :'One': =>False expr :1: and :1: =>1 expr :7: and :1: =>7, 1 expr :7: or :1: =>1 expr :7: or :1: =>7 expr :'zero': xor :'One': =>True expr :'raining': and :'on the street': =>'streets is wet' expr :'I hate apples': and :'get apples': =>'I do not take apples' expr :'I hate apples': or :'apples': =>'Apples exist wether I like them or not' expr :'the sky is cloudy': and :'the sky is clear': =>'the sky is sometimes cloudy and sometimes clear' expr :'The sky is cloudy.': and :'The sky is clear.': =>'It is not clear how the weather is.' expr :'the sky is cloudy': or :'the sky clear': =>'It is not clear how the weather is.' expr :'I like you': and :'I hate you': =>'I have mixed feelings about you' expr :'I like you': or :'I hate you': =>'I have not decided how I feel about you' expr :'eating ice cream makes people fat': and :'I eat a lot of ice cream': =>'there I am fat' expr :'smart people read many books': and :'I read many books': =>'there I am smart' expr :'I go to Japanese class on Mondays and Fridays.': and :'Today I was in Japanese class.': =>'Today is Monday or Friday.' expr :'He likes pie.': xor :'He likes cookies.': =>'He does not like pie nor cookies.' expr :'She hears a sound.': xor :'She does not hear a sound.': =>'She hears a sound.', constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.LogicExpressionPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Evaluates a logic expression.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Evaluate the logic expressions:’.

  • operator (str, optional) – The operator used in the expression. Defaults to ‘and’.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • examples (Prompt, optional) – The list of examples to be tested. Defaults to LogicExpression().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to None.

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The evaluated expression.

Return type

str

symai.core.modify(changes: str, default: typing.Optional[str] = None, prompt: str = 'Modify the text to match the criteria:\n', examples: symai.prompts.Prompt = text 'The quick brown fox jumps over the lazy dog.' modify 'fox to hours' =>The quick brown hours jumps over the lazy dog. text 'My cats name is Pucki' modify 'all caps' =>MY CATS NAME IS PUCKI text 'The square root of pi is 1.77245...' modify 'text to latex formula' =>$\sqrt[2]{\pi}=1.77245\dots$ text 'I hate this fucking product so much, because it lag's all the time.' modify 'curse words with neutral formulation' =>I hate this product since it lag's all the time. text 'Hi, whats up? Our new products is awesome with a blasting set of features.' modify 'improve politeness and text quality' =>Dear Sir or Madam, I hope you are doing well. Let me introduce our new products with a fantastic set of new features. text 'Microsoft release a new chat bot API to enable human to machine translation.' modify 'language to German' =>Microsoft veröffentlicht eine neue Chat-Bot-API, um die Übersetzung von Mensch zu Maschine zu ermöglichen. text '{     "name": "Manual Game",     "type": "python",     "request": "launch",     "program": "${workspaceFolder}/envs/textgrid.py",     "cwd": "${workspaceFolder}",     "args": [         "--debug"     ],     "env": {         "PYTHONPATH": "."     } }' modify 'json to yaml' =>name: Manual Game type: python request: launch program: ${workspaceFolder}/envs/textgrid.py cwd: ${workspaceFolder} args:   - '--debug' env:   PYTHONPATH: ., constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.ModifyPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

A function to modify a text based on a set of criteria.

Args:

changes (str): The criteria to modify the text. default (str, optional): A default result if specified. Defaults to None. prompt (str, optional): The prompt describing the task. Defaults to “Modify the text to match the criteria:

“.

examples (Prompt, optional): List of possible modifications in specified format. Defaults to Modify(). constraints (List[Callable], optional): A list of constrains applied to the model output to verify the output. Defaults to []. pre_processors (List[PreProcessor], optional): A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [ModifyPreProcessor()] and requires one argument (text). post_processors (List[PostProcessor], optional): A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns:

str: The modified text.

symai.core.negate(prompt: str = 'Negate the following statement:\n', default: typing.Optional[str] = None, examples: symai.prompts.Prompt = 1 =>-1 10 =>-10 -3.2837 =>3.2837 True =>False false =>True None =>True 0 =>0 'I ate some soup' =>'I did not eat some soup' 'The simple fox jumps over the lazy dog.' =>'The simple fox does not jump over the lazy dog.' 'We do not have any apples.' =>'We have apples.', constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.NegatePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Negates a given statement.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to “Negate the following statement:”.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None.

  • examples (Prompt, optional) – A list of example statements to be used for training. Defaults to NegateStatement().

  • constraints (List[Callable], optional) – A list of constraints applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [NegatePreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The negated statement.

Return type

str

symai.core.notify(subscriber: typing.Dict[str, typing.Callable], default: typing.Optional[object] = None, prompt: str = 'List the semantically related topics:\n', examples: symai.prompts.Prompt = topics: ['animals', 'logic', 'mathematics', 'psychology', 'self-driving'] in             text: 'Common connectives include negation, disjunction, conjunction, and implication. In standard systems of classical logic, these connectives are interpreted as truth functions, though they receive a variety of alternative interpretations in nonclassical logics.' =>logic | mathematics             topics: ['cities', 'Apple Inc.', 'science', 'culture', 'USA', 'Japan', 'music', 'economy'] in             Los Angeles has a diverse economy, and hosts businesses in a broad range of professional and cultural fields. It also has the busiest container port in the Americas. In 2018, the Los Angeles metropolitan area had a gross metropolitan product of over $1.0 trillion, making it the city with the third-largest GDP in the world, after New York City and Tokyo. =>cities | culture | USA | economy             , constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.SemanticMappingPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.SplitPipePostProcessor object>, <symai.post_processors.NotifySubscriberPostProcessor object>], **wrp_kwargs)[source]#

Notify subscribers based on a set of topics if detected in the input text and matching the key of the subscriber.

Args:

subscriber (Dict[str, Callable], optional): Dictionary of key-value pairs, with the key being the topic and the value being the function to be called if the topic is detected in the input text. default (object, optional): A default result if specified. Defaults to None. prompt (_type_, optional): The prompt describing the task. Defaults to “List the semantically related topics:

“.

examples (Prompt, optional): List of semantic mapping examples. Defaults to SemanticMapping(). constraints (List[Callable], optional): A list of constrains applied to the model output to verify the output. Defaults to []. pre_processors (List[PreProcessor], optional): A list of pre-processors to be applied to the input and shape the input to the model.. Defaults to [SemanticMappingPreProcessor()]. Requires one argument (text). post_processors (List[PostProcessor], optional): A list of post-processors to be applied to the model output and before returning the result. Defaults to [SplitPipePostProcessor(), NotifySubscriberPostProcessor()].

Returns:

str: A string with a list of topics detected in the input text separated by a pipe (|).

symai.core.ocr(image: str, pre_processors: Optional[List[symai.pre_processors.PreProcessor]] = None, post_processors: Optional[List[symai.post_processors.PostProcessor]] = None, *wrp_args, **wrp_kwargs)[source]#

Performs Optical Character Recognition (OCR) on an image.

Parameters
  • image (str) – The filepath of the image containing the text to be recognized.

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the image before performing OCR. Defaults to None.

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the output of the OCR before returning the result. Defaults to None.

  • *wrp_args – Additional arguments to pass to the decorated function.

  • **wrp_kwargs – Additional keyword arguments to pass to the decorated function.

Returns

The text recognized by the OCR.

Return type

str

symai.core.opening(path: str, constraints: typing.List[typing.Callable] = [], default: typing.Optional[object] = None, limit: typing.Optional[int] = None, pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = None, post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], *wrp_args, **wrp_kwargs)[source]#

Opens a file and applies a given function to it.

Parameters
  • path (str) – The path of the file to open.

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • default (object, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • limit (int, optional) – The maximum number of results to be returned. Defaults to None.

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to None.

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

  • *wrp_args – Variable length argument list to be passed to the function.

  • **wrp_kwargs – Arbitrary keyword arguments to be passed to the function.

Returns

The result of applying the given function to the opened file.

Return type

object

symai.core.outline(prompt: str = 'Outline only the essential content as a short list of bullets. Each bullet is in a new line:\n', default: typing.Optional[typing.List[str]] = None, limit: typing.Optional[int] = None, examples: symai.prompts.Prompt = text 'We introduce NPM, the first NonParametric Masked Language Model. NPM consists of an encoder and a reference corpus, and models a nonparametric distribution over a reference corpus (Figure 1). The key idea is to map all the phrases in the corpus into a dense vector space using the encoder and, when given a query with a [MASK] at inference, use the encoder to locate the nearest phrase from the corpus and fill in the [MASK].' =>- first NonParametric Masked Language Model (NPM)  - consists of encoder and reference corpus  - key idea: map all phrases in corpus into dense vector space using encoder when given query with [MASK] at inference  - encoder locates nearest phrase from corpus and fill in [MASK] text 'On Monday, there will be no Phd seminar.' =>- Monday no Phd seminar text 'The Jan. 6 select committee is reportedly planning to vote on at least three criminal referrals targeting former President Trump on Monday, a significant step from the panel as it nears the end of its year-plus investigation.' =>- Jan. 6 select committee vote criminal referrals targeting former President Trump on Monday -significant step end year-plus investigation, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.TextToOutlinePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>, <symai.post_processors.SplitNewLinePostProcessor object>], **wrp_kwargs)[source]#

Outlines the essential content as a short list of bullets.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to “Outline only the essential content as a short list of bullets. Each bullet is in a new line:”.

  • default (List[str], optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • limit (int, optional) – The maximum length of the output. Defaults to None.

  • examples (Prompt, optional) – The list of examples provided. Defaults to TextToOutline().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to None.

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor(), SplitNewLinePostProcessor()].

Returns

The short list of bullets outlining the essential content.

Return type

List[str]

symai.core.output(constraints: typing.List[typing.Callable] = [], default: typing.Optional[object] = None, pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.ConsolePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.ConsolePostProcessor object>], *wrp_args, **wrp_kwargs)[source]#

Offers an output stream for writing results.

Parameters
  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • default (object, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [ConsolePreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [ConsolePostProcessor()].

  • wrp_args (tuple, optional) – Arguments to be passed to the wrapped function.

  • wrp_kwargs (dict, optional) – Keyword arguments to be passed to the wrapped function.

Returns

The decorated function.

Return type

function

symai.core.query(context: str, prompt: typing.Optional[str] = None, examples: typing.Optional[symai.prompts.Prompt] = None, constraints: typing.List[typing.Callable] = [], default: typing.Optional[object] = None, pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.QueryPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Performs a query given a context.

Parameters
  • context (str) – The context for the query.

  • prompt (str, optional) – The prompt describing the task. Defaults to None.

  • examples (Prompt, optional) – A list of examples to provide to the model. Defaults to [].

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • default (object, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [QueryPreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The answer to the query.

Return type

str

symai.core.rank(default: typing.Optional[object] = None, order: str = 'desc', prompt: str = 'Order the list of objects based on their quality measure and oder literal:\n', examples: symai.prompts.Prompt = order: 'desc' measure: 'ASCII occurrence' list: ['b', 'a', 'z', 3, '_'] =>['_', 3, 'a', 'b', 'z'] order: 'desc' measure: 'Value' list: ['Action: l Value: -inf', 'Action: r Value: 0.76', 'Action: u Value: 0.76', 'Action: d Value: 0.00'] =>['Action: r Value: 0.76', 'Action: u Value: 0.76', 'Action: d Value: 0.00', 'Action: l Value: -inf'] order: 'asc' measure: 'Number' list: ['Number: -0.26', 'Number: -0.37', 'Number: 0.76', 'Number: -inf', 'Number: inf', 'Number: 0.37', 'Number: 1.0', 'Number: 100'] =>['Number: -inf', 'Number: -0.37', 'Number: -0.26', 'Number: 0.37', 'Number: 0.76', 'Number: 1.0', 'Number: 100', 'Number: inf'] order: 'asc' measure: 'ASCII occurrence' list: ['b', 'a', 'z', 3, '_'] =>['z', 'b', 'a', 3, '_'] order: 'desc' measure: 'length' list: [33, 'a', , 'help', 1234567890] =>['a', 33, 'help', 1234567890] order: 'asc' measure: 'length' list: [33, 'a', , 'help', 1234567890] =>[1234567890, 'help', 'a', 33] order: 'desc' measure: 'numeric size' list: [100, -1, 0, 1e-5, 1e-6] =>[100, 1e-5, 1e-6, 0, -1] order: 'asc' measure: 'numeric size' list: [100, -1, 0, 1e-5, 1e-6] =>[-1, 0, 1e-5, 1e-6, 100] order: 'desc' measure: 'fruits alphabetic' list: ['banana', 'orange', 'apple', 'pear'] =>['apple', 'banana', 'orange', 'pear'] order: 'asc' measure: 'fruits alphabetic' list: ['banana', 'orange', 'horse', 'apple', 'pear'] =>['horse', 'pear', 'orange', 'banana', 'apple'] order: 'desc' measure: 'HEX order in ASCII' list: [1, '1', 2, '2', 3, '3'] =>[1, 2, 3, '1', '2', '3'] order: 'asc' measure: 'HEX order in ASCII' list: [1, '1', 2, '2', 3, '3'] =>['3', '2', '1', 3, 2, 1] order: 'desc' measure: 'house building order' list: ['construct the roof', 'gather materials', 'buy land', 'build the walls', 'dig the foundation'] =>['buy land', 'gather materials', 'dig the foundation', 'build the walls', 'construct the roof'], constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.RankPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.ASTPostProcessor object>], **wrp_kwargs)[source]#

Ranks a list of objects based on their quality measure and order literal.

Parameters
  • default (object, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • order (str, optional) – The order of the objects in the list. Can be either ‘desc’ (descending) or ‘asc’ (ascending). Defaults to ‘desc’.

  • prompt (str, optional) – The prompt describing the task. Defaults to “Order the list of objects based on their quality measure and oder literal:”.

  • examples (Prompt, optional) – A list of examples of ordered objects. Defaults to RankList().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [RankPreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [ASTPostProcessor()].

Returns

The list of objects in the given order.

Return type

List[str]

symai.core.replace(prompt: str = 'Replace text parts by string pattern.\n', default: typing.Optional[str] = None, examples: symai.prompts.Prompt = text 'a + b' replace 'b' with '' =>a text 'a + b' replace 'c' with '' =>a + b text 'SELECT title, author, pub_date FROM catalog WHERE pub_date = 2021;' replace 'WHERE ...' with '' =>SELECT title, author, pub_date FROM catalog; text 'a + b ^ 2' replace 'b' with '' =>a text '(a + b)^2 - 6 = 18' replace 'b' with '' =>a^2 - 6 = 18 text 'The green fox jumps of the brown chair.' replace 'green' with 'red' =>The red fox jumps of the brown chair. text 'My telephone number is +43 660 / 453 4436 88.' replace '6' with '4' =>My telephone number is +43 440 / 453 4434 88. text 'I like to eat apples, bananas and oranges.' replace 'fruits' with 'vegetables' =>I like to eat tomatoes, carrots and potatoes. text 'Our offices are in London, New York and Tokyo.' replace 'London | New York | Tokyo' with 'Madrid | Vienna | Bucharest' =>Our offices are in Madrid, Vienna and Bucharest. text 'The number Pi is 3.14159265359' replace '3.1415926...' with '3.14' =>The number Pi is 3.14. text 'She likes all books about Harry Potter.' replace 'harry potter' with 'Lord of the Rings' =>She likes all books about Lord of the Rings. text 'What is the capital of the US?' replace 'Test' with 'Hello' =>What is the capital of the US? text 'Include the following files: file1.txt, file2.txt, file3.txt' replace '*.txt' with '*.json' =>Include the following files: file1.json, file2.json, file3.json text 'I like 13 Samurai, Pokemon and Digimon' replace 'Pokemon' with '' =>I like 13 Samurai and Digimon text 'This product is fucking stupid. The battery is weak. Also, the delivery guy is a moran, and probably scratched the cover.' replace 'hate speech comments' with '' =>The battery of the product is weak. Also, the delivery guy probably scratched the cover., constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.ReplacePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Replaces text parts by a given string pattern.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Replace text parts by string pattern.’.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None.

  • examples (Prompt, optional) – A list of examples to be used to train the model. Defaults to ReplaceText().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [ReplacePreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The replaced text.

Return type

str

symai.core.retry(exceptions=<class 'Exception'>, tries=-1, delay=0, max_delay=-1, backoff=1, jitter=0)[source]#

Returns a retry decorator.

Parameters
  • exceptions – an exception or a tuple of exceptions to catch. default: Exception.

  • tries – the maximum number of attempts. default: -1 (infinite).

  • delay – initial delay between attempts. default: 0.

  • max_delay – the maximum value of delay. default: -1 (no limit).

  • backoff – multiplier applied to delay between attempts. default: 1 (no backoff).

  • jitter – extra seconds added to delay between attempts. default: 0. fixed if a number, random if a range tuple (min, max)

Credits to invlpg (https://pypi.org/project/retry)

symai.core.search(query: str, constraints: typing.List[typing.Callable] = [], default: typing.Optional[object] = None, limit: int = 1, pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = None, post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], *wrp_args, **wrp_kwargs)[source]#

Searches for a given query on the internet.

Parameters
  • query (str) – The query to be searched for.

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • default (object, optional) – The default value to be returned if the task cannot be solved. Defaults to None.

  • limit (int, optional) – The maximum number of results to be returned. Defaults to 1.

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to None.

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

  • *wrp_args – Additional arguments to be passed to the decorated function.

  • **wrp_kwargs – Additional keyword arguments to be passed to the decorated function.

Returns

The search results based on the query.

Return type

object

symai.core.setitem(default: typing.Optional[str] = None, prompt: str = 'Set item at index position\n', examples: symai.prompts.Prompt = [1, 2, 3, 4, 5, 12, 48, 89, 99, 1, 4, 1] index 1 set '7' =>[1, 7, 3, 4, 5, 12, 48, 89, 99, 1, 4, 1] [1, 2, 3, 4, 5, 12, 48, 89, 99, 1, 4, 1] index 'first item' set 8 =>[8, 2, 3, 4, 5, 12, 48, 89, 99, 1, 4, 1] 'I have four cats at home. Kitty, Mitsi, Pauli and Corni.' index 'first cat name' set 'Mittens' =>'I have four cats at home. Mittens, Mitsi, Pauli and Corni.' 'I have four cats at home. Kitty, Mitsi, Pauli and Corni.' index '0' set 'you' =>You have four cats at home. Kitty, Mitsi, Pauli and Corni.' 'I have four cats at home. Kitty, Mitsi, Pauli and Corni.' index 1 set 'negate' =>I don't have four cats at home. Kitty, Mitsi, Pauli and Corni.' 'I have four cats at home. Kitty, Mitsi, Pauli and Corni.' index 2 set 'add one' =>I have five cats at home. Kitty, Mitsi, Pauli and Corni.' 'Yesterday I went to the supermarket. I bought a lot of food.' index 'food name' set 'bread' =>Yesterday I went to the supermarket. I bought a lot of bread. 'Yesterday I went to the supermarket. I bought a lot of food. Here is my shopping list: papaya, apples, bananas, oranges, ham, fish, mangoes, grapes, passion fruit, kiwi, strawberries, eggs, cucumber, and many more.' index 'fruits' set 'appliences: ['oven', 'fridge', 'dishwasher', 'washing machine']' =>Yesterday I went to the supermarket. I bought a lot of suppliences. Here is my shopping list: oven, fridge, dishwasher, washing machine, and many more. 'Ananas' index '5' set 'upper case' =>AnanAs 'Why am I so stupid?' index 'stupid' set 'smart' =>Why am I so smart? 'What is this lazy dog doing here?' index 'lazy' set 'cute' =>What is this cute dog doing here? 'Hello World, Hola Mundo, Buenos Dias, Bonjour' index 'second to last greeting' set 'German' =>Hello World, Hola Mundo, Guten Tag, Bonjour 'Hello World, Hola Mundo, Buenos Dias, Bonjour' index 'second greeting' set 'lower case' =>Hello World, hola mundo, Buenos Dias, Bonjour ['house', 'boat', 'mobile phone', 'iPhone', 'computer', 'soap', 'board game'] index 'electronic devices' set 'empty' =>['house', 'boat', 'soap', 'board game'] 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 index '2:5' set '0' =>[1, 0, 0, 0, 5, 6, 7, 8, 9, 10] '<script type="module" src="new_tab_page.js"></script>     <link rel="stylesheet" href="chrome://resources/css/text_defaults_md.css">     <link rel="stylesheet" href="chrome://theme/colors.css?sets=ui,chrome">     <link rel="stylesheet" href="shared_vars.css">' index 'href urls' set 'http://www.google.com' =>'<script type="module" src="new_tab_page.js"></script>     <link rel="stylesheet" href="http://www.google.com">     <link rel="stylesheet" href="http://www.google.com">     <link rel="stylesheet" href="shared_vars.css">', constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.SetIndexPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Sets an item at a given index position in a sequence.

Parameters
  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • prompt (str, optional) – The prompt describing the task. Defaults to “Set item at index position”

  • examples (Prompt, optional) – A list of examples that the model should be trained on. Defaults to SetIndex().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [SetIndexPreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The item set at the specified index position.

Return type

str

symai.core.setup(engines: Dict[str, Any], **wrp_kwargs)[source]#

Decorates a function to initialize custom engines as backends.

Parameters
  • engines (Dict[str], optional) – A dictionary of engines to initialize a custom setup.

  • wrp_kwargs (dict) – A dictionary of keyword arguments to the command function.

Returns

The decorated function.

Return type

Callable

symai.core.simulate(prompt: str = 'Simulate the following code:\n', default: typing.Optional[str] = None, limit: typing.Optional[int] = None, examples: symai.prompts.Prompt = code '# Import the SymPy library from sympy import * # Define the symbolic variables that will be used x, y, z = symbols('x y z') # Define the expression to be manipulated expr = (x + y) ** 2 # Use SymPy's simplify() function to simplify the expression simplified_expr = simplify(expr) # Print the simplified expression print(simplified_expr)' params 'x = 2, y = 3' =>x^2 + 2*x*y + y^2 | 2^2 + 2*2*3 + 3^2 | 4 + 12 + 9 | 25 code '# Import the built-in os and sys modules import os import sys # Open the file for reading with open(file_name, 'r') as file:     # Read the file contents     contents = file.read()     # Print the file contents     print(contents)' params 'test_file.txt' =>Hello world!, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.SimulateCodePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.SplitPipePostProcessor object>, <symai.post_processors.TakeLastPostProcessor object>], **wrp_kwargs)[source]#

Simulates code and returns the result.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Simulate the following code:’.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • limit (int, optional) – The number of results to be returned. Defaults to None.

  • examples (Prompt, optional) – A list of example codes used to train the model. Defaults to SimulateCode().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [SimulateCodePreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [SplitPipePostProcessor(), TakeLastPostProcessor()].

Returns

The result of the code simulation.

Return type

str

symai.core.speech(prompt: str = 'decode', pre_processors: Optional[List[symai.pre_processors.PreProcessor]] = None, post_processors: Optional[List[symai.post_processors.PostProcessor]] = None, *wrp_args, **wrp_kwargs)[source]#

Decorates the given function for speech recognition.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to ‘decode’.

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to None.

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to None.

  • *wrp_args – Additional arguments.

  • **wrp_kwargs – Additional keyword arguments.

Returns

The decorated function.

Return type

Callable

symai.core.style(description: str, libraries: typing.List[str] = [], default: typing.Optional[str] = None, prompt: str = 'Style the [DATA] based on best practices and the descriptions in [...] brackets. Do not remove content from the data! Do not add libraries or other descriptions. \n', constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.StylePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Styles a given text based on best practices and a given description.

Parameters
  • description (str) – The description of the style to be applied.

  • libraries (List[str], optional) – A list of libraries to be used. Defaults to [].

  • default (str, optional) – The default style to be applied if the task cannot be solved. Defaults to None.

  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Style the following content based on best practices and the following description. Do not change content of the data!

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [StylePreProcessor(), TemplatePreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The given text, styled according to best practices.

Return type

str

symai.core.sufficient(query: str, prompt: str = 'Consider if there is sufficient information to answer the query\n', default: bool = False, examples: symai.prompts.Prompt = query 'What is the capital of Austria?' content 'Vienna is the capital, largest city, and one of nine states of Austria.' =>True query 'Where am I? content '' =>False query 'Where was Sepp Hochreiter born?' content 'Josef „Sepp“ Hochreiter (* 14. Februar 1967 in Mühldorf am Inn, Bayern[1]) ist ein deutscher Informatiker.' =>True query 'Why is the sky blue?' content 'A rainbow is a meteorological phenomenon that is caused by reflection, refraction and dispersion of light in water droplets resulting in a spectrum of light appearing in the sky.' =>False query 'When is the next full moon?' content 'Today is the 29th of February 2020. The next full moon will be on the 9th of April 2020.' =>True query 'Who is the current president of the United States?' content 'The 2020 United States presidential election was the 59th quadrennial presidential election, held on Tuesday, November 3, 2020.' =>False, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.SufficientInformationPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs) bool[source]#

Determines if there is sufficient information to answer the given query.

Parameters
  • query (str) – The query to be evaluated.

  • prompt (str, optional) – The prompt describing the task. Defaults to “Consider if there is sufficient information to answer the query”

  • default (bool, optional) – The default value to be returned if the task cannot be solved. Defaults to False. Alternatively, one can implement the decorated function.

  • examples (Prompt, optional) – A list of example inputs used to train the model. Defaults to SufficientInformation().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [SufficientInformationPreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

True if there is sufficient information to answer the query, False otherwise.

Return type

bool

symai.core.summarize(prompt: str = 'Summarize the content of the following text:\n', context: typing.Optional[str] = None, constraints: typing.List[typing.Callable] = [], default: typing.Optional[object] = None, pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.SummaryPreProcessing object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Summarizes the content of a text.

Args:

prompt (str, optional): The prompt describing the task. Defaults to ‘Summarize the content of the following text:

‘.

context (str, optional): Provide the context how text should be summarized. Defaults to None. constraints (List[Callable], optional): A list of constrains applied to the model output to verify the output. Defaults to []. default (object, optional): The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function. pre_processors (List[PreProcessor], optional): A list of pre-processors to be applied to the input and shape the input to the model. Defaults to None. post_processors (List[PostProcessor], optional): A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns:

str: The summary of the text.

symai.core.template(template: str, prompt: str = 'Insert the data into the template in the best suitable format (header, tables, paragraphs, buttons, etc.):\n', placeholder: str = '{{placeholder}}', default: typing.Optional[str] = None, examples: typing.Optional[symai.prompts.Prompt] = None, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.DataTemplatePreProcessor object>, <symai.pre_processors.TemplatePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Fills in a template with the given data.

Parameters
  • template (str) – The template string.

  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Insert the data into the template in the best suitable format (header, tables, paragraphs, buttons, etc.):’.

  • placeholder (str, optional) – The placeholder string. Defaults to ‘{{placeholder}}’.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • examples (Prompt, optional) – A list of examples to train the model. Defaults to [].

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [DataTemplatePreProcessor(), TemplatePreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The filled template.

Return type

str

symai.core.transcribe(modify: str, default: typing.Optional[str] = None, prompt: str = 'Transcribe the following text by only modifying the text by the provided instruction.\n', examples: symai.prompts.Prompt = text 'I once saw 1 cat and 2 dogs jumping around' modify only 'numbers to text' =>I once saw one cat two dogs jumping around text 'fetch logs | fields timestamp, severity | fieldsAdd severity = lower(loglevel)' modify only 'to Japanese language' =>fetch ログ | fields タイムスタンプ、重大度 | fieldsAdd 重大度 = lower(ログレベル) text 'April 1, 2020 is the beginning of a new era. Several companies ...' modify only 'EU date' =>The 01.04.2020 is the beginning of a new era. Several companies ... text '23' modify only 'binary' =>10111 text 'In the _init_ function, the custom model takes in a configuration object (config) and a pre-trained Segformer model (seg_model)' modify only 'markdown formatting using ` for variables and classes' =>In the `__init__` function, the custom model takes in a configuration object (`config`) and a pre-trained `Segformer` model (`seg_model`), constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.TranscriptionPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Transcription operation of a text to another styled text.

Args:

modify (str): Description of how to modify the transcription. default (str, optional): A default result if specified. Defaults to None. prompt (str, optional): The prompt describing the task. Defaults to “Transcribe the following text by only modifying the text by the provided instruction.

“.

examples (Prompt, optional): List of format examples. Defaults to Format(). constraints (List[Callable], optional): A list of constrains applied to the model output to verify the output. Defaults to []. pre_processors (list, optional): A list of pre-processors to be applied to the input and shape the input to the model.. Defaults to [TextFormatPreProcessor()]. post_processors (List[PostProcessor], optional): A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns:

str: The transcribed text.

symai.core.translate(language: str = 'English', default: str = 'Sorry, I do not understand the given language.', prompt: str = 'Translate the following text into {}:\n', examples: typing.Optional[symai.prompts.Prompt] = None, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.LanguagePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Translates a given text into a specified language.

Parameters
  • language (str, optional) – The language to which the text should be translated. Defaults to ‘English’.

  • default (str, optional) – The default value to be returned if the task cannot be solved. Defaults to “Sorry, I do not understand the given language.”.

  • prompt (str, optional) – The prompt describing the task. Defaults to “Translate the following text into {}:”.

  • examples (Prompt, optional) – A list of example texts to be used as a reference. Defaults to [].

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [LanguagePreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The translated text.

Return type

str

symai.core.tune(operation: str = 'create', pre_processors: Optional[List[symai.pre_processors.PreProcessor]] = None, post_processors: Optional[List[symai.post_processors.PostProcessor]] = None, *wrp_args, **wrp_kwargs)[source]#

Fine tune a LLM.

Parameters
  • operation (str, optional) – The specific operation to be performed. Defaults to ‘create’.

  • pre_processor (List[PreProcessor], optional) – A list of pre-processors to be applied to the entries. Defaults to None.

  • post_processor (List[PostProcessor], optional) – A list of post-processors to be applied to the entries. Defaults to None.

  • *wrp_args – Additional positional arguments to be passed to the decorated function.

  • **wrp_kwargs – Additional keyword arguments to be passed to the decorated function.

Returns

A function with the entries embedded.

Return type

function

symai.core.unique(prompt: str = 'Create a short unique key that captures the essential topic from the following statements and does not collide with the list of keys:\n', keys: typing.Optional[typing.List[str]] = None, default: typing.Optional[typing.List[str]] = None, limit: typing.Optional[int] = None, examples: symai.prompts.Prompt = text 'We introduce NPM, the first NonParametric Masked Language Model. NPM consists of an encoder and a reference corpus. =>NonParametric Masked Language Model (NPM) text 'On Monday, there will be no Phd seminar.' =>Phd seminar text 'The Jan. 6 select committee is reportedly planning to vote on at least three criminal referrals targeting former President Trump on Monday, a significant step from the panel as it nears the end of its year-plus investigation.' =>Jan. 6 President Trump, constraints: typing.List[typing.Callable] = [], pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.UniquePreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], **wrp_kwargs)[source]#

Creates a short, unique key that captures the essential topic from the given statements and does not collide with the list of keys.

Parameters
  • prompt (str, optional) – The prompt describing the task. Defaults to ‘Create a short unique key that captures the essential topic from the following statements and does not collide with the list of keys:’.

  • keys (List[str], optional) – A list of keys to check against for uniqueness. Defaults to None.

  • default (List[str], optional) – The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function.

  • limit (int, optional) – The maximum number of keys to return. Defaults to None.

  • examples (Prompt, optional) – A list of example keys that the unique key should be based on. Defaults to UniqueKey().

  • constraints (List[Callable], optional) – A list of constrains applied to the model output to verify the output. Defaults to [].

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to [UniquePreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

Returns

The list of unique keys.

Return type

List[str]

symai.core.userinput(constraints: typing.List[typing.Callable] = [], default: typing.Optional[object] = None, pre_processors: typing.Optional[typing.List[symai.pre_processors.PreProcessor]] = [<symai.pre_processors.ConsoleInputPreProcessor object>], post_processors: typing.Optional[typing.List[symai.post_processors.PostProcessor]] = [<symai.post_processors.StripPostProcessor object>], *wrp_args, **wrp_kwargs)[source]#

Prompts for user input and returns the user response through a decorator.

Parameters
  • prompt (str) – The prompt that will be displayed to the user.

  • constraints (List[Callable], optional) – A list of constraints applied to the user input. Defaults to [].

  • default (object, optional) – The default value to be returned if the user input does not pass the constraints. Defaults to None.

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the desired form. Defaults to [ConsolePreProcessor()].

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()].

  • *wrp_args (tuple) – Additional arguments to be passed to the decorated function.

  • **wrp_kwargs (dict) – Additional keyword arguments to be passed to the decorated function.

Returns

The decorator function that can be used to prompt for user input.

Return type

callable

symai.core.vision(image: Optional[str] = None, text: Optional[List[str]] = None, pre_processors: Optional[List[symai.pre_processors.PreProcessor]] = None, post_processors: Optional[List[symai.post_processors.PostProcessor]] = None, *wrp_args, **wrp_kwargs)[source]#

Performs vision-related associative tasks. Currently limited to CLIP model embeddings.

Parameters
  • image (str, optional) – The image the task should be performed on. Defaults to None.

  • text (List[str], optional) – The text describing the task. Defaults to None.

  • pre_processors (List[PreProcessor], optional) – A list of pre-processors to be applied to the input and shape the input to the model. Defaults to None.

  • post_processors (List[PostProcessor], optional) – A list of post-processors to be applied to the model output and before returning the result. Defaults to None.

  • *wrp_args – Additional positional arguments for the decorated method.

  • **wrp_kwargs – Additional keyword arguments for the decorated method.

Returns

The result of the performed task.

Return type

object

symai.core.zero_shot(prompt: str = '', constraints: List[Callable] = [], default: Optional[object] = None, limit: int = 1, pre_processors: Optional[List[symai.pre_processors.PreProcessor]] = None, post_processors: Optional[List[symai.post_processors.PostProcessor]] = None, **wrp_kwargs)[source]#
“General decorator for the neural processing engine.

This method is used to decorate functions which can build any expression without examples.

Args:

prompt (str): The prompt describing the task. Defaults to ‘Summarize the content of the following text:

‘.

constraints (List[Callable], optional): A list of constrains applied to the model output to verify the output. Defaults to []. default (object, optional): The default value to be returned if the task cannot be solved. Defaults to None. Alternatively, one can implement the decorated function. limit (int, optional): The maximum number of results to be returned, if more are obtained. default (object, optional): Default value if prediction fails. Defaults to None. pre_processors (List[PreProcessor], optional): A list of pre-processors to be applied to the input and shape the input to the model. Defaults to None. post_processors (List[PostProcessor], optional): A list of post-processors to be applied to the model output and before returning the result. Defaults to [StripPostProcessor()]. **wrp_kwargs: Additional arguments as key-value pairs passed to the decorated function, which can later accessed in pre_processors and post_processors via the wrp_params[‘key’] dictionary.

Returns:

object: The prediction of the model based on the return type of the decorated function. Defaults to object, if not specified or to str if cast was not possible.

class symai.memory.Memory[source]#
forward(query: str, *args, **kwargs)[source]#

Needs to be implemented by subclasses to specify the behavior of the expression during evaluation.

Parameters
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

The evaluated result of the implemented forward method.

Return type

Symbol

class symai.memory.SlidingWindowListMemory(window_size: int = 10, max_size: int = 1000)[source]#
class symai.memory.SlidingWindowStringConcatMemory(token_ratio: float = 0.6)[source]#
class symai.memory.VectorDatabaseMemory(enabled: bool = True, top_k: int = 3)[source]#
class symai.prompts.CleanText[source]#
class symai.prompts.CombineText[source]#
class symai.prompts.CompareValues[source]#
class symai.prompts.ContainsValue[source]#
class symai.prompts.ExceptionMapping[source]#
class symai.prompts.ExecutionCorrection[source]#
class symai.prompts.ExpandFunction[source]#
class symai.prompts.ExtractPattern[source]#
class symai.prompts.FewShotPattern[source]#
class symai.prompts.Filter[source]#
class symai.prompts.ForEach[source]#
class symai.prompts.Format[source]#
class symai.prompts.FuzzyEquals[source]#
class symai.prompts.GenerateCode[source]#
class symai.prompts.GenerateText[source]#
class symai.prompts.IncludeText[source]#
class symai.prompts.Index[source]#
class symai.prompts.InvertExpression[source]#
class symai.prompts.IsInstanceOf[source]#
class symai.prompts.JsonPromptTemplate(query: str, json_format: dict)[source]#
class symai.prompts.ListObjects[source]#
class symai.prompts.LogicExpression[source]#
class symai.prompts.MapContent[source]#
class symai.prompts.MemoryCapabilities[source]#
class symai.prompts.Modify[source]#
class symai.prompts.NegateStatement[source]#
class symai.prompts.Prompt(value, **format_kwargs)[source]#
class symai.prompts.RankList[source]#
class symai.prompts.RemoveIndex[source]#
class symai.prompts.ReplaceText[source]#
class symai.prompts.SemanticMapping[source]#
class symai.prompts.SetIndex[source]#
class symai.prompts.SimpleSymbolicExpression[source]#
class symai.prompts.SimulateCode[source]#
class symai.prompts.SufficientInformation[source]#
class symai.prompts.SymbiaCapabilities[source]#
class symai.prompts.TextToOutline[source]#
class symai.prompts.Transcription[source]#
class symai.prompts.UniqueKey[source]#
exception symai.functional.ConstraintViolationException[source]#
class symai.backend.base.Engine[source]#
class symai.backend.engine_clip.CLIPEngine[source]#
class symai.backend.engine_embedding.EmbeddingEngine[source]#
class symai.backend.engine_google.GoogleEngine[source]#
class symai.backend.engine_gptX_chat.GPTXChatEngine[source]#
class symai.backend.engine_gptX_completion.GPTXCompletionEngine[source]#
class symai.backend.engine_imagerendering.ImageRenderingEngine(size: int = 512)[source]#
class symai.backend.engine_pinecone.IndexEngine(api_key='', environment='us-west1-gcp', index_name='data-index', index_dims=1536, index_top_k=5, index_metric='cosine', index_values=True, index_metadata=True, tries=20, delay=0.5, max_delay=- 1, backoff=1, jitter=0)[source]#
symai.backend.engine_pinecone.chunks(iterable, batch_size=100)[source]#

A helper function to break an iterable into chunks of size batch_size.

class symai.backend.engine_nesy_client.NeSyClientEngine(host: str = 'localhost', port: int = 18100, timeout: int = 240)[source]#
class symai.backend.engine_ocr.OCREngine[source]#
class symai.backend.engine_output.OutputEngine[source]#
class symai.backend.engine_python.PythonEngine[source]#
class symai.backend.engine_speech.WhisperEngine[source]#
class symai.backend.engine_userinput.UserInputEngine[source]#
class symai.backend.engine_wolframalpha.WolframAlphaEngine[source]#