mirror of
https://github.com/placeholder-soft/chroma.git
synced 2026-01-12 22:44:55 +08:00
This proposes an initial CLI The CLI is installed when you installed `pip install chromadb`. You then call the CLI with `chroma run --path <persist_dir> --port <port>` where path and port are optional. This also adds `chroma help` and `chroma docs` as convenience links - but I'm open to removing those. To make this easy - I added `typer` (by the author of FastAPI). I'm not sure this is the tool that we want to commit to for a fuller featured CLI, but given the extremely minimal footprint of this - I don't think it's a one way door. <img width="1477" alt="Screenshot 2023-08-23 at 4 59 54 PM" src="https://github.com/chroma-core/chroma/assets/891664/30374228-d303-41e1-8e9e-188b7f8532d4"> *** #### TODO - [x] test in fresh env - i think i need to add `typer` as a req - [ ] consider expanding the test to make sure the service is actually running - [x] hide the test option from the typer UI - [x] linking to a getting started guide could be interesting at the top of the logs
88 lines
2.7 KiB
Python
88 lines
2.7 KiB
Python
import typer
|
|
import uvicorn
|
|
import os
|
|
import webbrowser
|
|
|
|
app = typer.Typer()
|
|
|
|
_logo = """
|
|
\033[38;5;069m((((((((( \033[38;5;203m(((((\033[38;5;220m####
|
|
\033[38;5;069m(((((((((((((\033[38;5;203m(((((((((\033[38;5;220m#########
|
|
\033[38;5;069m(((((((((((((\033[38;5;203m(((((((((((\033[38;5;220m###########
|
|
\033[38;5;069m((((((((((((((\033[38;5;203m((((((((((((\033[38;5;220m############
|
|
\033[38;5;069m(((((((((((((\033[38;5;203m((((((((((((((\033[38;5;220m#############
|
|
\033[38;5;069m(((((((((((((\033[38;5;203m((((((((((((((\033[38;5;220m#############
|
|
\033[38;5;069m((((((((((((\033[38;5;203m(((((((((((((\033[38;5;220m##############
|
|
\033[38;5;069m((((((((((((\033[38;5;203m((((((((((((\033[38;5;220m##############
|
|
\033[38;5;069m((((((((((\033[38;5;203m(((((((((((\033[38;5;220m#############
|
|
\033[38;5;069m((((((((\033[38;5;203m((((((((\033[38;5;220m##############
|
|
\033[38;5;069m(((((\033[38;5;203m(((( \033[38;5;220m#########\033[0m
|
|
|
|
"""
|
|
|
|
|
|
@app.command() # type: ignore
|
|
def run(
|
|
path: str = typer.Option(
|
|
"./chroma_data", help="The path to the file or directory."
|
|
),
|
|
port: int = typer.Option(8000, help="The port to run the server on."),
|
|
test: bool = typer.Option(False, help="Test mode.", show_envvar=False, hidden=True),
|
|
) -> None:
|
|
"""Run a chroma server"""
|
|
|
|
print("\033[1m") # Bold logo
|
|
print(_logo)
|
|
print("\033[1m") # Bold
|
|
print("Running Chroma")
|
|
print("\033[0m") # Reset
|
|
|
|
typer.echo(f"\033[1mSaving data to\033[0m: \033[32m{path}\033[0m")
|
|
typer.echo(
|
|
f"\033[1mConnect to chroma at\033[0m: \033[32mhttp://localhost:{port}\033[0m"
|
|
)
|
|
typer.echo(
|
|
"\033[1mGetting started guide\033[0m: https://docs.trychroma.com/getting-started\n\n"
|
|
)
|
|
|
|
# set ENV variable for PERSIST_DIRECTORY to path
|
|
os.environ["IS_PERSISTENT"] = "True"
|
|
os.environ["PERSIST_DIRECTORY"] = path
|
|
|
|
# get the path where chromadb is installed
|
|
chromadb_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
# this is the path of the CLI, we want to move up one directory
|
|
chromadb_path = os.path.dirname(chromadb_path)
|
|
|
|
config = {
|
|
"app": "chromadb.app:app",
|
|
"host": "0.0.0.0",
|
|
"port": port,
|
|
"workers": 1,
|
|
"log_config": f"{chromadb_path}/log_config.yml",
|
|
}
|
|
|
|
if test:
|
|
return
|
|
|
|
uvicorn.run(**config)
|
|
|
|
|
|
@app.command() # type: ignore
|
|
def help() -> None:
|
|
"""Opens help url in your browser"""
|
|
|
|
webbrowser.open("https://discord.gg/MMeYNTmh3x")
|
|
|
|
|
|
@app.command() # type: ignore
|
|
def docs() -> None:
|
|
"""Opens docs url in your browser"""
|
|
|
|
webbrowser.open("https://docs.trychroma.com")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app()
|