From 96167b7ab8e2b796f942ea2e8e66a94e79f31363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Louf?= Date: Thu, 22 Feb 2024 15:11:27 +0100 Subject: [PATCH 1/2] WIP - Update the `Function` class --- outlines/function.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/outlines/function.py b/outlines/function.py index 48577be8f..4e86c692d 100644 --- a/outlines/function.py +++ b/outlines/function.py @@ -3,6 +3,7 @@ from typing import TYPE_CHECKING, Callable, Optional, Tuple, Union import requests +from pydantic import RootModel from outlines import generate, models @@ -11,6 +12,30 @@ from outlines.prompts import Prompt +class NewFunction: + """Represents an Outlines function. + + Functions are a convenient way to encapsulate a prompt template, a language + model and a Pydantic model that define the output structure. Once defined, + the function can be called with arguments that will be used to render the + prompt template. + + """ + + model: str + prompt_template: Optional[Callable] = None + pydantic_schema: Optional[RootModel] = None + + def prompt(self, fn: Callable): + pass + + def schema(self, model: RootModel): + pass + + def __call__(self, *args, **kwargs): + pass + + @dataclass class Function: """Represents an Outlines function. From fb98199c0d47d7bad8d52b12b667a5018335b139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Louf?= Date: Thu, 22 Feb 2024 15:02:13 +0100 Subject: [PATCH 2/2] Add CLI wireframe --- outlines/serve/main.py | 42 ++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 8 ++++++++ 2 files changed, 50 insertions(+) create mode 100644 outlines/serve/main.py diff --git a/outlines/serve/main.py b/outlines/serve/main.py new file mode 100644 index 000000000..a230750e6 --- /dev/null +++ b/outlines/serve/main.py @@ -0,0 +1,42 @@ +import typer +from typing_extensions import Annotated + +from outlines.function import extract_function_from_file + +app = typer.Typer( + no_args_is_help=True, help="Serve Outlines functions as APIs", add_completion=False +) + + +@app.command() +def serve( + path: Annotated[ + str, + typer.Argument(help="Path to the script that defines the Outlines function."), + ], + name: Annotated[ + str, + typer.Option("--name", "-n", help="The name of the function in the script."), + ] = "fn", + port: Annotated[ + int, + typer.Option("--port", "-p", help="Port to serve the function locally"), + ] = 8000, +): + """Serve the Outlines function.""" + + with open(path) as file: + content = file.read() + + _ = extract_function_from_file(content, name) + + # 1. Load the file and import objects + # 2. Find the function by its name + # 3. Create an API based on the prompt function's parameters and model name + # 4. Return example of calling the API + + print(f"{path}{port}{name}") + + +def main(): + app() diff --git a/pyproject.toml b/pyproject.toml index d131e8453..102334937 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,6 +65,7 @@ serve = [ "uvicorn", "fastapi", "pydantic>=2.0", + "typer[all]", ] [project.urls] @@ -76,6 +77,9 @@ repository = "https://github.com/outlines-dev/outlines" file="README.md" content-type = "text/markdown" +[project.scripts] +outlines = "outlines.serve.main:main" + [tool.setuptools] packages = ["outlines"] @@ -95,6 +99,9 @@ filterwarnings = [ "ignore::UserWarning", ] +[tool.poetry.scripts] +rick-portal-gun = "rick_portal_gun.main:app" + [tool.mypy] exclude=["examples"] @@ -117,6 +124,7 @@ module = [ "tiktoken.*", "torch.*", "transformers.*", + "typer.*", "llama_cpp", "huggingface_hub", "lark.*",