diff --git a/outlines/models/anthropic.py b/outlines/models/anthropic.py index c2fbe66fa..830c0cf77 100644 --- a/outlines/models/anthropic.py +++ b/outlines/models/anthropic.py @@ -11,9 +11,11 @@ class AnthropicTypeAdapter(ModelTypeAdapter): """Type adapter for the Anthropic clients. - `AnthropicTypeAdapter` is responsible for preparing the arguments to Anthropic's - `messages.create` methods: the input (prompt and possibly image). - Anthropic does not support defining the output type, so `format_output_type` is not implemented. + `AnthropicTypeAdapter` is responsible for preparing the arguments to + Anthropic's `messages.create` methods: the input (prompt and possibly + image). + Anthropic does not support defining the output type, so + `format_output_type` is not implemented. """ diff --git a/outlines/models/base.py b/outlines/models/base.py index c1a6b9808..0a76f3e3c 100644 --- a/outlines/models/base.py +++ b/outlines/models/base.py @@ -8,27 +8,31 @@ class ModelTypeAdapter(ABC): A type adapter instance must be given as a value to the `type_adapter` attribute when instantiating a model. The type adapter is responsible for formatting the input and output types - passed to the model to match the specific format expected by the associated model. + passed to the model to match the specific format expected by the + associated model. """ @abstractmethod def format_input(self, model_input): - """Format the user input to the expected input format of the model. + """Format the user input to the expected format of the model. - For API-based models, it typically means creating the `messages` argument passed to the client. - For local models, it can mean casting the input from str to list for instance. - This method is also used to validate that the input type provided by the user is supported by the model. + For API-based models, it typically means creating the `messages` + argument passed to the client. For local models, it can mean casting + the input from str to list for instance. + This method is also used to validate that the input type provided by + the user is supported by the model. """ ... @abstractmethod def format_output_type(self, output_type): - """Format the output type provided by the user to the expected output type format of the model. + """Format the output type to the expected format of the model. - For API-based models, this typically means creating a `response_format` argument. - For local models, it means formatting the logits processor to create the object type expected by the model. + For API-based models, this typically means creating a `response_format` + argument. For local models, it means formatting the logits processor to + create the object type expected by the model. """ ... @@ -37,10 +41,12 @@ def format_output_type(self, output_type): class Model(ABC): """Base class for all models. - This class defines a shared `__call__` method that can be used to call the model directly. - All models inheriting from this class must define a `type_adapter` attribute of type `ModelTypeAdapter`. - The methods of the `type_adapter` attribute are used in the `generate` method to format - the input and output types received by the model. + This class defines a shared `__call__` method that can be used to call the + model directly. + All models inheriting from this class must define a `type_adapter` + attribute of type `ModelTypeAdapter`. The methods of the `type_adapter` + attribute are used in the `generate` method to format the input and output + types received by the model. """ @@ -50,10 +56,9 @@ class Model(ABC): def __call__(self, model_input, output_type=None, **inference_kwargs): """Call the model. - Users can call the model directly, in which case we will create a generator instance with - the output type provided and call it. + Users can call the model directly, in which case we will create a + generator instance with the output type provided and call it. Thus, those commands are equivalent: - ```python generator = Generator(model, Foo) generator("prompt") @@ -72,8 +77,8 @@ def __call__(self, model_input, output_type=None, **inference_kwargs): def generate(self, model_input, output_type=None, **inference_kwargs): """Generate a response from the model. - The output_type argument contains a logits processor for local models while it contains - a type (Json, Enum...) for the API-based models. + The output_type argument contains a logits processor for local models + while it contains a type (Json, Enum...) for the API-based models. """ ... diff --git a/outlines/models/llamacpp.py b/outlines/models/llamacpp.py index 938b42582..6d8cd1ca5 100644 --- a/outlines/models/llamacpp.py +++ b/outlines/models/llamacpp.py @@ -98,9 +98,9 @@ def __setstate__(self, state): class LlamaCppTypeAdapter(ModelTypeAdapter): """Type adapter for the `llama-cpp-python` library. - `LlamaCppTypeAdapter` is responsible for preparing the arguments to `llama-cpp-python`'s - `Llama.__call__` method: the input (a string prompt), as well as the logits processor - (an instance of `LogitsProcessorList`). + `LlamaCppTypeAdapter` is responsible for preparing the arguments to + `llama-cpp-python`'s `Llama.__call__` method: the input (a string prompt), + as well as the logits processor (an instance of `LogitsProcessorList`). """ @@ -124,7 +124,7 @@ def format_str_input(self, model_input: str): return model_input def format_output_type(self, output_type): - """Generate the logits processor argument to pass to the model (a `LogitsProcessorList`). + """Generate the logits processor argument to pass to the model. Argument -------- diff --git a/outlines/models/openai.py b/outlines/models/openai.py index 2da81308c..376b6ce06 100644 --- a/outlines/models/openai.py +++ b/outlines/models/openai.py @@ -15,8 +15,8 @@ class OpenAITypeAdapter(ModelTypeAdapter): """Type adapter for the OpenAI clients. `OpenAITypeAdapter` is responsible for preparing the arguments to OpenAI's - `completions.create` methods: the input (prompt and possibly image), as well - as the output type (only JSON). + `completions.create` methods: the input (prompt and possibly image), as + well as the output type (only JSON). """