Skip to content

Commit

Permalink
Smart Apply: Enable by default (#5250)
Browse files Browse the repository at this point in the history
## Description

Enables the "smart apply" feature by default, removing the feature flag.

Chat Eval: sourcegraph/cody-leaderboard#16

Looker Dashboard: https://sourcegraph.looker.com/looks/2016


## Test plan

Test Smart Apply on:
- [x] PLG
- [x] Enterprise (with different model variants)
- [X] JetBrains (with WebView enabled)
- Note: Further testing will be done by the JetBrains team when the
WebView is fully implemented

<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
  • Loading branch information
umpox authored Aug 20, 2024
1 parent a8b07c3 commit 093fc71
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 87 deletions.
21 changes: 14 additions & 7 deletions agent/recordings/cody-chat_103640681/recording.har.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 18 additions & 18 deletions agent/recordings/defaultClient_631904893/recording.har.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion agent/src/cli/__snapshots__/command-chat.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ stdout: |+
\`\`\`typescript
Here's the implementation of a cow without any explanation:
\`\`\`typescript:animal.ts
class Cow implements StrangeAnimal {
makesSound(): 'coo' | 'moo' {
return 'moo';
Expand Down
4 changes: 2 additions & 2 deletions agent/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ describe('Agent', () => {
// is not a git directory and symf reports some git-related error.
expect(trimEndOfLine(lastMessage?.text ?? '')).toMatchInlineSnapshot(
`
"Certainly! Here's a Dog class that implements the Animal interface based on the context provided:
"Certainly! Here's a class Dog that implements the Animal interface based on the context provided:
\`\`\`typescript:src/animal.ts
export class Dog implements Animal {
Expand All @@ -472,7 +472,7 @@ describe('Agent', () => {
}
\`\`\`
This implementation satisfies the Animal interface requirements as defined in your workspace."
This Dog class fully implements the Animal interface as defined in your workspace."
`,
explainPollyError
)
Expand Down
3 changes: 0 additions & 3 deletions lib/shared/src/experimentation/FeatureFlagProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ export enum FeatureFlag {
CodyServerSideContextAPI = 'cody-server-side-context-api-enabled',

GitMentionProvider = 'git-mention-provider',

/** Enable experimental smart apply and chat codeblock UI */
CodyExperimentalSmartApply = 'cody-experimental-smart-apply',
}

const ONE_HOUR = 60 * 60 * 1000
Expand Down
16 changes: 5 additions & 11 deletions lib/shared/src/prompt/prompt-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PromptString, ps } from './prompt-string'
* Used so that we can parse file paths to support applying code directly to files
* from chat.
*/
const CODEBLOCK_PREMAMBLE = ps`When generating fenced code blocks in Markdown, ensure you include the full file path in the tag. The structure should be \`\`\`language:path/to/file\n\`\`\``
const CODEBLOCK_PREMAMBLE = ps`When generating fenced code blocks in Markdown, ensure you include the full file path in the tag. The structure should be \`\`\`language:path/to/file\n\`\`\`. You should only do this when generating a code block, the user does not need to be made aware of this in any other way.`

