|
1 | | -======================= |
2 | | -Specific config details |
3 | | -======================= |
| 1 | +============================== |
| 2 | +Specific configuration details |
| 3 | +============================== |
| 4 | + |
| 5 | +.. _llm_suggestions: |
| 6 | + |
| 7 | +LLM Suggestions |
| 8 | +=============== |
| 9 | + |
| 10 | +Starting with 9.0, IPython will be able to use LLM providers to suggest code in |
| 11 | +the terminal. This requires a recent version of prompt_toolkit in order to allow |
| 12 | +multiline suggestions. There are currently a number of limitations, and feedback |
| 13 | +on the API is welcome. |
| 14 | + |
| 15 | +Unlike many of IPython features, this is not enabled by default and requires |
| 16 | +multiple configuration options to be set to properly work: |
| 17 | + |
| 18 | + - Set a keybinding to trigger LLM suggestions. Due to terminal limitations |
| 19 | + across platforms and emulators, it is difficult to provide a default |
| 20 | + keybinding. Note that not all keybindings are availables, in particular all |
| 21 | + the `Ctrl-Enter`, `Alt-backslash` and `Ctrl-Shift-Enter` are not available |
| 22 | + without integration with your terminal emulator. |
| 23 | + |
| 24 | + - Chose a LLM `provider`, usually from Jupyter-AI. This will be the interface |
| 25 | + between IPython itself, and the LLM – that may be local or in on a server. |
| 26 | + |
| 27 | + - Configure said provider with models, API keys, etc – this will depend on the |
| 28 | + provider, and you will have to refer to Jupyter-AI documentation, and/or your |
| 29 | + LLM documenatation. |
| 30 | + |
| 31 | + |
| 32 | +While setting up IPython to use a real LLM, you can refer to |
| 33 | +``examples/auto_suggest_llm.py`` that both provide an example of how to set up |
| 34 | +IPython to use a Fake LLM provider, this can help ensure that the full setup is |
| 35 | +working before switching to a real LLM provider. |
| 36 | + |
| 37 | + |
| 38 | +Setup a keybinding |
| 39 | +------------------ |
| 40 | + |
| 41 | +You may want to refer on how to setup a keybinding in IPython, but in short you |
| 42 | +want to bind the ``IPython:auto_suggest.llm_autosuggestion`` command to a |
| 43 | +keybinding, and have it active only when the default buffer isi focused, and |
| 44 | +when using the NavigableSuggestions suggestter (this is the default suggestter, |
| 45 | +the one that is history and LLM aware). Thus the ``navigable_suggestions & |
| 46 | +default_buffer_focused`` filter should be used. |
| 47 | + |
| 48 | +Usually ``Ctrl-Q`` on macos is an available shortcut, note that is does use |
| 49 | +``Ctrl``, and not ``Command``. |
| 50 | + |
| 51 | +The following example will bind ``Ctrl-Q`` to the ``llm_autosuggestion`` |
| 52 | +command, with the suggested filter:: |
| 53 | + |
| 54 | + c.TerminalInteractiveShell.shortcuts = [ |
| 55 | + { |
| 56 | + "new_keys": ["c-q"], |
| 57 | + "command": "IPython:auto_suggest.llm_autosuggestion", |
| 58 | + "new_filter": "navigable_suggestions & default_buffer_focused", |
| 59 | + "create": True, |
| 60 | + }, |
| 61 | + ] |
| 62 | + |
| 63 | + |
| 64 | +Choose a LLM provider |
| 65 | +--------------------- |
| 66 | + |
| 67 | +Set the ``TerminalInteractiveShell.llm_provider_class`` trait to the fully |
| 68 | +qualified name of the Provider you like, when testing from inside the IPython |
| 69 | +source tree, you can use |
| 70 | +``"examples.auto_suggest_llm.ExampleCompletionProvider"`` This will always |
| 71 | +stream an extract of the Little Prince by Antoine de Saint-Exupéry, and will not |
| 72 | +require any API key or real LLM. |
| 73 | + |
| 74 | + |
| 75 | +In your configuration file adapt the following line to your needs: |
| 76 | + |
| 77 | +.. code-block:: python |
| 78 | +
|
| 79 | + c.TerminalInteractiveShell.llm_provider_class = "examples.auto_suggest_llm.ExampleCompletionProvider" |
| 80 | +
|
| 81 | +Configure the provider |
| 82 | +---------------------- |
| 83 | + |
| 84 | +It the provider needs to be passed parameters at initialization, you can do so |
| 85 | +by setting the ``llm_provider_kwargs`` traitlet. |
| 86 | + |
| 87 | +.. code-block:: python |
| 88 | +
|
| 89 | + c.TerminalInteractiveShell.llm_provider_kwargs = {"model": "skynet"} |
| 90 | +
|
| 91 | +This will depdend on the provider you chose, and you will have to refer to |
| 92 | +the provider documentation. |
| 93 | + |
| 94 | +Extra configuration may be needed by setting environment variables, this will |
| 95 | +again depend on the provider you chose, and you will have to refer to the |
| 96 | +provider documentation. |
| 97 | + |
| 98 | + |
4 | 99 |
|
5 | 100 | .. _custom_prompts: |
6 | 101 |
|
|
0 commit comments