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

added Term formatting #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

added Term formatting #12

wants to merge 2 commits into from

Conversation

FedeClaudi
Copy link

@FedeClaudi FedeClaudi commented Mar 17, 2023

Thank you for writing this, much easier then constantly switching between code/web browser.

I made a small change to improve the styling of the responses.
Using Term.jl it's possible to format the Markdown response to make something clearer/better looking.
Id does add a bit of TTX due to Term's code compilation.

image

Hope this helps!

P.s: getting this exact style requires Term 2.0.2 which will come out today/tomorrow. In doing this I found a bug in Term!

@diegozea
Copy link

Hi! This looks nice. However, I am worried about this change making it more difficult to copy and paste code. Also, sometimes I want to copy and paste the markdown answer as markdown.

@FedeClaudi
Copy link
Author

That's fair. In VSCode you can box select from the terminal so it's not an issue, but it wouldn't work in every terminal.

@diegozea
Copy link

Is having a copy button for the code blocks (like in ChatGPT) a good idea?

@svilupp
Copy link

svilupp commented Mar 19, 2023

Having access to access only the code would be super useful (even if it would be saved in some variable).

Is there a way to get contents of only the code blocks via Term? Or is my best bet to regex it?

@FedeClaudi
Copy link
Author

A copy button would be great, but would take some work to get it right. Term now can create live widgets in the terminal that could be used to display the text and make it interactive, e.g. select the code block and copy it. But it would take a bit of work to set it up and it would mean you couldn't just a repl mode like in the original implementation.

If it's something @diegozea is interested in we could give it a go. It would also be a great use case for term's new functionality. Perhaps, given that the basic GPT interaction logic is used by other packages too like HelpGPT.jl and likely more in the future, it makes sense to create a GPTBase.jl with the basic API support and have separate packages for the repl mode, Term's interactive mode, help gpt... what do you think?

@diegozea
Copy link

Yes, having a ChatGPTBase sound like the right thing to do!

I like that this package is using a REPL mode, so it would make sense to have the most interactive terminal app elsewhere.

I have another idea to solve the problem for this package: adding commands like copy, regenerate, etc. I can implement those, but not before the 28th of March (I have a lot of things to tackle before that day).

@svilupp
Copy link

svilupp commented Mar 19, 2023

Shared codebase is a great idea!

On the code copying, having a button would be cool.
But I think what is needed is a simple command to extract the code block(s) (eg, like https://github.com/anandijain/OpenAIReplMode.jl/blob/72a67c66c56d886d9d3252ac8db728ef0cbc379e/src/OpenAIReplMode.jl#L47).
Then a user could easily access it and either execute it directly or copy it to clipboard.

@ThatcherC
Copy link
Owner

That OpenAIReplMode.jl approach is really nice! I like that it keeps the the copy/paste nature of the output but adds in that nice Julia formatting.

In general, I think I'd like to add a setting or option that allows the ChatGPT response to be printed in plaintext to the terminal, or interpreted as Markdown. Maybe the more general solution would be to allow users to register different renderers (like plaintext, Markdown.jl, or Term.jl options) so we can have all of these options. How does that sound?

@FedeClaudi
Copy link
Author

Yeah that sounds perfect!

Btw, unrelated but it would be nice to have a way to reset the context when the conversation has become too long. Otherwise the only way is to re-start Julia which can be a bit annoying.

@diegozea diegozea mentioned this pull request Mar 20, 2023
@ThatcherC
Copy link
Owner

Re: resetting the history - that's a great idea! I'll track that in #18.

@ThatcherC
Copy link
Owner

I have a PR open for adding different formatters (#20), right now just with the Markdown formatter and a plaintext formatter. @FedeClaudi - do you think your Term.jl output could be implemented as one of these formatter functions? If so I think that'd be the nicest way to go so that users could pick between the cool Term formatter and simpler plain for MD styles.

@FedeClaudi
Copy link
Author

I had missed @diegozea's comment, but I think having something like "copy 1" and it copies the first code block in the response as a command would be the cleanest option.

@FedeClaudi
Copy link
Author

@ThatcherC yeah having the option to choose formatters would be great!
A couple comments/questions

  1. perhaps there should be a way to pass a parser when when initializing the package? Or set one as default to be always used (by storing it as parameter).
  2. Should I implement the term one as a function to be stored in your package or elsewhere? Having it in your package adds Term as a dependency, but that miight be okay if Term is also used elsewhere, e.g. to format the help prompt in Commands #17

@svilupp
Copy link

svilupp commented Mar 26, 2023

Slightly tangential but related to the Term-style formatting: would Term markdown be capable of supporting streaming requests (ie, incremental load of the response) to achieve the same UI as what you experience in the browser?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants