Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrades openai to version 1, removes openai history in magics #551

Merged
merged 12 commits into from
Jan 5, 2024
Merged
Prev Previous commit
Next Next commit
Removes "reset" option, copy edits in docs, updates sample file
  • Loading branch information
JasonWeill committed Jan 4, 2024
commit 4397341bee7934eefe86b9a0c8d33a616589177c
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ In addition, you will need access to at least one model provider.

To use any AI model provider within this notebook, you'll need the appropriate credentials, such as API keys.

Obtain the necessary credentials (e.g., API keys) from your model provider's platform.
Obtain the necessary credentials, such as API keys, from your model provider's platform.

You can set your keys using environment variables or in a code cell in your notebook.
In a code cell, you can use the %env magic command to set the credentials as follows:
Expand Down
26 changes: 3 additions & 23 deletions docs/source/users/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ should contain the following data:
AWS Console at the URL
`https://<region>.console.aws.amazon.com/sagemaker/home?region=<region>#/endpoints`.

- **Region name**: The AWS region your SageMaker endpoint is hosted in, e.g. `us-west-2`.
- **Region name**: The AWS region your SageMaker endpoint is hosted in, such as `us-west-2`.

- **Request schema**: The JSON object the endpoint expects, with the prompt
being substituted into any value that matches the string literal `"<prompt>"`.
Expand Down Expand Up @@ -473,8 +473,8 @@ running the following code in a notebook cell or IPython shell:
This command should not produce any output.

:::{note}
If you are using remote kernels (e.g. Amazon SageMaker Studio), the above
command will throw an error. This means that need to install the magics package
If you are using remote kernels, such as in Amazon SageMaker Studio, the above
command will throw an error. You will need to install the magics package
on your remote kernel separately, even if you already have `jupyter_ai_magics`
installed in your server's environment. In a notebook, run

Expand Down Expand Up @@ -519,11 +519,6 @@ We currently support the following language model providers:
- `openai-chat`
- `sagemaker-endpoint`

:::{warning}
As of v0.8.0, only the `%%ai` *cell* magic may be used to invoke a language
model, while the `%ai` *line* magic is reserved for invoking subcommands.
:::

### Listing available models

Jupyter AI also includes multiple subcommands, which may be invoked via the
Expand Down Expand Up @@ -604,21 +599,6 @@ A function that computes the lowest common multiples of two integers, and
a function that runs 5 test cases of the lowest common multiple function
```

### Clearing the OpenAI chat history

With the `openai-chat` provider *only*, you can run a cell magic command using the `-r` or
`--reset` option to clear the chat history. After you do this, previous magic commands you've
run with the `openai-chat` provider will no longer be added as context in
requests to this provider.

Because the `%%ai` command is a cell magic, you must provide a prompt on the second line.
This prompt will not be sent to the provider. A reset command will not generate any output.

```
%%ai openai-chat:gpt-3.5-turbo -r
reset the chat history
```

### Interpolating in prompts

Using curly brace syntax, you can include variables and other Python expressions in your
Expand Down
9 changes: 5 additions & 4 deletions examples/commands.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@
" -f, --format [code|html|image|json|markdown|math|md|text]\n",
" IPython display to use when rendering\n",
" output. [default=\"markdown\"]\n",
" -r, --reset Clears the conversation transcript used when\n",
" interacting with an OpenAI chat model\n",
" provider. Does nothing with other providers.\n",
" -n, --region-name TEXT AWS region name, e.g. 'us-east-1'. Required\n",
" for SageMaker provider; does nothing with\n",
" other providers.\n",
Expand All @@ -74,6 +71,10 @@
" language model's output from the endpoint's\n",
" JSON response. Required for SageMaker\n",
" provider; does nothing with other providers.\n",
" -m, --model-parameters TEXT A JSON value that specifies extra values\n",
" that will be passed to the model. The\n",
" accepted value parsed to a dict, unpacked\n",
" and passed as-is to the provider class.\n",
" --help Show this message and exit.\n",
"------------------------------------------------------------------------------\n",
"Usage: %ai [OPTIONS] COMMAND [ARGS]...\n",
Expand Down Expand Up @@ -1057,7 +1058,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down
9 changes: 0 additions & 9 deletions packages/jupyter-ai-magics/jupyter_ai_magics/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ def handle_error(self, args: ErrorArgs):
# Set CellArgs based on ErrorArgs
values = args.dict()
values["type"] = "root"
values["reset"] = False
cell_args = CellArgs(**values)

return self.run_ai_cell(cell_args, prompt)
Expand Down Expand Up @@ -505,11 +504,6 @@ def run_ai_cell(self, args: CellArgs, prompt: str):
+ "If you were trying to run a command, run `%ai help` to see a list of commands.",
)

# if `--reset` is specified, reset transcript and return early
if provider_id == "openai-chat" and args.reset:
self.transcript_openai = []
return

# validate presence of authn credentials
auth_strategy = self.providers[provider_id].auth_strategy
if auth_strategy:
Expand All @@ -532,9 +526,6 @@ def run_ai_cell(self, args: CellArgs, prompt: str):

# configure and instantiate provider
provider_params = {"model_id": local_model_id}
if provider_id == "openai-chat":
# provider_params["prefix_messages"] = self.transcript_openai
pass
# for SageMaker, validate that required params are specified
if provider_id == "sagemaker-endpoint":
if (
Expand Down
10 changes: 1 addition & 9 deletions packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ class CellArgs(BaseModel):
type: Literal["root"] = "root"
model_id: str
format: FORMAT_CHOICES_TYPE
reset: bool
model_parameters: Optional[str]
# The following parameters are required only for SageMaker models
region_name: Optional[str]
request_schema: Optional[str]
response_path: Optional[str]


# Should match CellArgs, but without "reset"
# Should match CellArgs
class ErrorArgs(BaseModel):
type: Literal["error"] = "error"
model_id: str
Expand Down Expand Up @@ -126,13 +125,6 @@ def verify_json_value(ctx, param, value):
default="markdown",
help=FORMAT_HELP,
)
@click.option(
"-r",
"--reset",
is_flag=True,
help="""Clears the conversation transcript used when interacting with an
OpenAI chat model provider. Does nothing with other providers.""",
)
@click.option(
REGION_NAME_SHORT_OPTION,
REGION_NAME_LONG_OPTION,
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15070,11 +15070,11 @@ __metadata:

"typescript@patch:typescript@^3 || ^4#~builtin<compat/typescript>":
version: 4.9.5
resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin<compat/typescript>::version=4.9.5&hash=289587"
resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin<compat/typescript>::version=4.9.5&hash=23ec76"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 1f8f3b6aaea19f0f67cba79057674ba580438a7db55057eb89cc06950483c5d632115c14077f6663ea76fd09fce3c190e6414bb98582ec80aa5a4eaf345d5b68
checksum: ab417a2f398380c90a6cf5a5f74badd17866adf57f1165617d6a551f059c3ba0a3e4da0d147b3ac5681db9ac76a303c5876394b13b3de75fdd5b1eaa06181c9d
languageName: node
linkType: hard

Expand Down
Loading