From f8b0554649cb90cc97f47fcd7647e8e45931ce6e Mon Sep 17 00:00:00 2001 From: rlouf Date: Sat, 21 Dec 2024 13:20:02 +0000 Subject: [PATCH] Deployed 9744f00 to main with MkDocs 1.6.1 and mike 2.1.3 --- main/api/guide/index.html | 356 +++++++------ main/api/json_schema/index.html | 152 +++--- main/api/models/index.html | 851 ++++++++++++++++++------------- main/api/parsing/index.html | 182 ++++--- main/api/prompts/index.html | 407 +++++++-------- main/api/regex/index.html | 157 +++--- main/api/samplers/index.html | 871 +++++++++++++++++++------------- main/search/search_index.json | 2 +- main/sitemap.xml.gz | Bin 127 -> 127 bytes 9 files changed, 1688 insertions(+), 1290 deletions(-) diff --git a/main/api/guide/index.html b/main/api/guide/index.html index 9c822c609..902cf8228 100644 --- a/main/api/guide/index.html +++ b/main/api/guide/index.html @@ -2188,30 +2188,6 @@ - -
  • @@ -2221,30 +2197,6 @@ - -
  • @@ -2254,30 +2206,6 @@ - -
  • @@ -2676,30 +2604,6 @@ - -
  • @@ -2709,30 +2613,6 @@ - -
  • @@ -2742,30 +2622,6 @@ - -
  • @@ -3394,11 +3250,60 @@

    Parameters

    -

    state - The guides current PartialParserState, or None if complete

    -
    Returns
    -

    A Generate instance that contains the model and the allowed token ids.

    + + +

    Parameters:

    + + + + + + + + + + + + + + + + + +
    NameTypeDescriptionDefault
    + state + + CFGState + +
    +

    The guides current PartialParserState, or None if complete

    +
    +
    + required +
    + + +

    Returns:

    + + + + + + + + + + + + + +
    TypeDescription
    + A `Generate` instance that contains the model and the allowed token ids. + +
    + +
    +
    Source code in outlines/fsm/guide.py @@ -3482,13 +3387,76 @@

    Update the state of the guide. Decode the token_id, and calculate the new parser_state with the token applied.

    -

    Parameters
    -

    state - The guides current PartialParserState, or None if complete -token_id - The id of the token that was just generated.

    -
    Returns
    -

    The guides new PartialParserState

    + + +

    Parameters:

    + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescriptionDefault
    + state + + CFGState + +
    +

    The guides current PartialParserState, or None if complete

    +
    +
    + required +
    + token_id + + int + +
    +

    The id of the token that was just generated.

    +
    +
    + required +
    + + +

    Returns:

    + + + + + + + + + + + + + +
    TypeDescription
    + The guides new PartialParserState + +
    + +
    +
    Source code in outlines/fsm/guide.py @@ -3553,14 +3521,74 @@

    Iterate over the given token_ids and yield those that are valid for the current parser state.

    -

    Parameters
    -

    parser_state - The current state of the parser, or None if complete. -token_ids - The list of token ids to check for validity.

    -
    Yields
    -

    int - Valid token ids.

    + + +

    Parameters:

    + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescriptionDefault
    + parser_state + + +
    +

    The current state of the parser, or None if complete.

    +
    +
    + required +
    + token_ids + + +
    +

    The list of token ids to check for validity.

    +
    +
    + required +
    + + +

    Yields:

    + + + + + + + + + + + + + +
    TypeDescription
    + int + +
    +

    Valid token ids.

    +
    +
    Source code in outlines/fsm/guide.py diff --git a/main/api/json_schema/index.html b/main/api/json_schema/index.html index 9467a6e76..4a45a4bad 100644 --- a/main/api/json_schema/index.html +++ b/main/api/json_schema/index.html @@ -2130,39 +2130,6 @@ - -
  • @@ -2498,39 +2465,6 @@ - -
  • @@ -2598,15 +2532,83 @@

    Convert a JSON schema to a string.

    -

    Parameters

    -

    json_schema - The JSON schema.

    -

    Returns

    -

    str - The JSON schema converted to a string.

    -

    Raises

    -

    ValueError - If the schema is not a dictionary, a string or a Pydantic class.

    + + +

    Parameters:

    + + + + + + + + + + + + + + + + + +
    NameTypeDescriptionDefault
    + json_schema + + Union[dict, str, Type[BaseModel]] + +
    +

    The JSON schema.

    +
    +
    + required +
    + + +

    Returns:

    + + + + + + + + + + + + + +
    TypeDescription
    + str + +
    +

    The JSON schema converted to a string.

    +
    +
    + + +

    Raises:

    + + + + + + + + + + + + + +
    TypeDescription
    + ValueError + +
    +

    If the schema is not a dictionary, a string or a Pydantic class.

    +
    +
    Source code in outlines/fsm/json_schema.py diff --git a/main/api/models/index.html b/main/api/models/index.html index 6709f5bc1..f1f114841 100644 --- a/main/api/models/index.html +++ b/main/api/models/index.html @@ -2107,30 +2107,6 @@ - -
  • @@ -2140,30 +2116,6 @@ - -
  • @@ -2196,30 +2148,6 @@ - -
  • @@ -2248,21 +2176,6 @@ - -
  • @@ -2272,21 +2185,6 @@ - -
  • @@ -2301,21 +2199,6 @@ - -
  • @@ -2334,30 +2217,6 @@ - -
  • @@ -2745,30 +2604,6 @@ - -
  • @@ -2778,30 +2613,6 @@ - -
  • @@ -2834,30 +2645,6 @@ - -
  • @@ -2886,21 +2673,6 @@ - -
  • @@ -2910,21 +2682,6 @@ - -
  • @@ -2939,21 +2696,6 @@ - -
  • @@ -2972,30 +2714,6 @@ - -
  • @@ -3777,16 +3495,93 @@

    Compute a forward pass through the transformer model.

    -

    Parameters
    -

    input_ids - The input token ids. Must be one or two dimensional. -attention_mask - The attention mask. Must be one or two dimensional. -past_key_values - A tuple of tuples containing the cached key and value tensors for each - attention head.

    -
    Returns
    -

    The computed logits and the new cached key and value tensors.

    + + +

    Parameters:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescriptionDefault
    + input_ids + + LongTensor + +
    +

    The input token ids. Must be one or two dimensional.

    +
    +
    + required +
    + attention_mask + + LongTensor + +
    +

    The attention mask. Must be one or two dimensional.

    +
    +
    + required +
    + past_key_values + + Optional[Tuple] + +
    +

    A tuple of tuples containing the cached key and value tensors for each +attention head.

    +
    +
    + None +
    + + +

    Returns:

    + + + + + + + + + + + + + +
    TypeDescription
    + The computed logits and the new cached key and value tensors. + +
    + +
    +
    Source code in outlines/models/transformers.py @@ -3897,8 +3692,11 @@

    Generate text using transformers.

    -

    Arguments
    -

    prompts + + +

    + Arguments +

    prompts A prompt or list of prompts. generation_parameters An instance of GenerationParameters that contains the prompt, @@ -3910,8 +3708,29 @@

    Arguments An instance of SamplingParameters, a dataclass that contains the name of the sampler to use and related parameters as available in Outlines.

    -
    Returns
    -

    The generated text

    +
    + +

    Returns:

    + + + + + + + + + + + + + +
    TypeDescription
    + The generated text + +
    + +
    +
    Source code in outlines/models/transformers.py @@ -4264,20 +4083,111 @@

    Instantiate a model from the transformers library and its tokenizer.

    -

    Parameters

    -

    model_name - The name of the model as listed on Hugging Face's model page. -device - The device(s) on which the model should be loaded. This overrides - the device_map entry in model_kwargs when provided. -model_kwargs - A dictionary that contains the keyword arguments to pass to the - from_pretrained method when loading the model. -tokenizer_kwargs - A dictionary that contains the keyword arguments to pass to the - from_pretrained method when loading the tokenizer.

    -

    Returns

    -

    A TransformersModel model instance.

    + + +

    Parameters:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescriptionDefault
    + model_name + + str + +
    +

    The name of the model as listed on Hugging Face's model page.

    +
    +
    + required +
    + device + + Optional[str] + +
    +

    The device(s) on which the model should be loaded. This overrides +the device_map entry in model_kwargs when provided.

    +
    +
    + None +
    + model_kwargs + + dict + +
    +

    A dictionary that contains the keyword arguments to pass to the +from_pretrained method when loading the model.

    +
    +
    + {} +
    + tokenizer_kwargs + + dict + +
    +

    A dictionary that contains the keyword arguments to pass to the +from_pretrained method when loading the tokenizer.

    +
    +
    + {} +
    + + +

    Returns:

    + + + + + + + + + + + + + +
    TypeDescription
    + A `TransformersModel` model instance. + +
    + +
    +
    Source code in outlines/models/transformers.py @@ -4666,22 +4576,134 @@

    Call the OpenAI API to generate text.

    -
    Parameters
    -

    prompt - A string or list of strings that will be used to prompt the model -max_tokens - The maximum number of tokens to generate -stop_at - A string or array of strings which, such that the generation stops - when they are generated. -system_prompt - The content of the system message that precedes the user's prompt. -temperature - The value of the temperature used to sample tokens -samples - The number of completions to generate for each prompt -stop_at - Up to 4 words where the API will stop the completion.

    + + +

    Parameters:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescriptionDefault
    + prompt + + Union[str, List[str]] + +
    +

    A string or list of strings that will be used to prompt the model

    +
    +
    + required +
    + max_tokens + + Optional[int] + +
    +

    The maximum number of tokens to generate

    +
    +
    + None +
    + stop_at + + Optional[Union[List[str], str]] + +
    +

    A string or array of strings which, such that the generation stops +when they are generated.

    +
    +
    + None +
    + system_prompt + + Optional[str] + +
    +

    The content of the system message that precedes the user's prompt.

    +
    +
    + None +
    + temperature + + Optional[float] + +
    +

    The value of the temperature used to sample tokens

    +
    +
    + None +
    + samples + + Optional[int] + +
    +

    The number of completions to generate for each prompt

    +
    +
    + None +
    + stop_at + + Optional[Union[List[str], str]] + +
    +

    Up to 4 words where the API will stop the completion.

    +
    +
    + None +
    Source code in outlines/models/openai.py @@ -4802,12 +4824,52 @@

    Create an OpenAI instance.

    This class supports the standard OpenAI API, the Azure OpeanAI API as well as compatible APIs that rely on the OpenAI client.

    -

    Parameters
    -

    client - An instance of the API's async client. -config - An instance of OpenAIConfig. Can be useful to specify some - parameters that cannot be set by calling this class' methods.

    + + +

    Parameters:

    + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescriptionDefault
    + client + + +
    +

    An instance of the API's async client.

    +
    +
    + required +
    + config + + +
    +

    An instance of OpenAIConfig. Can be useful to specify some +parameters that cannot be set by calling this class' methods.

    +
    +
    + required +
    Source code in outlines/models/openai.py @@ -4906,8 +4968,11 @@

    The information was last fetched on 2023/11/20. We document below the properties that are specific to the OpenAI API. Not all these properties are supported by Outlines.

    -

    Properties

    -

    model + + +

    + Properties +

    model The name of the model. Available models can be found on OpenAI's website. frequence_penalty Number between 2.0 and -2.0. Positive values penalize new tokens based on @@ -4934,7 +4999,7 @@

    Properties

    Number between 0 and 1. Parameter for nucleus sampling. user A unique identifier for the end-user.

    - +
    @@ -5155,19 +5220,109 @@

    Call OpenAI's Chat Completion API.

    -

    Parameters

    -

    prompt - The prompt we use to start the generation. Passed to the model - with the "user" role. -system_prompt - The system prompt, passed to the model with the "system" role - before the prompt. -client - The API client -config - An OpenAIConfig instance.

    -

    Returns

    -

    A tuple that contains the model's response(s) and usage statistics.

    + + +

    Parameters:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescriptionDefault
    + prompt + + str + +
    +

    The prompt we use to start the generation. Passed to the model +with the "user" role.

    +
    +
    + required +
    + system_prompt + + Union[str, None] + +
    +

    The system prompt, passed to the model with the "system" role +before the prompt.

    +
    +
    + required +
    + client + + +
    +

    The API client

    +
    +
    + required +
    + config + + OpenAIConfig + +
    +

    An OpenAIConfig instance.

    +
    +
    + required +
    + + +

    Returns:

    + + + + + + + + + + + + + +
    TypeDescription
    + A tuple that contains the model's response(s) and usage statistics. + +
    + +
    +
    Source code in outlines/models/openai.py diff --git a/main/api/parsing/index.html b/main/api/parsing/index.html index 95cda45bb..7d34d7443 100644 --- a/main/api/parsing/index.html +++ b/main/api/parsing/index.html @@ -2265,30 +2265,6 @@ - -
  • @@ -2675,30 +2651,6 @@ - -
  • @@ -4315,19 +4267,127 @@

    Get the indices of the sub-FSMs in fsm that could have matched the state sequence state_seq.

    -

    Parameters

    -

    state_seq - A state sequence. -fsms_to_trans_finals - A map from FSM indices to tuples containing sets of their state transitions - and sets of the final/accept states.

    -

    Returns

    -

    A generator returning tuples containing each sub-FSM index (in the order -they were union-ed to construct fsm) and booleans indicating whether or -not there is another valid transition from the last state in the sequence -for the associated sub-FSM (i.e. if the FSM can continue -accepting/matching) and whether or not the sequence ends in a final state -of the sub-FSM.

    + + +

    Parameters:

    + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescriptionDefault
    + state_seq + + Sequence[int] + +
    +

    A state sequence.

    +
    +
    + required +
    + fsms_to_trans_finals + + Dict[int, Tuple[Set[Tuple[int, int]], Set[int], Dict[int, Set[int]]]] + +
    +

    A map from FSM indices to tuples containing sets of their state transitions +and sets of the final/accept states.

    +
    +
    + required +
    + + +

    Returns:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    TypeDescription
    + A generator returning tuples containing each sub-FSM index (in the order + +
    + +
    +
    + they were union-ed to construct `fsm`) and booleans indicating whether or + +
    + +
    +
    + not there is another valid transition from the last state in the sequence + +
    + +
    +
    + for the associated sub-FSM (i.e. if the FSM can continue + +
    + +
    +
    + accepting/matching) and whether or not the sequence ends in a final state + +
    + +
    +
    + of the sub-FSM. + +
    + +
    +
    Source code in outlines/fsm/parsing.py diff --git a/main/api/prompts/index.html b/main/api/prompts/index.html index a2ba1a3f3..b244937c7 100644 --- a/main/api/prompts/index.html +++ b/main/api/prompts/index.html @@ -2119,21 +2119,6 @@ - -

  • @@ -2220,21 +2205,6 @@ - -
  • @@ -2244,39 +2214,6 @@ - -
  • @@ -2634,21 +2571,6 @@ - - @@ -2735,21 +2657,6 @@ - -
  • @@ -2759,39 +2666,6 @@ - -
  • @@ -2952,8 +2826,29 @@

    Render and return the template.

    -
    Returns
    -

    The rendered template as a Python str.

    + + +

    Returns:

    + + + + + + + + + + + + + +
    TypeDescription
    + The rendered template as a Python ``str``. + +
    + +
    +
    Source code in outlines/prompts.py @@ -3405,8 +3300,29 @@

    -

    Returns

    -

    A Prompt callable class which will render the template when called.

    + + +

    Returns:

    + + + + + + + + + + + + + +
    TypeDescription
    + A `Prompt` callable class which will render the template when called. + +
    + +
    +
    Source code in outlines/prompts.py @@ -3526,110 +3442,141 @@

    This function removes extra whitespaces and linebreaks from templates to allow users to enter prompts more naturally than if they used Python's constructs directly. See the examples for a detailed explanation.

    -

    Examples

    -

    Outlines follow Jinja2's syntax

    -
    -
    -
    -

    import outlines -outline = outlines.render("I like {{food}} and {{sport}}", food="tomatoes", sport="tennis") -I like tomatoes and tennis

    -
    -
    -
    -

    If the first line of the template is empty, render removes it

    -
    -
    -
    -

    from outlines import render

    -

    tpl = ''' -... A new string''' -tpl -... '\nA new string' -render(tpl) -... 'a new string'

    -
    -
    -
    -

    Similarly, render ignores linebreaks introduced by placing the closing quotes + + +

    Examples:

    +

    Outlines follow Jinja2's syntax

    +
    >>> import outlines
    +>>> outline = outlines.render("I like {{food}} and {{sport}}", food="tomatoes", sport="tennis")
    +I like tomatoes and tennis
    +
    +

    If the first line of the template is empty, render removes it

    +
    >>> from outlines import render
    +>>>
    +>>> tpl = '''
    +... A new string'''
    +>>> tpl
    +... '\nA new string'
    +>>> render(tpl)
    +... 'a new string'
    +
    +

    Similarly, render ignores linebreaks introduced by placing the closing quotes underneath the text:

    -
    -
    -
    -

    tpl = ''' -... A new string -... ''' -tpl -... '\nA new string\n' -render(tpl) -... 'A new string'

    -
    -
    -
    -

    If you want to insert a linebreak at the end of the rendered template, you will +

    >>> tpl = '''
    +... A new string
    +... '''
    +>>> tpl
    +... '\nA new string\n'
    +>>> render(tpl)
    +... 'A new string'
    +
    +

    If you want to insert a linebreak at the end of the rendered template, you will need to leave an empty line at the end of the template:

    -
    -
    -
    -

    tpl = ''' -... A new string -... -... ''' -tpl -... '\nA new string\n\n' -render(tpl) -... 'A new string\n'

    -
    -
    -
    -

    render removes the identation in docstrings. This is particularly important +

    >>> tpl = '''
    +... A new string
    +...
    +... '''
    +>>> tpl
    +... '\nA new string\n\n'
    +>>> render(tpl)
    +... 'A new string\n'
    +
    +

    render removes the identation in docstrings. This is particularly important when using prompt functions

    -
    -
    -
    -

    tpl = ''' -... a string -... and another string''' -tpl -... '\n a string\n and another string' -render(tpl) -... 'a string\nand another string'

    -
    -
    -
    -

    The indentation of the first line is assumed to be the same as the second line's

    -
    -
    -
    -

    tpl = '''a string -... and another''' -tpl -... 'a string\n and another' -render(tpl) -... 'a string\nand another'

    -
    -
    -
    -

    To get a different indentation for the first and the second line, we can start the +

    >>> tpl = '''
    +...    a string
    +...    and another string'''
    +>>> tpl
    +... '\n   a string\n   and another string'
    +>>> render(tpl)
    +... 'a string\nand another string'
    +
    +

    The indentation of the first line is assumed to be the same as the second line's

    +
    >>> tpl = '''a string
    +...     and another'''
    +>>> tpl
    +... 'a string\n    and another'
    +>>> render(tpl)
    +... 'a string\nand another'
    +
    +

    To get a different indentation for the first and the second line, we can start the prompt on the string's second line:

    -
    -
    -
    -

    tpl = ''' -... First line -... Second line''' -render(tpl) -... 'First Line\n Second Line'

    -
    -
    -
    -

    Parameters

    -

    template - A string that contains a template written with the Jinja2 syntax. -**values - Map from the variables in the template to their value.

    -

    Returns

    -

    A string that contains the rendered template.

    +
    >>> tpl = '''
    +... First line
    +...   Second line'''
    +>>> render(tpl)
    +... 'First Line\n  Second Line'
    +
    + + +

    Parameters:

    + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescriptionDefault
    + template + + str + +
    +

    A string that contains a template written with the Jinja2 syntax.

    +
    +
    + required +
    + **values + + Optional[Dict[str, Any]] + +
    +

    Map from the variables in the template to their value.

    +
    +
    + {} +
    + + +

    Returns:

    + + + + + + + + + + + + + +
    TypeDescription
    + A string that contains the rendered template. + +
    + +
    +
    Source code in outlines/prompts.py diff --git a/main/api/regex/index.html b/main/api/regex/index.html index ef7ff2044..22611071e 100644 --- a/main/api/regex/index.html +++ b/main/api/regex/index.html @@ -2193,30 +2193,6 @@ - - @@ -2480,30 +2456,6 @@ - - @@ -2562,18 +2514,103 @@

    Generate structured text in the language of a regular expression.

    -

    Parameters

    -

    model: - An instance of Transformer that represents a model from the - transformers library. -regex_str: - The regular expression that the output must follow. -sampler: - The sampling algorithm to use to generate token ids from the logits - distribution.

    -

    Returns

    -

    A SequenceGeneratorAdapter instance that generates text constrained by the -regular expression.

    + + +

    Parameters:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescriptionDefault
    + model + + +
    +

    An instance of Transformer that represents a model from the +transformers library.

    +
    +
    + required +
    + regex_str + + str + +
    +

    The regular expression that the output must follow.

    +
    +
    + required +
    + sampler + + Sampler + +
    +

    The sampling algorithm to use to generate token ids from the logits +distribution.

    +
    +
    + multinomial() +
    + + +

    Returns:

    + + + + + + + + + + + + + + + + + +
    TypeDescription
    + A `SequenceGeneratorAdapter` instance that generates text constrained by the + +
    + +
    +
    + regular expression. + +
    + +
    +
    Source code in outlines/generate/regex.py diff --git a/main/api/samplers/index.html b/main/api/samplers/index.html index ccb63b321..1e8a16863 100644 --- a/main/api/samplers/index.html +++ b/main/api/samplers/index.html @@ -2217,15 +2217,6 @@