From 466ec4e4b48f1d9d760996e6a84718c15dfdeb7f Mon Sep 17 00:00:00 2001 From: Javier Luraschi Date: Fri, 10 May 2024 12:21:46 -0700 Subject: [PATCH] cli entries for create run deploy --- .githooks/pre-commit | 13 ---------- .vscode/launch.json | 29 --------------------- README.md | 48 ++++++++++++++++++++++++----------- python/hal9/__init__.py | 2 +- python/hal9/api.py | 56 +++++++++++++++++++++++++++++++++++++++++ python/hal9/cli.py | 50 ++++++++++++++++++++++++++++++++++++ python/hal9/core.py | 41 ------------------------------ python/pyproject.toml | 6 ++++- 8 files changed, 146 insertions(+), 99 deletions(-) delete mode 100755 .githooks/pre-commit delete mode 100644 .vscode/launch.json create mode 100644 python/hal9/api.py create mode 100644 python/hal9/cli.py delete mode 100644 python/hal9/core.py diff --git a/.githooks/pre-commit b/.githooks/pre-commit deleted file mode 100755 index 760cc324..00000000 --- a/.githooks/pre-commit +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -# You can use this pre-commit hook by directing Git to look -# for hooks in this directory using the following command -# at the repository root: git config core.hooksPath .githooks - -# Prevent commits with BLOCK_GIT_COMMIT as an addtion in the staged diff -BLOCK_GIT_COMMIT_STRING='BLOCK_GIT_COMMIT' -if git diff --staged | grep -q "^+.*$BLOCK_GIT_COMMIT_STRING" -then - echo "Git commit blocker string detected: $BLOCK_GIT_COMMIT_STRING" - exit 1 -fi diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 665993f2..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - - { - "type": "lldb", - "request": "launch", - "name": "Debug", - "program": "${workspaceFolder}/server/target/debug/hal9", - "args": [ - "start", - "server/examples/my_app" - ], - "cwd": "${workspaceFolder}" - }, - { - "cwd": "${workspaceFolder}/py/", - "name": "Python: Current File", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal", - "justMyCode": true - } - ] -} \ No newline at end of file diff --git a/README.md b/README.md index 533ca648..2518e78d 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ -# Hal9: Create and Deploy GenAI Chatbots +# Hal9: Create and Share Generative Apps [![Hal9 PyPi Downloads](https://img.shields.io/pypi/dm/hal9?label=PyPI)](https://pypi.org/project/hal9/) -Create and deploy Large Language Model (LLM) chatbots in seconds. -- **Open:** Use any LLM like OpenAI, LLama, Gemini, Groq, etc. and open libraries like LangChain. -- **Intuitive:** No need to learn a chat framework, simply use stdin and stdout. -- **Scalable:** Engineers can esily integrate your chatbot with Docker or use Hal9's self-service enterprise cloud. +Create and deploy generative (LLMs and [difussers](https://github.com/huggingface/diffusers)) applications (chatbots and APIs) in seconds. +- **Open:** Use any model (OpenAI, Llama, Groq, Midjourney) and any library like (LangChainl, DSPy). +- **Intuitive:** No need to learn an app framework (streamlit, flask), simply use stdin and stdout. +- **Scalable:** Engineers can esily integrate your app with Docker or use Hal9's self-service enterprise cloud. + +Focus on AI (RAG, fine-tuning, aligment, training) and skip engineering tasks (frontend development, backend integration, deployment, operations). ## Getting started @@ -14,22 +16,25 @@ To create and deploy a chatbot in 10 seconds run the following: ```bash pip install hal9 -hal9 create my-project -hal9 deploy my-project +hal9 create chatbot +hal9 deploy chatbot ``` -To customize, read the following sections. +To customize further, read the following sections. ## Creation -By default `hal9 create` we will use OpenAI, you can choose your template as follows: +By default `hal9 create` we will use the OpenAI template, you can choose different ones as follows: ```bash hal9 create my-project --template openai +hal9 create my-project --template midjourney hal9 create my-project --template groq hal9 create my-project --template langchain ``` +A template provides ready to use code with specific technologies and use cases. If you already have code, you can skip this step. + Send a PR if you want to add additional templates. ## Development @@ -44,20 +49,29 @@ cd my-project pip install -r requirements.txt export OPENAI_KEY=YOUR_OPENAI_KEY -python app.py ``` If you customized your template with `--template` make sure to set the correct key, for example `export GROQ_KEY=YOUR_GROQ_KEY`. ## Runtime +Run your application as follows, + +```python +python app.py +``` + Use the command line tool to enter prompts, type `` twice to send the prompt to your code. Replies will be streamed back to console. -We decided to use a simple chat interface to help AI teams focus what matters: Retrieval Augmented Generation (RAG) workflows. The interactivity and backend can be left to the engineering team or services like Hal9. +From the parent folder, you can also run your application as follows: + +```bash +hal9 run my-project +``` ## Deployment -We currently support Docker and Hal9 Cloud, but community can send PR's with additional technologies or providers. +We currently support Docker and `hal9.com`. Developers can send PR's with additional technologies or providers. ### Docker @@ -72,8 +86,14 @@ Your backend and frontend engineers can then easily consume this as an API. You ### Hal9 -To deploy to Hal9's cloud run: +To deploy to `hal9.com` run: + +```bash +hal9 deploy my-project --target hal9.com +``` + +When Hal9 runs in your own cloud you can replace `--target hal9.com` with the correct domain, for example: ```bash -hal9 deploy my-project --email email@email.com +hal9 deploy my-project --target hal9.acme.com ``` diff --git a/python/hal9/__init__.py b/python/hal9/__init__.py index 4f1f5580..a3bd8c0f 100644 --- a/python/hal9/__init__.py +++ b/python/hal9/__init__.py @@ -1 +1 @@ -from hal9.core import * +from hal9.api import * diff --git a/python/hal9/api.py b/python/hal9/api.py new file mode 100644 index 00000000..bb630cc1 --- /dev/null +++ b/python/hal9/api.py @@ -0,0 +1,56 @@ +import requests +import time +import tempfile +import sys +import runpy + +def create(path :str, template :str) -> str: + """Create an application + + Parameters + ---------- + path : str + Path to the application. + template : str + The template to use. + """ + + print(f'Project created! {name}') + +def run(path :str) -> str: + """Run an application + + Parameters + ---------- + path : str + Path to the application. + """ + + print(f'Project created! {name}') + +def deploy(path :str, target :str) -> str: + """Deploy an application + + Parameters + ---------- + path : str + Path to the application. + target : str + The deployment target, defaults to 'hal9.com'. + """ + + response = requests.post('https://api.hal9.com/api/v1/deploy', json = { + 'name': 'name', + 'title': 'title', + 'description': 'description', + 'access': 'access', + 'code': 'code', + 'prompt': 'prompt', + 'thumbnail': 'thumbnail', + 'token': 'token', + 'user': 'user', + }) + + if not response.ok: + print('Failed to deploy') + exit() \ No newline at end of file diff --git a/python/hal9/cli.py b/python/hal9/cli.py new file mode 100644 index 00000000..2a1a71e4 --- /dev/null +++ b/python/hal9/cli.py @@ -0,0 +1,50 @@ +import click +from collections import OrderedDict +from hal9.api import * + +@click.group() +def cli(): + """ + Create and Deploy Generative Applications + + Use this tool to create apps from templates that use Generative AI, + run them locally and deploy them to the cloud. + """ + pass + +@click.command() +@click.argument('path') +def create(path): + """ + Create Project + + PATH: The path for the new project. Required argument. + """ + print(f'Creating: {path}') + +@click.command() +@click.argument('path') +def run(path): + """ + Run Project + + PATH: The path to the project. Required argument. + """ + print(f'Running {path}') + +@click.command() +@click.argument('path') +def deploy(path): + """ + Deploy Project + + PATH: The path to the project. Required argument. + """ + print(f'Deploying {path}') + +cli.add_command(create) +cli.add_command(run) +cli.add_command(deploy) + +if __name__ == "__main__": + cli() \ No newline at end of file diff --git a/python/hal9/core.py b/python/hal9/core.py deleted file mode 100644 index f816729c..00000000 --- a/python/hal9/core.py +++ /dev/null @@ -1,41 +0,0 @@ -import requests -import time -import tempfile -import sys -import runpy - -def create(template :str) -> str: - """Create an app for the given template - - Parameters - ---------- - template : str - The template to use to create the project. - """ - -def deploy(project :str, destination :str) -> str: - """Deploy project to given destination - - Parameters - ---------- - project : str - The project name used to deploy the app. - destination : str - The deployment destination, defaults to Hal9. - """ - - response = requests.post('https://api.hal9.com/api/v1/deploy', json = { - 'name': 'name', - 'title': 'title', - 'description': 'description', - 'access': 'access', - 'code': 'code', - 'prompt': 'prompt', - 'thumbnail': 'thumbnail', - 'token': 'token', - 'user': 'user', - }) - - if not response.ok: - print('Failed to deploy') - exit() \ No newline at end of file diff --git a/python/pyproject.toml b/python/pyproject.toml index db617873..278900a3 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "hal9" -version = "2.0.0" +version = "2.0.1" description = "" authors = ["Javier Luraschi "] readme = "README.md" @@ -9,6 +9,10 @@ readme = "README.md" python = ">=3.8,<3.9.7 || >3.9.7,<4.0" requests = "^2.28.2" +click = "^8.1.7" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" + +[tool.poetry.scripts] +hal9 = "hal9.cli:cli" \ No newline at end of file