<commit_before>import * as _ from "lodash";
import * as i from "./Interfaces";
import Job from "./Job";
import PluginManager from "./PluginManager";

export default class Autocompletion implements i.AutocompletionProvider {
    static limit = 9;

    getSuggestions(job: Job) {
        let specializedProviders = PluginManager.specializedAutocompletionProviders(job.prompt.expanded);
        let providers = specializedProviders.length ? specializedProviders : PluginManager.genericAutocompletionProviders;

        return Promise.all(_.map(providers, provider => provider.getSuggestions(job))).then(results =>
            _._(results)
                .flatten()
                .filter((suggestion: i.Suggestion) => suggestion.score > 0)
                .sortBy((suggestion: i.Suggestion) => -suggestion.score)
                .uniqBy("value")
                .take(Autocompletion.limit)
                .value()
        );
    }
}<commit_msg>Score all suggestions together.<commit_after>import * as _ from "lodash";
import * as i from "./Interfaces";
import Job from "./Job";
import PluginManager from "./PluginManager";
const score: (i: string, m: string) => number = require("fuzzaldrin").score;

export default class Autocompletion implements i.AutocompletionProvider {
    static limit = 9;

    getSuggestions(job: Job) {
        let specializedProviders = PluginManager.specializedAutocompletionProviders(job.prompt.expanded);
        let providers = specializedProviders.length ? specializedProviders : PluginManager.genericAutocompletionProviders;

        return Promise.all(providers.map(provider => provider.getSuggestions(job))).then(results =>
            _._(results)
                .flatten()
                .filter((suggestion: i.Suggestion) => !suggestion.isAlreadyOnPrompt(job))
                .sortBy((suggestion: i.Suggestion) => -score(suggestion.value, suggestion.getPrefix(job)))
                .uniqBy((suggestion: i.Suggestion) => suggestion.value)
                .take(Autocompletion.limit)
                .value()
        );
    }
}
{'fraction_non_alphanumeric': 0.11417513304305757, 'fraction_numerical': 0.001451378809869376, 'mean_word_length': 2.931558935361217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '315561', 'n_tokens_mistral': 586, 'n_tokens_neox': 535, 'n_words': 116}