Skip to content

Commit

Permalink
Revert "Cody: Add warning message for recipes (#54025)" (#54319)
Browse files Browse the repository at this point in the history
This reverts commit e40e0d0 (cc
@deepak2431)

We noticed that there is some unexpected behavior in some recipes where
this warning is shown even if only 5 lines of code are selected. It's
probably because the context lines are truncated but we don't have time
to look into this and fix it just yet (we were supposed to release a few
hours ago 😓). We'll take a closer look after the release.

## Test plan

- It's a revert

<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->
  • Loading branch information
philipp-spiess committed Jun 27, 2023
1 parent e673147 commit af3b8ed
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 104 deletions.
10 changes: 1 addition & 9 deletions client/cody-shared/src/chat/recipes/explain-code-detailed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MAX_RECIPE_INPUT_TOKENS, MAX_RECIPE_SURROUNDING_TOKENS } from '../../prompt/constants'
import { truncateText, truncateTextStart, isTextTruncated } from '../../prompt/truncation'
import { truncateText, truncateTextStart } from '../../prompt/truncation'
import { Interaction } from '../transcript/interaction'

import { getContextMessagesFromSelection, getNormalizedLanguageName, MARKDOWN_FORMAT_PROMPT } from './helpers'
Expand All @@ -19,14 +19,6 @@ export class ExplainCodeDetailed implements Recipe {
const truncatedPrecedingText = truncateTextStart(selection.precedingText, MAX_RECIPE_SURROUNDING_TOKENS)
const truncatedFollowingText = truncateText(selection.followingText, MAX_RECIPE_SURROUNDING_TOKENS)

if (
isTextTruncated(selection.selectedText, truncatedSelectedText) ||
isTextTruncated(selection.precedingText, truncatedPrecedingText) ||
isTextTruncated(selection.followingText, truncatedFollowingText)
) {
await context.editor.showWarningMessage('Truncated extra long selection so output may be incomplete.')
}

const languageName = getNormalizedLanguageName(selection.fileName)
const promptMessage = `Please explain the following ${languageName} code. Be very detailed and specific, and indicate when it is not clear to you what is going on. Format your response as an ordered list.\n\`\`\`\n${truncatedSelectedText}\n\`\`\`\n${MARKDOWN_FORMAT_PROMPT}`
const displayText = `Explain the following code:\n\`\`\`\n${selection.selectedText}\n\`\`\``
Expand Down
10 changes: 1 addition & 9 deletions client/cody-shared/src/chat/recipes/explain-code-high-level.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MAX_RECIPE_INPUT_TOKENS, MAX_RECIPE_SURROUNDING_TOKENS } from '../../prompt/constants'
import { truncateText, truncateTextStart, isTextTruncated } from '../../prompt/truncation'
import { truncateText, truncateTextStart } from '../../prompt/truncation'
import { Interaction } from '../transcript/interaction'

import { getContextMessagesFromSelection, getNormalizedLanguageName, MARKDOWN_FORMAT_PROMPT } from './helpers'
Expand All @@ -19,14 +19,6 @@ export class ExplainCodeHighLevel implements Recipe {
const truncatedPrecedingText = truncateTextStart(selection.precedingText, MAX_RECIPE_SURROUNDING_TOKENS)
const truncatedFollowingText = truncateText(selection.followingText, MAX_RECIPE_SURROUNDING_TOKENS)

if (
isTextTruncated(selection.selectedText, truncatedSelectedText) ||
isTextTruncated(selection.precedingText, truncatedPrecedingText) ||
isTextTruncated(selection.followingText, truncatedFollowingText)
) {
await context.editor.showWarningMessage('Truncated extra long selection so output may be incomplete.')
}

const languageName = getNormalizedLanguageName(selection.fileName)
const promptMessage = `Explain the following ${languageName} code at a high level. Only include details that are essential to an overal understanding of what's happening in the code.\n\`\`\`\n${truncatedSelectedText}\n\`\`\`\n${MARKDOWN_FORMAT_PROMPT}`
const displayText = `Explain the following code at a high level:\n\`\`\`\n${selection.selectedText}\n\`\`\``
Expand Down
10 changes: 2 additions & 8 deletions client/cody-shared/src/chat/recipes/file-touch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
MAX_RECIPE_SURROUNDING_TOKENS,
} from '../../prompt/constants'
import { populateCurrentEditorContextTemplate } from '../../prompt/templates'
import { truncateText, isTextTruncated } from '../../prompt/truncation'
import { truncateText } from '../../prompt/truncation'
import { BufferedBotResponseSubscriber } from '../bot-response-multiplexer'
import { Interaction } from '../transcript/interaction'

