Elffuss BraidHub

kikocis/continue public

d0cd3fef8227 · 4.6 KiBRawPermalink
1import { ChatMessage, LLMOptions } from "..";
2
3import { BaseLLM } from ".";
4import { LLMLogger } from "./logger";
5
6class DummyLLM extends BaseLLM {
7 static providerName = "openai";
8 static defaultOptions: Partial<LLMOptions> = {
9 model: "dummy-model",
10 contextLength: 200_000,
11 completionOptions: {
12 model: "some-model",
13 maxTokens: 4096,
14 },
15 apiBase: "https://api.test-api-dummy.com/v1/",
16 };
17}
18describe("BaseLLM", () => {
19 let baseLLM: BaseLLM;
20
21 beforeEach(() => {
22 const options: LLMOptions = {
23 model: "dummy-model",
24 };
25 // Instantiate a DummyLLM instance
26 baseLLM = new DummyLLM(options);
27 });
28
29 describe("BaseLLM constructor", () => {
30 it("should correctly initialize with given options", () => {
31 const templatMessagesFunction = (messages: ChatMessage[]) => {
32 return messages[0]?.content.toString() ?? "";
33 };
34 const llmLogger = new LLMLogger();
35 const options: LLMOptions = {
36 model: "gpt-3.5-turbo",
37 uniqueId: "testId",
38 contextLength: 1024,
39 completionOptions: {
40 model: "some-model",
41 maxTokens: 150,
42 },
43 requestOptions: {},
44 promptTemplates: {},
45 templateMessages: templatMessagesFunction,
46 logger: llmLogger,
47 llmRequestHook: () => {},
48 apiKey: "testApiKey",
49 aiGatewaySlug: "testSlug",
50 apiBase: "https://api.example.com",
51 accountId: "testAccountId",
52 deployment: "davinci",
53 apiVersion: "v1",
54 apiType: "public",
55 region: "us",
56 projectId: "testProjectId",
57 };
58
59 const instance = new DummyLLM(options);
60
61 expect(instance.title).toBeDefined();
62 expect(instance.uniqueId).toBe("testId");
63 expect(instance.model).toBe("gpt-3.5-turbo");
64 expect(instance.contextLength).toBe(1024);
65 expect(instance.completionOptions.maxTokens).toBe(150);
66 expect(instance.requestOptions).toEqual({});
67 expect(instance.promptTemplates).toEqual({});
68 expect(instance.templateMessages).toEqual(templatMessagesFunction);
69 expect(instance.logger).toBe(llmLogger);
70 expect(instance.apiKey).toBe("testApiKey");
71 expect(instance.aiGatewaySlug).toBe("testSlug");
72 expect(instance.apiBase).toBe("https://api.example.com/");
73 expect(instance.accountId).toBe("testAccountId");
74 expect(instance.deployment).toBe("davinci");
75 expect(instance.apiVersion).toBe("v1");
76 expect(instance.apiType).toBe("public");
77 expect(instance.region).toBe("us");
78 expect(instance.projectId).toBe("testProjectId");
79 });
80 });
81
82 test("model should return correct provider model", () => {
83 expect(baseLLM.model).toBe("dummy-model");
84 });
85
86 test("supportsFim should always return false", () => {
87 expect(baseLLM.supportsFim()).toBe(false);
88 });
89
90 describe("supportsImages", () => {
91 test("should return true when modelSupportsImages returns true", () => {
92 baseLLM.model = "gpt-4-vision";
93 expect(baseLLM.supportsImages()).toBe(true);
94 });
95
96 test("should return false when modelSupportsImages returns false", () => {
97 expect(baseLLM.supportsImages()).toBe(false);
98 });
99 });
100
101 describe("supportsCompletions", () => {
102 test("should return correctly under specific conditions", () => {
103 // Mocking properties and scenarios to match the conditions in supportsCompletions
104 baseLLM.apiBase = "api.groq.com";
105 expect(baseLLM.supportsCompletions()).toBe(false);
106
107 baseLLM.apiBase = "integrate.api.nvidia.com";
108 expect(baseLLM.supportsCompletions()).toBe(false);
109
110 baseLLM.apiBase = "api.mistral.ai";
111 expect(baseLLM.supportsCompletions()).toBe(false);
112
113 baseLLM.apiBase = ":1337";
114 expect(baseLLM.supportsCompletions()).toBe(false);
115
116 baseLLM.apiBase = "something:3000";
117 expect(baseLLM.supportsCompletions()).toBe(true);
118 });
119 });
120 describe("supportsPrefill", () => {
121 test("should return correctly under specific conditions", () => {
122 expect(baseLLM.supportsPrefill()).toBe(false);
123
124 class PrefillLLM extends BaseLLM {
125 static providerName = "ollama";
126 }
127 const prefillLLM = new PrefillLLM({ model: "some-model" });
128 expect(prefillLLM.supportsPrefill()).toBe(true);
129 });
130 });
131 describe("fetch", () => {
132 // TODO: Implement tests for fetch method
133 });
134 describe("*_streamFim", () => {
135 // TODO: Implement tests for *_streamFim method
136 });
137 describe("complete", () => {
138 // TODO: Implement tests for complete method
139 });
140 describe("*streamChat", () => {
141 // TODO: Implement tests for *streamChat method
142 });
143});