Skip to content

Commit f74a99c

Browse files
Merge pull request #6214 from uinstinct/llm-context-length
improve: increase default context length and add tests for detecting context length
2 parents deda3f0 + 8a79d55 commit f74a99c

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

core/llm/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const DEFAULT_MAX_TOKENS = 4096;
2-
const DEFAULT_CONTEXT_LENGTH = 8192;
2+
const DEFAULT_CONTEXT_LENGTH = 32_768;
33
const DEFAULT_TEMPERATURE = 0.5;
44

55
const DEFAULT_ARGS = {

core/llm/index.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { ChatMessage, LLMOptions } from "..";
22

3+
import { allModelProviders } from "@continuedev/llm-info";
4+
import { LlmInfo } from "@continuedev/llm-info/dist/types";
35
import { BaseLLM } from ".";
6+
import { DEFAULT_CONTEXT_LENGTH } from "./constants";
7+
import { LLMClasses } from "./llms";
48
import { LLMLogger } from "./logger";
59

610
class DummyLLM extends BaseLLM {
@@ -140,4 +144,31 @@ describe("BaseLLM", () => {
140144
describe("*streamChat", () => {
141145
// TODO: Implement tests for *streamChat method
142146
});
147+
148+
describe("default context length", () => {
149+
allModelProviders.map((modelProvider) => {
150+
const LLMClass = LLMClasses.find(
151+
(llm) => llm.providerName === modelProvider.id,
152+
);
153+
if (!LLMClass) {
154+
throw new Error(`did not find LLM provider for ${modelProvider.id}`);
155+
}
156+
const testContextLength = (llmInfo: LlmInfo) => () => {
157+
const llm = new LLMClass({ model: llmInfo.model });
158+
if (llmInfo.contextLength) {
159+
expect(llm.contextLength).toEqual(llmInfo.contextLength);
160+
} else {
161+
expect(llm.contextLength).toEqual(DEFAULT_CONTEXT_LENGTH);
162+
}
163+
};
164+
describe(`${modelProvider.id}`, () => {
165+
modelProvider.models.forEach((llmInfo) => {
166+
test(
167+
`should have correct context length for ${llmInfo.model}`,
168+
testContextLength(llmInfo),
169+
);
170+
});
171+
});
172+
});
173+
});
143174
});

core/llm/llms/Anthropic.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class Anthropic extends BaseLLM {
88
static providerName = "anthropic";
99
static defaultOptions: Partial<LLMOptions> = {
1010
model: "claude-3-5-sonnet-latest",
11-
contextLength: 200_000,
1211
completionOptions: {
1312
model: "claude-3-5-sonnet-latest",
1413
maxTokens: 8192,

core/llm/llms/Bedrock.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class Bedrock extends BaseLLM {
4848
static defaultOptions: Partial<LLMOptions> = {
4949
region: "us-east-1",
5050
model: "anthropic.claude-3-sonnet-20240229-v1:0",
51-
contextLength: 200_000,
5251
profile: "bedrock",
5352
};
5453

0 commit comments

Comments
 (0)