Skip to content

Commit

Permalink
Uses emoji in its own column
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonWeill committed Apr 21, 2023
1 parent cdc6e04 commit d0ab4ab
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 26 deletions.
31 changes: 19 additions & 12 deletions examples/commands.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,19 @@
{
"data": {
"text/markdown": [
"| Provider | Environment variable | Models |\n",
"|----------|----------------------|--------|\n",
"| `ai21` | `AI21_API_KEY` | `ai21:j1-large`, `ai21:j1-grande`, `ai21:j1-jumbo`, `ai21:j1-grande-instruct`, `ai21:j2-large`, `ai21:j2-grande`, `ai21:j2-jumbo`, `ai21:j2-grande-instruct`, `ai21:j2-jumbo-instruct` |\n",
"| `anthropic` | `ANTHROPIC_API_KEY` | `anthropic:claude-v1`, `anthropic:claude-v1.0`, `anthropic:claude-v1.2`, `anthropic:claude-instant-v1`, `anthropic:claude-instant-v1.0` |\n",
"| `cohere` | `COHERE_API_KEY` | `cohere:medium`, `cohere:xlarge` |\n",
"| `huggingface_hub` | `HUGGINGFACEHUB_API_TOKEN` | This provider does not define a list of models. |\n",
"| `openai` | `OPENAI_API_KEY` | `openai:text-davinci-003`, `openai:text-davinci-002`, `openai:text-curie-001`, `openai:text-babbage-001`, `openai:text-ada-001`, `openai:davinci`, `openai:curie`, `openai:babbage`, `openai:ada` |\n",
"| `openai-chat` | `OPENAI_API_KEY` | `openai-chat:gpt-4`, `openai-chat:gpt-4-0314`, `openai-chat:gpt-4-32k`, `openai-chat:gpt-4-32k-0314`, `openai-chat:gpt-3.5-turbo`, `openai-chat:gpt-3.5-turbo-0301` |\n",
"| `sagemaker-endpoint` | *Not applicable.* | This provider does not define a list of models. |\n"
"| Provider | Environment variable | Set? | Models |\n",
"|----------|----------------------|------|--------|\n",
"| `ai21` | `AI21_API_KEY` | <abbr title=\"You have not set this environment variable, so you cannot use this provider's models.\">❌</abbr> | `ai21:j1-large`, `ai21:j1-grande`, `ai21:j1-jumbo`, `ai21:j1-grande-instruct`, `ai21:j2-large`, `ai21:j2-grande`, `ai21:j2-jumbo`, `ai21:j2-grande-instruct`, `ai21:j2-jumbo-instruct` |\n",
"| `anthropic` | `ANTHROPIC_API_KEY` | <abbr title=\"You have not set this environment variable, so you cannot use this provider's models.\">❌</abbr> | `anthropic:claude-v1`, `anthropic:claude-v1.0`, `anthropic:claude-v1.2`, `anthropic:claude-instant-v1`, `anthropic:claude-instant-v1.0` |\n",
"| `cohere` | `COHERE_API_KEY` | <abbr title=\"You have not set this environment variable, so you cannot use this provider's models.\">❌</abbr> | `cohere:medium`, `cohere:xlarge` |\n",
"| `huggingface_hub` | `HUGGINGFACEHUB_API_TOKEN` | <abbr title=\"You have not set this environment variable, so you cannot use this provider's models.\">❌</abbr> | This provider does not define a list of models. |\n",
"| `openai` | `OPENAI_API_KEY` | <abbr title=\"You have set this environment variable, so you can use this provider's models.\">✅</abbr> | `openai:text-davinci-003`, `openai:text-davinci-002`, `openai:text-curie-001`, `openai:text-babbage-001`, `openai:text-ada-001`, `openai:davinci`, `openai:curie`, `openai:babbage`, `openai:ada` |\n",
"| `openai-chat` | `OPENAI_API_KEY` | <abbr title=\"You have set this environment variable, so you can use this provider's models.\">✅</abbr> | `openai-chat:gpt-4`, `openai-chat:gpt-4-0314`, `openai-chat:gpt-4-32k`, `openai-chat:gpt-4-32k-0314`, `openai-chat:gpt-3.5-turbo`, `openai-chat:gpt-3.5-turbo-0301` |\n",
"| `sagemaker-endpoint` | Not applicable. | <abbr title=\"Not applicable\">N/A</abbr> | This provider does not define a list of models. |\n"
],
"text/plain": [
"ai21\n",
"Requires environment variable AI21_API_KEY (not set)\n",
"* ai21:j1-large\n",
"* ai21:j1-grande\n",
"* ai21:j1-jumbo\n",
Expand All @@ -128,20 +129,24 @@
"* ai21:j2-jumbo-instruct\n",
"\n",
"anthropic\n",
"Requires environment variable ANTHROPIC_API_KEY (not set)\n",
"* anthropic:claude-v1\n",
"* anthropic:claude-v1.0\n",
"* anthropic:claude-v1.2\n",
"* anthropic:claude-instant-v1\n",
"* anthropic:claude-instant-v1.0\n",
"\n",
"cohere\n",
"Requires environment variable COHERE_API_KEY (not set)\n",
"* cohere:medium\n",
"* cohere:xlarge\n",
"\n",
"huggingface_hub\n",
"Requires environment variable HUGGINGFACEHUB_API_TOKEN (not set)\n",
"* This provider does not define a list of models.\n",
"\n",
"openai\n",
"Requires environment variable OPENAI_API_KEY (set)\n",
"* openai:text-davinci-003\n",
"* openai:text-davinci-002\n",
"* openai:text-curie-001\n",
Expand All @@ -153,6 +158,7 @@
"* openai:ada\n",
"\n",
"openai-chat\n",
"Requires environment variable OPENAI_API_KEY (set)\n",
"* openai-chat:gpt-4\n",
"* openai-chat:gpt-4-0314\n",
"* openai-chat:gpt-4-32k\n",
Expand Down Expand Up @@ -183,12 +189,13 @@
{
"data": {
"text/markdown": [
"| Provider | Models |\n",
"|----------|--------|\n",
"| `openai` | `openai:text-davinci-003`, `openai:text-davinci-002`, `openai:text-curie-001`, `openai:text-babbage-001`, `openai:text-ada-001`, `openai:davinci`, `openai:curie`, `openai:babbage`, `openai:ada` |\n"
"| Provider | Environment variable | Set? | Models |\n",
"|----------|----------------------|------|--------|\n",
"| `openai` | `OPENAI_API_KEY` | <abbr title=\"You have set this environment variable, so you can use this provider's models.\">✅</abbr> | `openai:text-davinci-003`, `openai:text-davinci-002`, `openai:text-curie-001`, `openai:text-babbage-001`, `openai:text-ada-001`, `openai:davinci`, `openai:curie`, `openai:babbage`, `openai:ada` |\n"
],
"text/plain": [
"openai\n",
"Requires environment variable OPENAI_API_KEY (set)\n",
"* openai:text-davinci-003\n",
"* openai:text-davinci-002\n",
"* openai:text-curie-001\n",
Expand Down
31 changes: 24 additions & 7 deletions packages/jupyter-ai-magics/jupyter_ai_magics/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,36 @@ def _ai_inline_list_models_for_provider(self, provider_id, Provider):
# Is the required environment variable set?
def _ai_env_status_for_provider_markdown(self, provider_id):
if provider_id not in PROVIDER_ENV_VARS:
return 'Not applicable.'
return 'Not applicable. | <abbr title="Not applicable">N/A</abbr> ' # No emoji

env_var = PROVIDER_ENV_VARS[provider_id]
output = f"`{env_var}` "
if (os.getenv(env_var) != None):
output += "✅"
output = f"`{env_var}` | "
if (os.getenv(env_var) == None):
output += ("<abbr title=\"You have not set this environment variable, "
+ "so you cannot use this provider's models.\">❌</abbr>");
else:
output += "❌"
output += ("<abbr title=\"You have set this environment variable, "
+ "so you can use this provider's models.\">✅</abbr>");

return output

def _ai_env_status_for_provider_text(self, provider_id):
if provider_id not in PROVIDER_ENV_VARS:
return '' # No message necessary

env_var = PROVIDER_ENV_VARS[provider_id]
output = f"Requires environment variable {env_var} "
if (os.getenv(env_var) != None):
output += "(set)"
else:
output += "(not set)"

return output + "\n"


def _ai_list_command_markdown(self, single_provider=None):
output = ("| Provider | Environment variable | Models |\n"
+ "|----------|----------------------|--------|\n")
output = ("| Provider | Environment variable | Set? | Models |\n"
+ "|----------|----------------------|------|--------|\n")
if (single_provider is not None and single_provider not in self.providers):
return f"There is no model provider with ID `{single_provider}`.";

Expand All @@ -183,6 +199,7 @@ def _ai_list_command_text(self, single_provider=None):
continue;

output += (f"{provider_id}\n"
+ self._ai_env_status_for_provider_text(provider_id) # includes \n if nonblank
+ self._ai_bulleted_list_models_for_provider(provider_id, Provider))

return output
Expand Down
23 changes: 16 additions & 7 deletions packages/jupyter-ai-magics/jupyter_ai_magics/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
from pydantic import BaseModel, Extra
from langchain.chat_models import ChatOpenAI

PROVIDER_ENV_VARS = {
"ai21": "AI21_API_KEY",
"anthropic": "ANTHROPIC_API_KEY",
"cohere": "COHERE_API_KEY",
"huggingface_hub": "HUGGINGFACEHUB_API_TOKEN",
"openai": "OPENAI_API_KEY",
"openai-chat": "OPENAI_API_KEY",
"openai-chat-new": "OPENAI_API_KEY"
}

class EnvAuthStrategy(BaseModel):
"""Require one auth token via an environment variable."""
Expand Down Expand Up @@ -103,7 +112,7 @@ class AI21Provider(BaseProvider, AI21):
]
model_id_key = "model"
pypi_package_deps = ["ai21"]
auth_strategy = EnvAuthStrategy(name="AI21_API_KEY")
auth_strategy = EnvAuthStrategy(name=PROVIDER_ENV_VARS["ai21"])

class AnthropicProvider(BaseProvider, Anthropic):
id = "anthropic"
Expand All @@ -117,15 +126,15 @@ class AnthropicProvider(BaseProvider, Anthropic):
]
model_id_key = "model"
pypi_package_deps = ["anthropic"]
auth_strategy = EnvAuthStrategy(name="ANTHROPIC_API_KEY")
auth_strategy = EnvAuthStrategy(name=PROVIDER_ENV_VARS["anthropic"])

class CohereProvider(BaseProvider, Cohere):
id = "cohere"
name = "Cohere"
models = ["medium", "xlarge"]
model_id_key = "model"
pypi_package_deps = ["cohere"]
auth_strategy = EnvAuthStrategy(name="COHERE_API_KEY")
auth_strategy = EnvAuthStrategy(name=PROVIDER_ENV_VARS["cohere"])

class HfHubProvider(BaseProvider, HuggingFaceHub):
id = "huggingface_hub"
Expand All @@ -136,7 +145,7 @@ class HfHubProvider(BaseProvider, HuggingFaceHub):
# https://stackoverflow.com/questions/67998191
# tqdm is a dependency of huggingface_hub
pypi_package_deps = ["huggingface_hub", "ipywidgets"]
auth_strategy = EnvAuthStrategy(name="HUGGINGFACEHUB_API_TOKEN")
auth_strategy = EnvAuthStrategy(name=PROVIDER_ENV_VARS["huggingface_hub"])

class OpenAIProvider(BaseProvider, OpenAI):
id = "openai"
Expand All @@ -154,7 +163,7 @@ class OpenAIProvider(BaseProvider, OpenAI):
]
model_id_key = "model_name"
pypi_package_deps = ["openai"]
auth_strategy = EnvAuthStrategy(name="OPENAI_API_KEY")
auth_strategy = EnvAuthStrategy(name=PROVIDER_ENV_VARS["openai"])

class ChatOpenAIProvider(BaseProvider, OpenAIChat):
id = "openai-chat"
Expand All @@ -169,7 +178,7 @@ class ChatOpenAIProvider(BaseProvider, OpenAIChat):
]
model_id_key = "model_name"
pypi_package_deps = ["openai"]
auth_strategy = EnvAuthStrategy(name="OPENAI_API_KEY")
auth_strategy = EnvAuthStrategy(name=PROVIDER_ENV_VARS["openai-chat"])

def append_exchange(self, prompt: str, output: str):
"""Appends a conversational exchange between user and an OpenAI Chat
Expand Down Expand Up @@ -198,7 +207,7 @@ class ChatOpenAINewProvider(BaseProvider, ChatOpenAI):
]
model_id_key = "model_name"
pypi_package_deps = ["openai"]
auth_strategy = EnvAuthStrategy(name="OPENAI_API_KEY")
auth_strategy = EnvAuthStrategy(name=PROVIDER_ENV_VARS["openai-chat-new"])

class SmEndpointProvider(BaseProvider, SagemakerEndpoint):
id = "sagemaker-endpoint"
Expand Down

0 comments on commit d0ab4ab

Please sign in to comment.