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

Showing the Think process for Deep Seek R1 in Cody UI #6896

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

Conversation

arafatkatze
Copy link
Contributor

@arafatkatze arafatkatze commented Jan 31, 2025

Originally a PR from @abeatrix on having a thinktag UX.

Loom Video

This PR adds a simple hack to support rendering tags in the ChatMessageContent component. The content is displayed in a collapsible details element, allowing users to view the AI's internal thought process.
The MarkdownFromCody component is also updated to allow the element.

Test plan

  • Run SG instance locally and switch to branch fake-think-tag
  • Run cody with this branch in the debugger and choose sonnet model with the local SG instance(NOTE: Since the model is not actually released this is a fake hack)
  • Ask Cody "Tell me a long story"
  • Verify that tags are properly extracted and displayed in the ChatMessageContent component
image
  • Ensure that the collapsible details element functions as expected, allowing users to view the think content
  • Confirm that the MarkdownFromCody component correctly renders the element

abeatrix and others added 4 commits January 28, 2025 22:48
This PR adds support for rendering <think> tags in the ChatMessageContent component. The <think> content is displayed in a collapsible details element, allowing users to view the AI's internal thought process.

The MarkdownFromCody component is also updated to allow the <think> element.
@arafatkatze arafatkatze requested a review from abeatrix January 31, 2025 08:55
open
className={clsx(
"tw-container tw-mb-4",
"tw-border tw-border-gray-600/15 dark:tw-border-gray-500/20",
Copy link
Contributor Author

@arafatkatze arafatkatze Jan 31, 2025

Choose a reason for hiding this comment

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

Will fix all the CSS in proper files separately AFTER the design has been approved.

@PriNova
Copy link
Collaborator

PriNova commented Jan 31, 2025

@arafatkatze If you need some inspirations how I implemented it, have a look at https://github.com/PriNova/cody/blob/dev/vscode/webviews/chat/ChatMessageContent/ChatMessageContent.tsx
But to be honest, it is not somehow optimized.

I used special thinking tags to separate them from the model response for future changes.
The thinking tags I handled in the model response stream handler.
I don't know if this is the right choice, but it somehow works.

@@ -217,3 +217,140 @@ body[data-vscode-theme-kind='vscode-light'] .content pre > code {
color: var(--vscode-descriptionForeground);
margin-left: auto;
}

/* Think Container Styles */
.thinkContainer {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@taiyab I don't actually know much about how CSS works and this code was mostly LLM generated so

How about this? @abeatrix tests this code on functionality and verifies if this does what it claims to do. We can merge this in for now but down the line when you do a much proper cleanup and merger for agentic/normal chat you can take care of this too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason we want to do this in a stylesheet instead of using tailwind?

@arafatkatze arafatkatze changed the title [WIP] Showing the Think process for Deep Seek R1 in Cody UI Showing the Think process for Deep Seek R1 in Cody UI Feb 3, 2025
@arafatkatze arafatkatze requested review from a team and removed request for abeatrix February 3, 2025 15:43
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.

Left some comments in line. I think it'd be easier if you could change the merge into branch for this PR from main to the bee/think-tag branch so we can see what the changes are between this branch and the original branch, and then merge them together before we can ask design or product for the final review.

}

const extractThinkContent = (content: string): StreamingContent => {
const thinkRegex = /<think>([\s\S]*?)<\/think>/g
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const thinkRegex = /<think>([\s\S]*?)<\/think>/g
const thinkRegex = /^<think>([\s\S]*?)<\/think>/g

Do we want to make sure only the tags at the beginning are being considered? I know I wrote the original regex but haven't really tested it throughoutly 😆

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, do we want to consider "thinking" in additional to "think" for other provider? For example, Anthropic suggested using "" tags for CoT https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/chain-of-thought#how-to-prompt-for-thinking

displayContent,
thinkContent,
hasThinkTag: thinkMatches.length > 0 || hasOpenThinkTag,
isThinking: hasOpenThinkTag,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
isThinking: hasOpenThinkTag,

If hasThinkTag is false it already means isThinking is true? Alternatively we can rename hasThinkTag to isThinking if you think that's more clear, but I don't think we will need both.

displayContent: string
thinkContent: string
hasThinkTag: boolean
isThinking: boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
isThinking: boolean

@@ -217,3 +217,140 @@ body[data-vscode-theme-kind='vscode-light'] .content pre > code {
color: var(--vscode-descriptionForeground);
margin-left: auto;
}

/* Think Container Styles */
.thinkContainer {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason we want to do this in a stylesheet instead of using tailwind?

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.

The code runs as described, but left a few comments about the styling and improvements we can make:

image

width: 1.5rem;
height: 1.5rem;
border-radius: 0.375rem;
background-color: rgba(229, 231, 235, 0.5);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
background-color: rgba(229, 231, 235, 0.5);

Do we need a background color for it?

image

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.

3 participants