Expand Down Expand Up @@ -64,13 +64,7 @@ export class FileTouch implements Recipe {

const truncatedText = truncateText(humanInput, MAX_HUMAN_INPUT_TOKENS)
const MAX_RECIPE_CONTENT_TOKENS = MAX_RECIPE_INPUT_TOKENS + MAX_RECIPE_SURROUNDING_TOKENS * 2
const truncatedSelectedText = truncateText(
selection.selectedText,
Math.min(MAX_RECIPE_CONTENT_TOKENS, MAX_RECIPE_INPUT_TOKENS)
)
if (isTextTruncated(selection.selectedText, truncatedSelectedText)) {
await context.editor.showWarningMessage('Truncated extra long selection so output may be incomplete.')
}
const truncatedSelectedText = truncateText(selection.selectedText, MAX_RECIPE_CONTENT_TOKENS)

// Reconstruct Cody's prompt using user's context
// Replace placeholders in reverse order to avoid collisions if a placeholder occurs in the input
Expand Down
5 changes: 1 addition & 4 deletions client/cody-shared/src/chat/recipes/find-code-smells.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CHARS_PER_TOKEN, MAX_AVAILABLE_PROMPT_LENGTH, MAX_RECIPE_INPUT_TOKENS } from '../../prompt/constants'
import { truncateText, isTextTruncated } from '../../prompt/truncation'
import { truncateText } from '../../prompt/truncation'
import { Interaction } from '../transcript/interaction'

import { getNormalizedLanguageName } from './helpers'
Expand Down Expand Up @@ -27,9 +27,6 @@ If you have no ideas because the code looks fine, feel free to say that it alrea
selection.selectedText,
Math.min(maxTokenCount, MAX_RECIPE_INPUT_TOKENS)
)
if (isTextTruncated(selection.selectedText, truncatedSelectedText)) {
await context.editor.showWarningMessage('Truncated extra long selection so output may be incomplete.')
}
const promptMessage = `${promptPrefix}\n\n\`\`\`\n${truncatedSelectedText}\n\`\`\`\n\n${promptSuffix}`

const displayText = `Find code smells in the following code: \n\`\`\`\n${selection.selectedText}\n\`\`\``
Expand Down
10 changes: 1 addition & 9 deletions client/cody-shared/src/chat/recipes/generate-docstring.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MAX_RECIPE_INPUT_TOKENS, MAX_RECIPE_SURROUNDING_TOKENS } from '../../prompt/constants'
import { truncateText, truncateTextStart, isTextTruncated } from '../../prompt/truncation'
import { truncateText, truncateTextStart } from '../../prompt/truncation'
import { Interaction } from '../transcript/interaction'

