Skip to content

Commit

Permalink
Register, update, and delete aliases (jupyterlab#136)
Browse files Browse the repository at this point in the history
* Validates registry name

* WIP: Register alias

* Raises exceptions

* Refactors, adds delete and update commands

* Additional examples

* Update sample notebook

* Update docs

* List aliases

* Refactoring

* Recommends using 'update' command

* WIP: Gets variable from user namespace, tests whether it's a chain

* Updates sample workbook, calls custom chain

* Updates user docs for aliases

* Edits sample notebook

* Alias list in text display, updates messaging

* Updates sample workbook

* Updates sample notebook, parsers to use click

* Additional cleanup

* Updates sample notebook, removes unahppy case

* Fix error from rebase, updates sample notebook

* Fixed error when --format is used

* Update docs/source/users/index.md

Co-authored-by: Piyush Jain <[email protected]>

* Update docs/source/users/index.md

Co-authored-by: Piyush Jain <[email protected]>

* Wraps ValueError exceptions to not print stack trace

---------

Co-authored-by: Piyush Jain <[email protected]>
  • Loading branch information
JasonWeill and 3coins authored Jun 6, 2023
1 parent 1dd6b68 commit 5e84543
Show file tree
Hide file tree
Showing 4 changed files with 1,016 additions and 136 deletions.
53 changes: 53 additions & 0 deletions docs/source/users/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,56 @@ As a shortcut for explaining errors, you can use the `%ai error` command, which
%ai error anthropic:claude-v1.2
```

### Creating and managing aliases

You can create an alias for a model using the `%ai register` command. For example, the command:

```
%ai register claude anthropic:claude-v1.2
```

will register the alias `claude` as pointing to the `anthropic` provider's `claude-v1.2` model. You can then use this alias as you would use any other model name:

```
%%ai claude
Write a poem about C++.
```

You can also define a custom LangChain chain:

```
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain.llms import OpenAI
llm = OpenAI(temperature=0.9)
prompt = PromptTemplate(
input_variables=["product"],
template="What is a good name for a company that makes {product}?",
)
chain = LLMChain(llm=llm, prompt=prompt)
```

… and then use `%ai register` to give it a name:

```
%ai register companyname chain
```

You can change an alias's target using the `%ai update` command:

```
%ai update claude anthropic:claude-instant-v1.0
```

You can delete an alias using the `%ai delete` command:

```
%ai delete claude
```

You can see a list of all aliases by running the `%ai list` command.

Aliases' names can contain ASCII letters (uppercase and lowercase), numbers, hyphens, underscores, and periods. They may not contain colons. They may also not override built-in commands — run `%ai help` for a list of these commands.

Aliases must refer to models or `LLMChain` objects; they cannot refer to other aliases.
Loading

0 comments on commit 5e84543

Please sign in to comment.