continue-custom/core/test/baseLLM.test.ts
Nate Sesti f72b00d38d
Dev (#1678)
* Fix an issue where CMD+K does not clear the terminal when the terminal has focus (#1671)

On MacOS, ⌘+K is bound, by default, to Terminal:Clear. Without this
change ⌘+K does not clear the terminal but instead iniates a chord
sequence and waits for the next stroke of the chord.

Co-authored-by: Rob Leidle <rleidle@tesla.com>

* Change treeSitter to cache the Language objects it loads from wasm (#1672)

Without this change, for a repository with 600 typescript files, the
indexer would fail to finish correctly and there would be many of the
following errors in the webview console log:

'Unable to load language for file ${path} RuntimeError: table index is out of bounds'

The following bash will create a repo that reproduces the problem:

current_path="."

for ((i=1; i<=20; i++)); do
    new_folder="folder-$i"
    mkdir -p "$current_path/$new_folder"
    current_path="$current_path/$new_folder"

    for ((a=1; a<=30; a++)); do
      head -c 10000 /dev/urandom | base64 > "$current_path/file-$a.ts"
    done
done

Co-authored-by: Rob Leidle <rleidle@tesla.com>

* acknowledge sourcemap flag in esbuild.js

* don't run jetbrains-release.yaml on vscode releases

* further testing for walkDir

* chore: add telemetry to commands (#1673)

* test: Add basic unit test to baseLLM (#1668)

* update version

* test: Add basic unit test to baseLLM

---------

Co-authored-by: Nate Sesti <sestinj@gmail.com>
Co-authored-by: inimaz <imaz@ai-verse.com>

* feat: add Quick Actions CodeLens feature (#1674)

* docs: add docs and schema for "OS" provider (#1536)

* ignore .env

* ✨ use and cache imports for autocomplete (#1456)

* ✨ use and cache imports for autocomplete

* fix tsc

* add voyage rerank-1

* import Handlebars

* feat: open pane on install (#1564)

* feat: open pane on activation

* comment out testing code

* chore: add telemetry for pageviews (#1576)

* feat: update onboarding w/ embeddings model (#1570)

* chore(gui): remove unused pages

* feat: add embeddings step

* feat: update styles

* feat: copy button updates

* fix: correct pull command for embed model

* fix: remove commented code

* fix: remove commented code

* feat: simplify copy btn props

* chore: rename onboarding selection event

* feat: add provider config

* fix: undo msg name

* remove dead code

* fix: invalid mode check

* fix: remove testing logic

* fix: fullscreen gui retains context when hidden, fixed fullscreen focusing (#1582)

* small UI tweaks

* media query

* feat: add best experience onboarding

* small fixes

* feat: add free trial card to onboarding (#1600)

* feat: add free trial card to onboarding

* add import

* chore: add telemetry for full screen toggle (#1618)

* rerank-lite-1

* remove doccs

* basic tests for VS Code extension

* improved testing of VS Code extension

* manually implement stop tokens for hf inference api

* chore: onboarding metrics (#1626)

* fix: pageview tracking

* feat: add onboarding telemetry

* create single `onboardingStatus` type

* improved var naming

* remove console logs

* fix windows performance issue

* rename vscodeExtension.ts

* migration of onboarding variables

* "stash" instead of "delete" in indexing progress

* fix preview.yaml

* also fix main.yaml

* Update troubleshooting.md (#1637)

* feat: add quick actions

* Update index.d.ts

* quick actions mvp

* update docs

* subscribe to vscode change settings

* Update commands.ts

* cleanup

* Update quick-actions.md

* Update VerticalPerLineCodeLensProvider.ts

* resolve feedback

---------

Co-authored-by: Nate Sesti <sestinj@gmail.com>
Co-authored-by: Nate Sesti <33237525+sestinj@users.noreply.github.com>
Co-authored-by: Jonah Wagner <jonahwagner231@gmail.com>

* chore: add `isCommandEvent` to command telemetry (#1675)

* chore: add `isCommandEvent` to command telemetry

* Update commands.ts

* Nate/better retrieval (#1677)

* deduplicatearray tests

* break out separate retrieval pipelines

* IConfigHandler

* tests for codebase indexer

* better .continueignore for continue

* indexing fixes

* ignore .gitignore and .continueignore when indexing

* retrieval pipeline improvements

* fix formatting err in out .continueignore

* add necessary filter to lance_db_cache

* update package.json version

---------

Co-authored-by: Rob Leidle <rleidle@gmail.com>
Co-authored-by: Rob Leidle <rleidle@tesla.com>
Co-authored-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>
Co-authored-by: inimaz <49730431+inimaz@users.noreply.github.com>
Co-authored-by: inimaz <imaz@ai-verse.com>
Co-authored-by: Jonah Wagner <jonahwagner231@gmail.com>
2024-07-05 23:20:28 -07:00

140 lines
4.6 KiB
TypeScript

import { ChatMessage, LLMOptions, ModelProvider } from "../index";
import { BaseLLM } from "../llm/index.js";
class DummyLLM extends BaseLLM {
static providerName: ModelProvider = "openai";
static defaultOptions: Partial<LLMOptions> = {
model: "dummy-model",
contextLength: 200_000,
completionOptions: {
model: "some-model",
maxTokens: 4096,
},
apiBase: "https://api.test-api-dummy.com/v1/",
};
}
describe("BaseLLM", () => {
let baseLLM: BaseLLM;
beforeEach(() => {
const options: LLMOptions = {
model: "dummy-model",
};
// Instantiate a DummyLLM instance
baseLLM = new DummyLLM(options);
});
describe("BaseLLM constructor", () => {
it("should correctly initialize with given options", () => {
const templatMessagesFunction = (messages: ChatMessage[]) => {
return messages[0]?.content.toString() ?? "";
};
const writeLogFunction = async () => {};
const options: LLMOptions = {
model: "gpt-3.5-turbo",
uniqueId: "testId",
systemMessage: "Test System Message",
contextLength: 1024,
completionOptions: {
model: "some-model",
maxTokens: 150,
},
requestOptions: {},
promptTemplates: {},
templateMessages: templatMessagesFunction,
writeLog: writeLogFunction,
llmRequestHook: () => {},
apiKey: "testApiKey",
aiGatewaySlug: "testSlug",
apiBase: "https://api.example.com",
accountId: "testAccountId",
engine: "davinci",
apiVersion: "v1",
apiType: "public",
region: "us",
projectId: "testProjectId",
};
const instance = new DummyLLM(options);
expect(instance.title).toBeDefined();
expect(instance.uniqueId).toBe("testId");
expect(instance.model).toBe("gpt-3.5-turbo");
expect(instance.systemMessage).toBe("Test System Message");
expect(instance.contextLength).toBe(1024);
expect(instance.completionOptions.maxTokens).toBe(150);
expect(instance.requestOptions).toEqual({});
expect(instance.promptTemplates).toEqual({});
expect(instance.templateMessages).toEqual(templatMessagesFunction);
expect(instance.writeLog).toBe(writeLogFunction);
expect(instance.apiKey).toBe("testApiKey");
expect(instance.aiGatewaySlug).toBe("testSlug");
expect(instance.apiBase).toBe("https://api.example.com/");
expect(instance.accountId).toBe("testAccountId");
expect(instance.engine).toBe("davinci");
expect(instance.apiVersion).toBe("v1");
expect(instance.apiType).toBe("public");
expect(instance.region).toBe("us");
expect(instance.projectId).toBe("testProjectId");
});
});
test("model should return correct provider model", () => {
expect(baseLLM.model).toBe("dummy-model");
});
test("supportsFim should always return false", () => {
expect(baseLLM.supportsFim()).toBe(false);
});
describe("supportsImages", () => {
test("should return true when modelSupportsImages returns true", () => {
baseLLM.model = "gpt-4-vision";
expect(baseLLM.supportsImages()).toBe(true);
});
test("should return false when modelSupportsImages returns false", () => {
expect(baseLLM.supportsImages()).toBe(false);
});
});
describe("supportsCompletions", () => {
test("should return correctly under specific conditions", () => {
// Mocking properties and scenarios to match the conditions in supportsCompletions
baseLLM.apiBase = "api.groq.com";
expect(baseLLM.supportsCompletions()).toBe(false);
baseLLM.apiBase = "api.mistral.ai";
expect(baseLLM.supportsCompletions()).toBe(false);
baseLLM.apiBase = ":1337";
expect(baseLLM.supportsCompletions()).toBe(false);
baseLLM.apiBase = "something:3000";
expect(baseLLM.supportsCompletions()).toBe(true);
});
});
describe("supportsPrefill", () => {
test("should return correctly under specific conditions", () => {
expect(baseLLM.supportsPrefill()).toBe(false);
class PrefillLLM extends BaseLLM {
static providerName: ModelProvider = "ollama";
}
const prefillLLM = new PrefillLLM({ model: "some-model" });
expect(prefillLLM.supportsPrefill()).toBe(true);
});
});
describe("fetch", () => {
// TODO: Implement tests for fetch method
});
describe("*_streamFim", () => {
// TODO: Implement tests for *_streamFim method
});
describe("complete", () => {
// TODO: Implement tests for complete method
});
describe("*streamChat", () => {
// TODO: Implement tests for *streamChat method
});
});