Skip to content

Commit b92d311

Browse files
srdaspre-commit-ci[bot]michaelchia3coinskrassowski
committed
Save chat history to Jupyter Lab's root directory (jupyterlab#770)
* save chat history to jupyter lab root dir The /export command was saving chat history in the pwd, i.e., the directory from where JupyterLab is launched rather than the JupyterLab root. For JupyterLab sessions, where the root directory is different from the launch directory, users will not be able to see the exported chat history file in JupyterLab. This is now rectified. * learn arxiv tex files (jupyterlab#742) * learn arxiv tex files * Created a new option remote or -r. Example: /learn -r arxiv <arxiv-id> * Approach: downloads the tar file for the entire paper into downloads_temp. Then, unzips and collects all .tex files in the tar file and concatenates them. Different authors use various approaches. Some have the entire paper in one tex file, whereas others may have separate tex files for each section, so we need to collect all the tex file into a single file and then hand off to the splitter, embedder. After completion, remove the temp directory. Return a properly formatted error if package arxiv needs to be installed. * Handle two types of errors: (i) package arxiv not installed. (ii) User enters a wrong paper id. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * learn_arxiv * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * learn arxiv tex files * Created a new option remote or -r. Example: /learn -r arxiv <arxiv-id> * Approach: downloads the tar file for the entire paper into downloads_temp. Then, unzips and collects all .tex files in the tar file and concatenates them. Different authors use various approaches. Some have the entire paper in one tex file, whereas others may have separate tex files for each section, so we need to collect all the tex file into a single file and then hand off to the splitter, embedder. After completion, remove the temp directory. Return a properly formatted error if package arxiv needs to be installed. * Handle two types of errors: (i) package arxiv not installed. (ii) User enters a wrong paper id. * learn_arxiv * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Streamlined code for learning arxiv files (1) removed temp dir handling {2) extracted only tex files (3) Moved imports into the `arxiv_to_text` function {4) improved tar file processing * update learn for arxiv * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * removed extra imports * Fix /learn in 2.14.0 (jupyterlab#747) * accumulate filepaths * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * learn arxiv tex files * Created a new option remote or -r. Example: /learn -r arxiv <arxiv-id> * Approach: downloads the tar file for the entire paper into downloads_temp. Then, unzips and collects all .tex files in the tar file and concatenates them. Different authors use various approaches. Some have the entire paper in one tex file, whereas others may have separate tex files for each section, so we need to collect all the tex file into a single file and then hand off to the splitter, embedder. After completion, remove the temp directory. Return a properly formatted error if package arxiv needs to be installed. * Handle two types of errors: (i) package arxiv not installed. (ii) User enters a wrong paper id. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update learn for arxiv files Redoing code after the PR 747 made changes to the same file. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Improved code for arxiv files Improvements to PR 742: (i) removed extra `arxiv.Client` call (ii) removed unnecessary `try/catch` (iii) moved `datetime` import outside `arxiv_to_text` function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Saves arxiv to root, better exception handling. * Added arxiv feature to docs. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: michaelchia <michael_chia7@msn.com> Co-authored-by: Piyush Jain <piyushjain@duck.com> * Distinguish between completion and chat models (jupyterlab#711) * Distinguish between completion and chat models * Fix tests * Shorten the tab name, move settings button Lint * Implement the completion model selection in chat UI * Improve docstring * Call `_validate_lm_em_id` only once, add typing annotations * Remove embeddings provider for completions as the team has no plans to support it :( * Use type alias to reduce changeset/make review easier Without this change prettier reformats the plugin with an extra indentation, which leads to bad changeset display on GitHub. * Rename `_validate_lm_em_id` to `_validate_model_ids` * Rename `LLMHandlerMixin` to `CompletionsModelMixin` and rename the file from `llm_mixin` to `model_mixin` fro consistency. Of note, the file name does not need `completions_` prefix as the file is in `completions/` subdirectory. * Rename "Chat LM" to "LM"; add title attribute; note using the title attribute because getting the icon to show up nicely (getting they nice grey color and positioning as it gets in buttons, compared to just plain black) was not trivial; I think the icon might be the way to go in the future but I would postpone it to another PR. That said, I still think it should say "Chat LM" because it has no effect on magics nor completions. * Rename heading "Completer model" → "Inline completions model" * Move `UseSignal` down to `CompleterSettingsButton` implementation * Rename the label in the select to "Inline completion model" * Disable selection when completer is not enabled * Remove use of `UseSignal`, tweak naming of `useState` from `completerIsEnabled` to `isCompleterEnabled` * Use mui tooltips * Fix use of `jai_config_manager` * Fix tests * Fix `unsupported_slash_commands` default (jupyterlab#768) * Updates to /export command (1) Save chat history file to Jupyter root directory, not cwd, in markdown format (2) Add time stamps to the saved files (3) Enable the `/export <filename>` option, else use default file name. (4) Remove code to increment file numbers for multiple chat histories, given that the time stamps are now being used. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update export function (1) Use argparse to extract filename if the option is used (2) Remove the old function to get the chat file name and streamline the code * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add Titan embedding model v2 (jupyterlab#778) * Add Titan embeddning model v2 Included the new embedding model, released recently on Amazon Bedrock. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * refactor /export code Remove if then and replace with a single inline expression * Refactor export code reprise Updated some variable names --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: michaelchia <michael_chia7@msn.com> Co-authored-by: Piyush Jain <piyushjain@duck.com> Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com>
1 parent 7580980 commit b92d311

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

docs/source/users/index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,17 @@ use the `-a` or `--all-files` option.
464464
/learn -a <directory>
465465
```
466466

467+
### Learning arXiv files
468+
`/learn` command also provides downloading and processing papers from the [arXiv](https://arxiv.org/) repository. You will need to install the `arxiv` python package for this feature to work. Run `pip install arxiv` to install the `arxiv` package.
469+
470+
```
471+
/learn -r arxiv 2404.18558
472+
```
473+
474+
### Exporting chat history
475+
Use the `/export` command to export the chat history from the current session to a markdown file named `chat_history-YYYY-MM-DD-HH-mm.md`. Using `/export <file_name>` will export the chat history to `<file_name>-YYYY-MM-DD-HH-mm.md` instead. You can export chat history as many times as you like in a single session. Each successive export will include the entire chat history up to that point in the session.
476+
477+
467478
### Additional chat commands
468479

469480
To clear the chat panel, use the `/clear` command. This does not reset the AI model; the model may still remember previous messages that you sent it, and it may use them to inform its responses.
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import argparse
12
import os
3+
from datetime import datetime
24
from typing import List
35

46
from jupyter_ai.models import AgentChatMessage, HumanChatMessage
@@ -9,13 +11,15 @@
911
class ExportChatHandler(BaseChatHandler):
1012
id = "export"
1113
name = "Export chat messages"
12-
help = "Export the chat messages in markdown format"
14+
help = "Export the chat messages in markdown format with timestamps"
1315
routing_type = SlashCommandRoutingType(slash_id="export")
1416

1517
uses_llm = False
1618

1719
def __init__(self, *args, **kwargs):
1820
super().__init__(*args, **kwargs)
21+
self.parser.prog = "/export"
22+
self.parser.add_argument("path", nargs=argparse.REMAINDER)
1923

2024
def chat_message_to_markdown(self, message):
2125
if isinstance(message, AgentChatMessage):
@@ -25,22 +29,15 @@ def chat_message_to_markdown(self, message):
2529
else:
2630
return ""
2731

28-
# Multiple chat histories in separate files
29-
def get_chat_filename(self, path="./chat_history.md"):
30-
filename, extension = os.path.splitext(path)
31-
counter = 1
32-
while os.path.exists(path):
33-
path = filename + "_" + str(counter) + ".md"
34-
counter += 1
35-
return path
36-
37-
async def process_message(self, _):
32+
# Write the chat history to a markdown file with a timestamp
33+
async def process_message(self, message: HumanChatMessage):
3834
markdown_content = "\n\n".join(
3935
self.chat_message_to_markdown(msg) for msg in self._chat_history
4036
)
41-
# Write the markdown content to a file or do whatever you want with it
42-
chat_filename = self.get_chat_filename()
43-
with open(chat_filename, "w") as chat_history:
37+
args = self.parse_args(message)
38+
chat_filename = args.path[0] if args.path else "chat_history"
39+
chat_filename = f"{chat_filename}-{datetime.now():%Y-%m-%d-%H-%M}.md"
40+
chat_file = os.path.join(self.root_dir, chat_filename)
41+
with open(chat_file, "w") as chat_history:
4442
chat_history.write(markdown_content)
45-
46-
self.reply(f"File saved to `{chat_filename}`")
43+
self.reply(f"File saved to `{chat_file}`")

0 commit comments

Comments
 (0)