diff --git a/src/canopy_cli/cli.py b/src/canopy_cli/cli.py index af1c6b1f..ecd691c7 100644 --- a/src/canopy_cli/cli.py +++ b/src/canopy_cli/cli.py @@ -577,20 +577,34 @@ def stop(url): """ ) ) -def api_docs(): - import json - from canopy_cli import HTML_TEMPLATE - from canopy_server.app import app - # generate docs - - filename = "canopy-api-docs.html" - - with open(filename, "w") as fd: - print(HTML_TEMPLATE % json.dumps(app.openapi()), file=fd) - +@click.option("--url", default="http://0.0.0.0:8000", + help="Canopy's service url. Defaults to http://0.0.0.0:8000") +def api_docs(url): import webbrowser - webbrowser.open('file://' + os.path.realpath(filename)) + generated_docs = False + try: + check_service_health(url) + except CLIError: + msg = (f"Canopy server is not running. Would you like to generate the docs " + f"to a local HTML file?") + click.confirm(click.style(msg, fg="red"), abort=True) + generated_docs = True + + if generated_docs: + import json + from canopy_cli import HTML_TEMPLATE + from canopy_server.app import app + # generate docs + + filename = "canopy-api-docs.html" + msg = f"Generating docs to {filename}" + click.echo(click.style(msg, fg="green")) + with open(filename, "w") as fd: + print(HTML_TEMPLATE % json.dumps(app.openapi()), file=fd) + webbrowser.open('file://' + os.path.realpath(filename)) + else: + webbrowser.open('http://localhost:8000/redoc') if __name__ == "__main__": diff --git a/src/canopy_server/__init__.py b/src/canopy_server/__init__.py index 9ca26cbd..8b137891 100644 --- a/src/canopy_server/__init__.py +++ b/src/canopy_server/__init__.py @@ -1,14 +1 @@ -description = """ -Canopy is an open-source Retrieval Augmented Generation (RAG) framework and context engine built on top of the Pinecone vector database. Canopy enables you to quickly and easily experiment with and build applications using RAG. Start chatting with your documents or text data with a few simple commands. -Canopy provides a configurable built-in server, so you can effortlessly deploy a RAG-powered chat application to your existing chat UI or interface. Or you can build your own custom RAG application using the Canopy library. - -## Prerequisites - -### Pinecone API key -If you don't have a Pinecone account, you can sign up for a free Starter plan at https://www.pinecone.io/. -To find your Pinecone API key and environment log into Pinecone console (https://app.pinecone.io/). You can access your API key from the "API Keys" section in the sidebar of your dashboard, and find the environment name next to it. - -### OpenAI API key -You can find your free trial OpenAI API key https://platform.openai.com/account/api-keys. You might need to log in or register for OpenAI services. -""" # noqa: E501 diff --git a/src/canopy_server/app.py b/src/canopy_server/app.py index 26367591..3341c7bb 100644 --- a/src/canopy_server/app.py +++ b/src/canopy_server/app.py @@ -40,7 +40,6 @@ from canopy.llm.openai import OpenAILLM from canopy_cli.errors import ConfigError -from canopy_server import description from canopy import __version__ @@ -49,9 +48,25 @@ load_dotenv() # load env vars before import of openai openai.api_key = os.getenv("OPENAI_API_KEY") +APP_DESCRIPTION = """ +Canopy is an open-source Retrieval Augmented Generation (RAG) framework and context engine built on top of the Pinecone vector database. Canopy enables you to quickly and easily experiment with and build applications using RAG. Start chatting with your documents or text data with a few simple commands. + +Canopy provides a configurable built-in server, so you can effortlessly deploy a RAG-powered chat application to your existing chat UI or interface. Or you can build your own custom RAG application using the Canopy library. + +## Prerequisites + +### Pinecone API key +If you don't have a Pinecone account, you can sign up for a free Starter plan at https://www.pinecone.io/. +To find your Pinecone API key and environment log into Pinecone console (https://app.pinecone.io/). You can access your API key from the "API Keys" section in the sidebar of your dashboard, and find the environment name next to it. + +### OpenAI API key +You can find your free trial OpenAI API key https://platform.openai.com/account/api-keys. You might need to log in or register for OpenAI services. +""" # noqa: E501 + + app = FastAPI( title="Canopy API", - description=description, + description=APP_DESCRIPTION, version=__version__, license_info={ "name": "Apache 2.0",