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

@Snippets #3918

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

@Snippets #3918

wants to merge 24 commits into from

Conversation

RXminuS
Copy link
Contributor

@RXminuS RXminuS commented Apr 23, 2024

This is a PR to include experimental @snippet support.

These snippets can be inserted just like normal context

CleanShot 2024-05-02 at 18 50 39@2x

The content of the snippets is inserted into the conversation so that they can tweak the responses by the LLM.

CleanShot 2024-05-02 at 18 51 22@2x

But also do cool things like:

CleanShot 2024-05-02 at 18 52 27@2x

CleanShot 2024-05-02 at 18 48 51@2x

TODO:

  • Prompt tuning
  • Content Security Policy verificaiton
  • In-conversation injectionPoint support
    • Multi injection mixins
  • Fix remaining TODO's

Test Plan:

Behind experimental flag, unit tests pass for existing code

@RXminuS RXminuS changed the title Prompt Snippets #-style Prompt Instruction Snippets #-style Apr 23, 2024
@RXminuS RXminuS changed the title Prompt Instruction Snippets #-style Response Instruction Snippets #-style Apr 23, 2024
@PriNova
Copy link
Contributor

PriNova commented Apr 24, 2024

Hey @RXminuS ,
I like the idea to have the ability of choosing pre-defined pre-instruction prompts for the chat, but also for edit commands. Switching between via '#tag' seems reasonable.
If it can be customized via .cody config file, based on User- or Workspace-Profile will be amazing.

The # is potentially a bit difficult to discover, so trying a simple UI element instead to tweak response style. The idea is still the same though where you pick a bunch of style-tags to apply.

This can later always be expanded to ALSO allow for quick access via a #-like interface so you can simply type everything instead of having to click
@RXminuS RXminuS changed the title Response Instruction Snippets #-style Chat Mixins May 1, 2024
@PriNova
Copy link
Contributor

PriNova commented May 2, 2024

Hey @RXminuS I saw that you included mermaid mixin feature. This is epic.

One recommendation I can give is, that internally Cody should fetch the mermaid API for the flow chart and sequence diagram as context to correctly provide the mermaid syntax. In complex use cases it often fails.
As advice for content fetching use:

Flow Chart
Sequence Diagram

@RXminuS RXminuS marked this pull request as ready for review May 2, 2024 16:56
@RXminuS
Copy link
Contributor Author

RXminuS commented May 2, 2024

One recommendation I can give is, that internally Cody should fetch the mermaid API for the flow chart and sequence diagram as context to correctly provide the mermaid syntax. In complex use cases it often fails. As advice for content fetching use:

Yeah that's a good idea! I'll have to rework it a little so that I can mix-in at multiple points but then that's completely doable. I think that would improve responses a lot!

@RXminuS RXminuS requested review from a team May 2, 2024 17:01
@RXminuS RXminuS added the wip label May 2, 2024
@RXminuS RXminuS self-assigned this May 2, 2024
@RXminuS RXminuS changed the title Chat Mixins @Snippets May 2, 2024
@RXminuS
Copy link
Contributor Author

RXminuS commented May 6, 2024

@PriNova I added a bit hacky way of doing this but it seems to work, so maybe good enough for now? Mermaid is still quite tedious with whitespace so graphs do still fail at times.

CleanShot 2024-05-06 at 14 03 38

@RXminuS RXminuS removed the request for review from a team May 6, 2024 12:19
@PriNova
Copy link
Contributor

PriNova commented May 6, 2024

@PriNova I added a bit hacky way of doing this but it seems to work, so maybe good enough for now? Mermaid is still quite tedious with whitespace so graphs do still fail at times.

This looks awesome. Did you try fetching the API docs like I mentioned above?
If the user specifies the type of graph via @snippet:visual-Flow, @snippet:visual-Pie or @snippet:visual-Sequence, etc, then retrieving the appropriate API should be doable.

What most newer LLMs also understand are GraphViz dot files.

@RXminuS
Copy link
Contributor Author

RXminuS commented May 6, 2024

This looks awesome. Did you try fetching the API docs like I mentioned above?

Yeah I did but they waste a lot of tokens doing both the mermaid graph themselves and then the exact same block as code. That's why I just quickly made a gist that combines all the docs/cheatsheets and removes the duplicates. Not a long term solution but having the examples seemed to improve results by quite a bit.

I think the biggest amount of mistakes comes from how there's a high likelyhood of some extra whitespace making it in (and breaking the syntax) probably due to tokens with trailing whitespace being more commonly used than ones with explicit separate whitespace. This has been an issue I've had before trying to generate structured data.

If the user specifies the type of graph via @snippet:visual-Flow, @snippet:visual-Pie or @snippet:visual-Sequence, etc, then retrieving the appropriate API should be doable.

It feels a bit too verbose IMHO? I would like it to just pick the right graph based on my question.

@RXminuS RXminuS removed the wip label May 6, 2024
@PriNova
Copy link
Contributor

PriNova commented May 6, 2024

Yeah I did but they waste a lot of tokens doing both the mermaid graph themselves and then the exact same block as code. That's why I just quickly made a gist that combines all the docs/cheatsheets and removes the duplicates. Not a long term solution but having the examples seemed to improve results by quite a bit.

You are right, it takes around 5k tokens for the API of one chart-type. That's a lot.

I think the biggest amount of mistakes comes from how there's a high likelyhood of some extra whitespace making it in (and breaking the syntax) probably due to tokens with trailing whitespace being more commonly used than ones with explicit separate whitespace. This has been an issue I've had before trying to generate structured data.

The most common chart types are simply formatted, which can be done as a post-formatting step. The first line has no whitespaces and all following lines are prepended with whitespace. Maybe this could be a work-around.

Copy link
Contributor

@abeatrix abeatrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love the new @-mention menu! I haven't conducted a full review yet but left a question/feedback regarding how we inject the @snippet in preamble instead of chat message.

Also, it'd be great to add a new e2e test cover the new menu for @snippets 😄

@@ -52,7 +54,29 @@ export class DefaultPrompter implements IPrompter {
undefined
)

const preambleMessages = getSimplePreamble(chat.modelID, codyApiVersion, preInstruction)
sortContextItems(this.explicitContext)
// We now filter out any mixins from the user contet and add those as preamble messages as well
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm do we want to alter the preamble instead of the last human message text for @-mention snippets ?
This seems to make it hard to debug using the exported transcript because the prompt for the snippet doesn't show up in the transcript history, and this might not work when the chat transcript gets too long?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I wasn't sure about the correct injection point so wanted to implement both. My main reasoning was to keep it similar to the normal instructions config option but just "ad hoc" which is why I started there.

But I think both of your observations are good arguments to change it. 👍

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.

None yet

4 participants