Skip to content

Commit

Permalink
Autocomplete: Remove same line suffix information from ollama prompts (
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp-spiess committed Feb 20, 2024
1 parent ab02cb4 commit 0d10299
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This is a log of all notable changes to Cody for VS Code. [Unreleased] changes a
- Chat: Fixed an issue where the links in the welcome message for chat are unclickable. [pull/3155](https://github.com/sourcegraph/cody/pull/3155)
- Chat: File range is now displayed correctly in the chat view. [pull/3172](https://github.com/sourcegraph/cody/pull/3172)
- Autocomplete: Fixed an issue where the loading indicator might get stuck in the loading state. [pull/3178](https://github.com/sourcegraph/cody/pull/3178)
- Autocomplete: Fixes an issue where Ollama results were sometimes not visible when the current line has text after the cursor. [pull/3213](https://github.com/sourcegraph/cody/pull/3213)

### Changed

Expand Down
3 changes: 2 additions & 1 deletion vscode/src/completions/providers/experimental-ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
type ProviderConfig,
type ProviderOptions,
} from './provider'
import { getSuffixAfterFirstNewline } from '../text-processing'

interface OllamaPromptContext {
snippets: { uri: vscode.Uri; content: string }[]
Expand Down Expand Up @@ -87,7 +88,7 @@ class ExperimentalOllamaProvider extends Provider {
currentFileNameComment,
isInfill,
prefix: this.options.docContext.prefix,
suffix: this.options.docContext.suffix,
suffix: getSuffixAfterFirstNewline(this.options.docContext.suffix),
}

if (process.env.OLLAMA_CONTEXT_SNIPPETS) {
Expand Down
16 changes: 3 additions & 13 deletions vscode/src/completions/providers/fireworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '@sourcegraph/cody-shared'

import { getLanguageConfig } from '../../tree-sitter/language'
import { getSuffixAfterFirstNewline } from '../text-processing'
import type { ContextSnippet } from '../types'
import { forkSignal, generatorWithTimeout, zipGenerators } from '../utils'
import { fetch } from '../../fetch'
Expand Down Expand Up @@ -164,6 +165,8 @@ class FireworksProvider extends Provider {
.map(line => (languageConfig ? languageConfig.commentStart + line : '// '))
.join('\n')}\n`

// We want to remove the same line suffix from a completion request since both StarCoder and Llama
// code can't handle this correctly.
const suffixAfterFirstNewline = getSuffixAfterFirstNewline(suffix)

const nextPrompt = this.createInfillingPrompt(
Expand Down Expand Up @@ -512,19 +515,6 @@ export function createProviderConfig({
}
}

// We want to remove the same line suffix from a completion request since both StarCoder and Llama
// code can't handle this correctly.
function getSuffixAfterFirstNewline(suffix: string): string {
const firstNlInSuffix = suffix.indexOf('\n')

// When there is no next line, the suffix should be empty
if (firstNlInSuffix === -1) {
return ''
}

return suffix.slice(suffix.indexOf('\n'))
}

function isStarCoderFamily(model: string): boolean {
return model.startsWith('starcoder')
}
Expand Down
11 changes: 11 additions & 0 deletions vscode/src/completions/text-processing/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,14 @@ export function getPositionAfterTextInsertion(position: Position, text?: string)

return updatedPosition
}

export function getSuffixAfterFirstNewline(suffix: string): string {
const firstNlInSuffix = suffix.indexOf('\n')

// When there is no next line, the suffix should be empty
if (firstNlInSuffix === -1) {
return ''
}

return suffix.slice(firstNlInSuffix)
}

0 comments on commit 0d10299

Please sign in to comment.