/**
* The preamble we add to the start of the last human open-end chat message that has context items.
Expand All @@ -30,18 +30,12 @@ export class PromptMixin {
* Prepends all mixins to `humanMessage`. Modifies and returns `humanMessage`.
* Add hedging prevention prompt to specific models who need this.
*/
public static mixInto(
humanMessage: ChatMessage,
modelID: string,
options?: { experimentalSmartApplyEnabled?: boolean }
): ChatMessage {
public static mixInto(humanMessage: ChatMessage, modelID: string): ChatMessage {
// Default Mixin is added at the end so that it cannot be overriden by other mixins.
let mixins = PromptString.join(
[
...PromptMixin.mixins,
...(options?.experimentalSmartApplyEnabled ? [PromptMixin.codeBlockMixin] : []),
PromptMixin.contextMixin,
].map(mixin => mixin.prompt),
[...PromptMixin.mixins, PromptMixin.codeBlockMixin, PromptMixin.contextMixin].map(
mixin => mixin.prompt
),
ps`\n\n`
)

Expand Down
23 changes: 5 additions & 18 deletions vscode/src/chat/chat-view/ChatController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
DOTCOM_URL,
type DefaultChatCommands,
type EventSource,
FeatureFlag,
type Guardrails,
type Message,
ModelUsage,
Expand Down Expand Up @@ -64,7 +63,7 @@ import {
import type { startTokenReceiver } from '../../auth/token-receiver'
import { getContextFileFromUri } from '../../commands/context/file-path'
import { getContextFileFromCursor, getContextFileFromSelection } from '../../commands/context/selection'
import { getConfigWithEndpoint, getConfiguration, getFullConfig } from '../../configuration'
import { getConfigWithEndpoint, getConfiguration } from '../../configuration'
import type { EnterpriseContextFactory } from '../../context/enterprise-context-factory'
import { type RemoteSearch, RepoInclusion } from '../../context/remote-search'
import type { Repo } from '../../context/repo-fetcher'
Expand Down Expand Up @@ -562,22 +561,12 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
}
}

private async isSmartApplyEnabled(): Promise<boolean> {
if (this.extensionClient.capabilities?.edit === 'none') {
// Smart Apply relies on the Edit capability
return false
}

const config = await getFullConfig()
return (
config.internalUnstable ||
(await featureFlagProvider.evaluateFeatureFlag(FeatureFlag.CodyExperimentalSmartApply))
)
private isSmartApplyEnabled(): boolean {
return this.extensionClient.capabilities?.edit !== 'none'
}

private async getConfigForWebview(): Promise<ConfigurationSubsetForWebview & LocalEnv> {
const config = getConfigWithEndpoint()
const experimentalSmartApply = await this.isSmartApplyEnabled()
const sidebarViewOnly = this.extensionClient.capabilities?.webviewNativeConfig?.view === 'single'
const isEditorViewType = this.webviewPanelOrView?.viewType === 'cody.editorPanel'
const webviewType = isEditorViewType && !sidebarViewOnly ? 'editor' : 'sidebar'
Expand All @@ -590,7 +579,7 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
uiKindIsWeb: vscode.env.uiKind === vscode.UIKind.Web,
serverEndpoint: config.serverEndpoint,
experimentalNoodle: config.experimentalNoodle,
experimentalSmartApply,
smartApply: this.isSmartApplyEnabled(),
webviewType,
multipleWebviewsEnabled: !sidebarViewOnly,
internalDebugContext: config.internalDebugContext,
Expand Down Expand Up @@ -1254,11 +1243,9 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
sendTelemetry?: (contextSummary: any, privateContextSummary?: any) => void,
contextAlternatives?: RankedContext[]
): Promise<Message[]> {
const experimentalSmartApplyEnabled = await this.isSmartApplyEnabled()
const { prompt, context } = await prompter.makePrompt(
this.chatModel,
this.authProvider.getAuthStatus().codyApiVersion,
{ experimentalSmartApplyEnabled }
this.authProvider.getAuthStatus().codyApiVersion
)
abortSignal.throwIfAborted()

Expand Down
8 changes: 2 additions & 6 deletions vscode/src/chat/chat-view/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ export class DefaultPrompter {
//
// Returns the reverse prompt and the new context that was used in the prompt for the current message.
// If user-context added at the last message is ignored, returns the items in the newContextIgnored array.
public async makePrompt(
chat: ChatModel,
codyApiVersion: number,
options?: { experimentalSmartApplyEnabled?: boolean }
): Promise<PromptInfo> {
public async makePrompt(chat: ChatModel, codyApiVersion: number): Promise<PromptInfo> {
return wrapInActiveSpan('chat.prompter', async () => {
const promptBuilder = await PromptBuilder.create(chat.contextWindow)
const preInstruction: PromptString | undefined = PromptString.fromConfig(
Expand Down Expand Up @@ -76,7 +72,7 @@ export class DefaultPrompter {
!this.isCommand &&
Boolean(this.explicitContext.length || historyItems.length || this.corpusContext.length)
) {
reverseTranscript[0] = PromptMixin.mixInto(reverseTranscript[0], chat.modelID, options)
reverseTranscript[0] = PromptMixin.mixInto(reverseTranscript[0], chat.modelID)
}

const messagesIgnored = promptBuilder.tryAddMessages(reverseTranscript)
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/chat/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export interface ConfigurationSubsetForWebview
| 'agentExtensionVersion'
| 'internalDebugContext'
> {
experimentalSmartApply: boolean
smartApply: boolean
// Type/location of the current webview.
webviewType?: WebviewType | undefined | null
// Whether support running multiple webviews (e.g. sidebar w/ multiple editor panels).
Expand Down
2 changes: 1 addition & 1 deletion vscode/webviews/App.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const dummyVSCodeAPI: VSCodeWrapper = {
serverEndpoint: 'https://example.com',
uiKindIsWeb: false,
experimentalNoodle: false,
experimentalSmartApply: false,
smartApply: false,
},
authStatus: {
...defaultAuthStatus,
Expand Down
2 changes: 1 addition & 1 deletion vscode/webviews/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export const App: React.FunctionComponent<{ vscodeAPI: VSCodeWrapper }> = ({ vsc
isTranscriptError={isTranscriptError}
guardrails={guardrails}
userHistory={userHistory}
experimentalSmartApplyEnabled={config.config.experimentalSmartApply}
smartApplyEnabled={config.config.smartApply}
/>
)}
</ComposedWrappers>
Expand Down
Loading

0 comments on commit 093fc71

Please sign in to comment.