o
    ÓÙ¾i›  ã                   @   sŠ   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
 ddlmZ ee
ƒ fde	d	efd
d„ƒZe e¡e
ƒ fde	fdd„ƒZdS )é    )Úsingledispatch)Úpython_types_to_regex)ÚSequenceGeneratorAdapter)ÚOpenAI)ÚSamplerÚmultinomialé   )ÚregexÚsamplerÚreturnc                 C   s"   t |ƒ\}}t| ||ƒ}||_|S )aY  Generate structured data that can be parsed as a Python type.

    Parameters
    ----------
    model:
        An instance of `Transformer` that represents a model from the
        `transformers` library.
    python_type:
        A Python type. The output of the generator must be parseable into
        this type.
    sampler:
        The sampling algorithm to use to generate token ids from the logits
        distribution.

    Returns
    -------
    A `SequenceGenerator` instance that generates text constrained by the Python type
    and translates this text into the corresponding type.

    )r   r	   Úformat_sequence)ÚmodelÚpython_typer
   Ú	regex_strÚ	format_fnÚ	generator© r   úL/home/ubuntu/.local/lib/python3.10/site-packages/outlines/generate/format.pyÚformat   s   r   c                 C   s   t dƒ‚)NzkCannot use Python type-structured generation with an OpenAI model due to the limitations of the OpenAI API.)ÚNotImplementedError)r   r   r
   r   r   r   Úformat_openai*   s   ÿr   N)Ú	functoolsr   Úoutlines.fsm.typesr   Úoutlines.generate.apir   Úoutlines.modelsr   Úoutlines.samplersr   r   r	   r   Úregisterr   r   r   r   r   Ú<module>   s    ÿÿþ