From 30d3cda000bacecfb70995b96a3e3f9b5d8d98b1 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Fri, 6 Oct 2023 16:13:05 -0700 Subject: [PATCH] Added CLI (#2) * Added CLI interface * Added check on OpenAI key --- .ruff.toml | 2 ++ sanclone/main.py | 37 +++++++++++++++++++++++++++++++++++++ setup.py | 3 ++- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .ruff.toml create mode 100644 sanclone/main.py diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 0000000..6802919 --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,2 @@ +# Allow lines to be as long as 120 characters. +line-length = 120 diff --git a/sanclone/main.py b/sanclone/main.py new file mode 100644 index 0000000..cdcf136 --- /dev/null +++ b/sanclone/main.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +import click + +WELCOME = """ +Welcome to San Clone 👋 a molecular cloning agent 🧬. +Give it an instruction like "Clone NADH Oxidase from Streptococcus pyogenes into the pET16b" +and press ✨ enter ✨ +""" + + +@click.command() +def main(): + # check openai key + try: + from langchain.llms import OpenAI + + OpenAI(model="babbage-002") + except Exception as e: + if "OPENAI_API_KEY" in str(e): + print("You need to set your OPENAI_API_KEY environment variable.") + print("You can get one from https://beta.openai.com/") + print("Then run the following command:") + print("export OPENAI_API_KEY=") + print("You can add this to your ~/.bashrc or ~/.bash_profile") + return + print(WELCOME) + while True: + instruction = input(">") + if instruction == "exit" or instruction == "quit" or instruction == "q": + print("Goodbye 👋") + break + else: + pass + + +if __name__ == "__main__": + main() diff --git a/setup.py b/setup.py index 657fa61..a21420f 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,8 @@ url="https://github.com/whitead/sanclone", license="MIT", packages=["sanclone", "sanclone.tools"], - install_requires=["langchain", "biopython"], + install_requires=["langchain", "biopython", "click"], + entry_points={"console_scripts": ["sanclone = sanclone.main:main"]}, test_suite="tests", long_description=long_description, long_description_content_type="text/markdown",