Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
[app] Made generating the docs optional
Browse files Browse the repository at this point in the history
This way they are only generated if the user want to generate them locally
  • Loading branch information
igiloh-pinecone committed Nov 5, 2023
1 parent 3d16600 commit 2bbba59
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 27 deletions.
38 changes: 26 additions & 12 deletions src/canopy_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
13 changes: 0 additions & 13 deletions src/canopy_server/__init__.py
Original file line number Diff line number Diff line change
@@ -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
19 changes: 17 additions & 2 deletions src/canopy_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__


Expand All @@ -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",
Expand Down

0 comments on commit 2bbba59

Please sign in to comment.