|
| 1 | +import typer |
| 2 | +import uvicorn |
| 3 | +import os |
| 4 | +import webbrowser |
| 5 | + |
| 6 | +app = typer.Typer() |
| 7 | + |
| 8 | +_logo = """ |
| 9 | + \033[38;5;069m((((((((( \033[38;5;203m(((((\033[38;5;220m#### |
| 10 | + \033[38;5;069m(((((((((((((\033[38;5;203m(((((((((\033[38;5;220m######### |
| 11 | + \033[38;5;069m(((((((((((((\033[38;5;203m(((((((((((\033[38;5;220m########### |
| 12 | + \033[38;5;069m((((((((((((((\033[38;5;203m((((((((((((\033[38;5;220m############ |
| 13 | + \033[38;5;069m(((((((((((((\033[38;5;203m((((((((((((((\033[38;5;220m############# |
| 14 | + \033[38;5;069m(((((((((((((\033[38;5;203m((((((((((((((\033[38;5;220m############# |
| 15 | + \033[38;5;069m((((((((((((\033[38;5;203m(((((((((((((\033[38;5;220m############## |
| 16 | + \033[38;5;069m((((((((((((\033[38;5;203m((((((((((((\033[38;5;220m############## |
| 17 | + \033[38;5;069m((((((((((\033[38;5;203m(((((((((((\033[38;5;220m############# |
| 18 | + \033[38;5;069m((((((((\033[38;5;203m((((((((\033[38;5;220m############## |
| 19 | + \033[38;5;069m(((((\033[38;5;203m(((( \033[38;5;220m#########\033[0m |
| 20 | +
|
| 21 | + """ |
| 22 | + |
| 23 | + |
| 24 | +@app.command() # type: ignore |
| 25 | +def run( |
| 26 | + path: str = typer.Option( |
| 27 | + "./chroma_data", help="The path to the file or directory." |
| 28 | + ), |
| 29 | + port: int = typer.Option(8000, help="The port to run the server on."), |
| 30 | + test: bool = typer.Option(False, help="Test mode.", show_envvar=False, hidden=True), |
| 31 | +) -> None: |
| 32 | + """Run a chroma server""" |
| 33 | + |
| 34 | + print("\033[1m") # Bold logo |
| 35 | + print(_logo) |
| 36 | + print("\033[1m") # Bold |
| 37 | + print("Running Chroma") |
| 38 | + print("\033[0m") # Reset |
| 39 | + |
| 40 | + typer.echo(f"\033[1mSaving data to\033[0m: \033[32m{path}\033[0m") |
| 41 | + typer.echo( |
| 42 | + f"\033[1mConnect to chroma at\033[0m: \033[32mhttp://localhost:{port}\033[0m" |
| 43 | + ) |
| 44 | + typer.echo( |
| 45 | + "\033[1mGetting started guide\033[0m: https://docs.trychroma.com/getting-started\n\n" |
| 46 | + ) |
| 47 | + |
| 48 | + # set ENV variable for PERSIST_DIRECTORY to path |
| 49 | + os.environ["IS_PERSISTENT"] = "True" |
| 50 | + os.environ["PERSIST_DIRECTORY"] = path |
| 51 | + |
| 52 | + # get the path where chromadb is installed |
| 53 | + chromadb_path = os.path.dirname(os.path.realpath(__file__)) |
| 54 | + |
| 55 | + # this is the path of the CLI, we want to move up one directory |
| 56 | + chromadb_path = os.path.dirname(chromadb_path) |
| 57 | + |
| 58 | + config = { |
| 59 | + "app": "chromadb.app:app", |
| 60 | + "host": "0.0.0.0", |
| 61 | + "port": port, |
| 62 | + "workers": 1, |
| 63 | + "log_config": f"{chromadb_path}/log_config.yml", |
| 64 | + } |
| 65 | + |
| 66 | + if test: |
| 67 | + return |
| 68 | + |
| 69 | + uvicorn.run(**config) |
| 70 | + |
| 71 | + |
| 72 | +@app.command() # type: ignore |
| 73 | +def help() -> None: |
| 74 | + """Opens help url in your browser""" |
| 75 | + |
| 76 | + webbrowser.open("https://discord.gg/MMeYNTmh3x") |
| 77 | + |
| 78 | + |
| 79 | +@app.command() # type: ignore |
| 80 | +def docs() -> None: |
| 81 | + """Opens docs url in your browser""" |
| 82 | + |
| 83 | + webbrowser.open("https://docs.trychroma.com") |
| 84 | + |
| 85 | + |
| 86 | +if __name__ == "__main__": |
| 87 | + app() |
0 commit comments