Skip to content

Commit

Permalink
Add CLI wireframe
Browse files Browse the repository at this point in the history
  • Loading branch information
rlouf committed Feb 22, 2024
1 parent 96167b7 commit fb98199
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
42 changes: 42 additions & 0 deletions outlines/serve/main.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ serve = [
"uvicorn",
"fastapi",
"pydantic>=2.0",
"typer[all]",
]

[project.urls]
Expand All @@ -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"]

Expand All @@ -95,6 +99,9 @@ filterwarnings = [
"ignore::UserWarning",
]

[tool.poetry.scripts]
rick-portal-gun = "rick_portal_gun.main:app"

[tool.mypy]
exclude=["examples"]

Expand All @@ -117,6 +124,7 @@ module = [
"tiktoken.*",
"torch.*",
"transformers.*",
"typer.*",
"llama_cpp",
"huggingface_hub",
"lark.*",
Expand Down

0 comments on commit fb98199

Please sign in to comment.