import {
Expand All @@ -24,14 +24,6 @@ export class GenerateDocstring implements Recipe {
const truncatedPrecedingText = truncateTextStart(selection.precedingText, MAX_RECIPE_SURROUNDING_TOKENS)
const truncatedFollowingText = truncateText(selection.followingText, MAX_RECIPE_SURROUNDING_TOKENS)

if (
isTextTruncated(selection.selectedText, truncatedSelectedText) ||
isTextTruncated(selection.precedingText, truncatedPrecedingText) ||
isTextTruncated(selection.followingText, truncatedFollowingText)
) {
await context.editor.showWarningMessage('Truncated extra long selection so output may be incomplete.')
}

const extension = getFileExtension(selection.fileName)
const languageName = getNormalizedLanguageName(selection.fileName)
const promptPrefix = `Generate a comment documenting the parameters and functionality of the following ${languageName} code:`
Expand Down
12 changes: 5 additions & 7 deletions client/cody-shared/src/chat/recipes/generate-pr-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { readFileSync } from 'fs'
import path from 'path'

import { MAX_RECIPE_INPUT_TOKENS } from '../../prompt/constants'
import { truncateText, isTextTruncated } from '../../prompt/truncation'
import { truncateText } from '../../prompt/truncation'
import { Interaction } from '../transcript/interaction'

import { Recipe, RecipeContext, RecipeID } from './recipe'
Expand Down Expand Up @@ -63,15 +63,13 @@ export class PrDescription implements Recipe {
}

const truncatedGitCommitOutput = truncateText(gitCommitOutput, MAX_RECIPE_INPUT_TOKENS)

if (isTextTruncated(gitCommitOutput, truncatedGitCommitOutput)) {
await context.editor.showWarningMessage(
'Truncated extra long git log output, so PR description may be incomplete.'
)
let truncatedCommitMessage = ''
if (truncatedGitCommitOutput.length < gitCommitOutput.length) {
truncatedCommitMessage = 'Truncated extra long git log output, so PR description may be incomplete.'
}

const promptMessage = `Summarise these changes:\n${gitCommitOutput}\n\n made while working in the current git branch.\nUse this pull request template to ${prTemplateContent} generate a pull request description based on the committed changes.\nIf the PR template mentions a requirement to check the contribution guidelines, then just summarise the changes in bulletin format.\n If it mentions a test plan for the changes use N/A\n.`
const assistantResponsePrefix = 'Here is the PR description for the work done in your current branch:\n'
const assistantResponsePrefix = `Here is the PR description for the work done in your current branch:\n${truncatedCommitMessage}`
return new Interaction(
{ speaker: 'human', text: promptMessage, displayText: rawDisplayText },
{
Expand Down
12 changes: 6 additions & 6 deletions client/cody-shared/src/chat/recipes/generate-release-notes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { spawnSync } from 'child_process'

import { MAX_RECIPE_INPUT_TOKENS } from '../../prompt/constants'
import { truncateText, isTextTruncated } from '../../prompt/truncation'
import { truncateText } from '../../prompt/truncation'
import { Interaction } from '../transcript/interaction'

import { Recipe, RecipeContext, RecipeID } from './recipe'
Expand Down Expand Up @@ -77,14 +77,14 @@ export class ReleaseNotes implements Recipe {
}

const truncatedGitLogOutput = truncateText(gitLogOutput, MAX_RECIPE_INPUT_TOKENS)
if (isTextTruncated(gitLogOutput, truncatedGitLogOutput)) {
await context.editor.showWarningMessage(
'Truncated extra long git log output, so release notes may miss some changes.'
)
console.log(truncatedGitLogOutput)
let truncatedLogMessage = ''
if (truncatedGitLogOutput.length < gitLogOutput.length) {
truncatedLogMessage = 'Truncated extra long git log output, so release notes may miss some changes.'
}

const promptMessage = `Generate release notes by summarising these commits:\n${truncatedGitLogOutput}\n\nUse proper heading format for the release notes.\n\n${tagsPromptText}.Do not include other changes and dependency updates.`
const assistantResponsePrefix = `Here is the generated release notes for ${selectedLabel}\n`
const assistantResponsePrefix = `Here is the generated release notes for ${selectedLabel}\n${truncatedLogMessage}`
return new Interaction(
{ speaker: 'human', text: promptMessage, displayText: rawDisplayText },
{
Expand Down
13 changes: 2 additions & 11 deletions client/cody-shared/src/chat/recipes/generate-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MAX_RECIPE_INPUT_TOKENS, MAX_RECIPE_SURROUNDING_TOKENS } from '../../prompt/constants'
import { truncateText, truncateTextStart, isTextTruncated } from '../../prompt/truncation'
import { truncateText, truncateTextStart } from '../../prompt/truncation'
import { Interaction } from '../transcript/interaction'

import {
Expand All @@ -23,18 +23,9 @@ export class GenerateTest implements Recipe {
const truncatedSelectedText = truncateText(selection.selectedText, MAX_RECIPE_INPUT_TOKENS)
const truncatedPrecedingText = truncateTextStart(selection.precedingText, MAX_RECIPE_SURROUNDING_TOKENS)
const truncatedFollowingText = truncateText(selection.followingText, MAX_RECIPE_SURROUNDING_TOKENS)

if (
isTextTruncated(selection.selectedText, truncatedSelectedText) ||
isTextTruncated(selection.precedingText, truncatedPrecedingText) ||
isTextTruncated(selection.followingText, truncatedFollowingText)
) {
await context.editor.showWarningMessage('Truncated extra long selection so output may be incomplete.')
}

const extension = getFileExtension(selection.fileName)
const languageName = getNormalizedLanguageName(selection.fileName)

const languageName = getNormalizedLanguageName(selection.fileName)
const promptMessage = `Generate a unit test in ${languageName} for the following code:\n\`\`\`${extension}\n${truncatedSelectedText}\n\`\`\`\n${MARKDOWN_FORMAT_PROMPT}`
const assistantResponsePrefix = `Here is the generated unit test:\n\`\`\`${extension}\n`

Expand Down
11 changes: 5 additions & 6 deletions client/cody-shared/src/chat/recipes/git-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { spawnSync } from 'child_process'
import path from 'path'

import { MAX_RECIPE_INPUT_TOKENS } from '../../prompt/constants'
import { truncateText, isTextTruncated } from '../../prompt/truncation'
import { truncateText } from '../../prompt/truncation'
import { Interaction } from '../transcript/interaction'

import { Recipe, RecipeContext, RecipeID } from './recipe'
Expand Down Expand Up @@ -71,14 +71,13 @@ export class GitHistory implements Recipe {
}

const truncatedGitLogOutput = truncateText(gitLogOutput, MAX_RECIPE_INPUT_TOKENS)
if (isTextTruncated(gitLogOutput, truncatedGitLogOutput)) {
await context.editor.showWarningMessage(
'Truncated extra long git log output, so summary may be incomplete.'
)
let truncatedLogMessage = ''
if (truncatedGitLogOutput.length < gitLogOutput.length) {
truncatedLogMessage = 'Truncated extra long git log output, so summary may be incomplete.'
}

const promptMessage = `Summarize these commits:\n${truncatedGitLogOutput}\n\nProvide your response in the form of a bulleted list. Do not mention the commit hashes.`
const assistantResponsePrefix = 'Here is a summary of recent changes:\n'
const assistantResponsePrefix = `Here is a summary of recent changes:\n${truncatedLogMessage}`
return new Interaction(
{ speaker: 'human', text: promptMessage, displayText: rawDisplayText },
{
Expand Down
10 changes: 1 addition & 9 deletions client/cody-shared/src/chat/recipes/improve-variable-names.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MAX_RECIPE_INPUT_TOKENS, MAX_RECIPE_SURROUNDING_TOKENS } from '../../prompt/constants'
import { truncateText, truncateTextStart, isTextTruncated } from '../../prompt/truncation'
import { truncateText, truncateTextStart } from '../../prompt/truncation'
import { Interaction } from '../transcript/interaction'

import {
Expand All @@ -23,14 +23,6 @@ export class ImproveVariableNames implements Recipe {
const truncatedSelectedText = truncateText(selection.selectedText, MAX_RECIPE_INPUT_TOKENS)
const truncatedPrecedingText = truncateTextStart(selection.precedingText, MAX_RECIPE_SURROUNDING_TOKENS)
const truncatedFollowingText = truncateText(selection.followingText, MAX_RECIPE_SURROUNDING_TOKENS)

if (
isTextTruncated(selection.selectedText, truncatedSelectedText) ||
isTextTruncated(selection.precedingText, truncatedPrecedingText) ||
isTextTruncated(selection.followingText, truncatedFollowingText)
) {
await context.editor.showWarningMessage('Truncated extra long selection.')
}
const extension = getFileExtension(selection.fileName)

const displayText = `Improve the variable names in the following code:\n\`\`\`\n${selection.selectedText}\n\`\`\``
Expand Down
2 changes: 1 addition & 1 deletion client/cody-shared/src/chat/recipes/next-questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class NextQuestions implements Recipe {

const maxTokenCount =
MAX_AVAILABLE_PROMPT_LENGTH - (promptPrefix.length + promptSuffix.length) / CHARS_PER_TOKEN
const truncatedText = truncateText(humanChatInput, Math.min(maxTokenCount, MAX_AVAILABLE_PROMPT_LENGTH))
const truncatedText = truncateText(humanChatInput, maxTokenCount)
const promptMessage = `${promptPrefix}\n\n\`\`\`\n${truncatedText}\n\`\`\`\n\n${promptSuffix}`

const assistantResponsePrefix = 'Sure, here are great follow-up discussion topics and learning ideas:\n\n - '
Expand Down
10 changes: 1 addition & 9 deletions client/cody-shared/src/chat/recipes/optimize-code.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MAX_RECIPE_INPUT_TOKENS, MAX_RECIPE_SURROUNDING_TOKENS } from '../../prompt/constants'
import { truncateText, truncateTextStart, isTextTruncated } from '../../prompt/truncation'
import { truncateText, truncateTextStart } from '../../prompt/truncation'
import { Interaction } from '../transcript/interaction'

import {
Expand All @@ -22,14 +22,6 @@ export class OptimizeCode implements Recipe {
const truncatedSelectedText = truncateText(selection.selectedText, MAX_RECIPE_INPUT_TOKENS)
const truncatedPrecedingText = truncateTextStart(selection.precedingText, MAX_RECIPE_SURROUNDING_TOKENS)
const truncatedFollowingText = truncateText(selection.followingText, MAX_RECIPE_SURROUNDING_TOKENS)

if (
isTextTruncated(selection.selectedText, truncatedSelectedText) ||
isTextTruncated(selection.precedingText, truncatedPrecedingText) ||
isTextTruncated(selection.followingText, truncatedFollowingText)
) {
await context.editor.showWarningMessage('Truncated extra long selection so output may be incomplete.')
}
const extension = getFileExtension(selection.fileName)

const displayText = `Optimize the time and space consumption of the following code:\n\`\`\`\n${selection.selectedText}\n\`\`\``
Expand Down
9 changes: 3 additions & 6 deletions client/cody-shared/src/chat/recipes/translate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MAX_RECIPE_INPUT_TOKENS } from '../../prompt/constants'
import { truncateText, isTextTruncated } from '../../prompt/truncation'
import { truncateText } from '../../prompt/truncation'
import { Interaction } from '../transcript/interaction'

import { languageMarkdownID, languageNames } from './langs'
Expand All @@ -19,16 +19,13 @@ export class TranslateToLanguage implements Recipe {

const toLanguage = await context.editor.showQuickPick(languageNames)
if (!toLanguage) {
await context.editor.showWarningMessage('No language selected. Please select a language and try again.')
// TODO: Show the warning within the Chat UI.
// editor.showWarningMessage('Must pick a language to translate to.')
return null
}

const truncatedSelectedText = truncateText(selection.selectedText, MAX_RECIPE_INPUT_TOKENS)

if (isTextTruncated(selection.selectedText, truncatedSelectedText)) {
await context.editor.showWarningMessage('Truncated extra long selection so output may be incomplete.')
}

const promptMessage = `Translate the following code into ${toLanguage}\n\`\`\`\n${truncatedSelectedText}\n\`\`\``
const displayText = `Translate the following code into ${toLanguage}\n\`\`\`\n${selection.selectedText}\n\`\`\``

Expand Down
10 changes: 0 additions & 10 deletions client/cody-shared/src/prompt/truncation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,3 @@ export function truncateTextStart(text: string, maxTokens: number): string {
const maxLength = maxTokens * CHARS_PER_TOKEN
return text.length <= maxLength ? text : text.slice(-maxLength - 1)
}

/**
* Checks if the text has been truncated
*/
export function isTextTruncated(text: string, truncateText: string): boolean {
if (truncateText.length < text.length) {
return true
}
return false
}

0 comments on commit af3b8ed

Please sign in to comment.