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

Autocomplete: Remove same line suffix information from ollama prompts #3213

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading