Skip to content

Commit 6cb827d

Browse files
committed
Revise and implemented requested changes from PR#56 review
1 parent e4b160f commit 6cb827d

File tree

7 files changed

+49
-31
lines changed

7 files changed

+49
-31
lines changed

src/benchmark/framework/experiment/setupDSL/benchmarkingBundleBuilder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export type CorrespondingInputParams<T extends LLMServiceStringIdentifier> =
2121
: T extends "grazie"
2222
? InputBenchmarkingModelParams.GrazieParams
2323
: T extends "lmstudio"
24-
? InputBenchmarkingModelParams.DeepSeekParams
24+
? InputBenchmarkingModelParams.LMStudioParams
2525
: T extends "deepseek"
26-
? InputBenchmarkingModelParams.LMStudioParams
26+
? InputBenchmarkingModelParams.DeepSeekParams
2727
: never;
2828

2929
export class BenchmarkingBundle {

src/extension/settings/configReaders.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function readAndValidateUserModelsParams(
126126
...lmStudioUserParams,
127127
...deepSeekUserParams,
128128
]);
129-
validateApiKeysAreProvided(openAiUserParams, grazieUserParams);
129+
validateApiKeysAreProvided(openAiUserParams, grazieUserParams, deepSeekUserParams);
130130

131131
const modelsParams: ModelsParams = {
132132
predefinedProofsModelParams: resolveParamsAndShowResolutionLogs(
@@ -213,7 +213,8 @@ function validateIdsAreUnique(allModels: UserModelParams[]) {
213213

214214
function validateApiKeysAreProvided(
215215
openAiUserParams: OpenAiUserModelParams[],
216-
grazieUserParams: GrazieUserModelParams[]
216+
grazieUserParams: GrazieUserModelParams[],
217+
deepSeekUserParams: DeepSeekUserModelParams[]
217218
) {
218219
const buildApiKeyError = (
219220
serviceName: string,
@@ -233,6 +234,9 @@ function validateApiKeysAreProvided(
233234
if (grazieUserParams.some((params) => params.apiKey === "None")) {
234235
throw buildApiKeyError("Grazie", "grazie");
235236
}
237+
if (deepSeekUserParams.some((params) => params.apiKey === "None")) {
238+
throw buildApiKeyError("Deep Seek", "deepSeek");
239+
}
236240
}
237241

238242
function validateModelsArePresent<T>(allModels: T[]) {

src/llm/llmIterator.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class LLMSequentialIterator
3636
);
3737
}
3838

39+
// TODO: Implement a smarter way of ordering the services
3940
private createHooks(
4041
proofGenerationContext: ProofGenerationContext,
4142
modelsParams: ModelsParams,
@@ -48,6 +49,16 @@ export class LLMSequentialIterator
4849
services.predefinedProofsService,
4950
"predefined-proofs"
5051
),
52+
// Here DeepSeek service is reordered to the beginning
53+
// of the list, due to it's strong performance and
54+
// low costs. Refer to discussion:
55+
// https://github.com/JetBrains-Research/coqpilot/pull/56#discussion_r1935180516
56+
...this.createLLMServiceHooks(
57+
proofGenerationContext,
58+
modelsParams.deepSeekParams,
59+
services.deepSeekService,
60+
"deepseek"
61+
),
5162
...this.createLLMServiceHooks(
5263
proofGenerationContext,
5364
modelsParams.openAiParams,
@@ -66,12 +77,6 @@ export class LLMSequentialIterator
6677
services.lmStudioService,
6778
"lm-studio"
6879
),
69-
...this.createLLMServiceHooks(
70-
proofGenerationContext,
71-
modelsParams.deepSeekParams,
72-
services.deepSeekService,
73-
"deepseek"
74-
),
7580
];
7681
}
7782

src/llm/llmServices/deepSeek/deepSeekModelParamsResolver.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export class DeepSeekModelParamsResolver
1919
.requiredToBeConfigured()
2020
.validate([
2121
(value) =>
22-
DeepSeekModelParamsResolver._allowedModels.includes(value),
23-
`be one of the allowed models: ${DeepSeekModelParamsResolver._allowedModels.join(
22+
DeepSeekModelParamsResolver.allowedModels.includes(value),
23+
`be one of the allowed models: ${DeepSeekModelParamsResolver.allowedModels.join(
2424
", "
2525
)}`,
2626
]);
@@ -36,5 +36,5 @@ export class DeepSeekModelParamsResolver
3636
.requiredToBeConfigured()
3737
.validateAtRuntimeOnly();
3838

39-
static readonly _allowedModels = ["deepseek-chat", "deepseek-reasoner"];
39+
static readonly allowedModels = ["deepseek-chat", "deepseek-reasoner"];
4040
}

src/llm/llmServices/deepSeek/deepSeekService.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import { ProofVersion } from "../commonStructures/proofVersion";
1111
import { GeneratedProofImpl } from "../generatedProof";
1212
import { LLMServiceImpl } from "../llmService";
1313
import { LLMServiceInternal } from "../llmServiceInternal";
14-
import { OpenAiModelParams } from "../modelParams";
1514
import { DeepSeekModelParams } from "../modelParams";
1615
import { toO1CompatibleChatHistory } from "../utils/o1ClassModels";
1716

1817
import { DeepSeekModelParamsResolver } from "./deepSeekModelParamsResolver";
18+
import { illegalState } from "../../../utils/throwErrors";
1919

2020
export class DeepSeekService extends LLMServiceImpl<
2121
DeepSeekUserModelParams,
@@ -31,8 +31,6 @@ export class DeepSeekService extends LLMServiceImpl<
3131
this.generationsLoggerBuilder
3232
);
3333
protected readonly modelParamsResolver = new DeepSeekModelParamsResolver();
34-
35-
static readonly baseApiUrl = "https://api.deepseek.com/v1";
3634
}
3735

3836
export class DeepSeekGeneratedProof extends GeneratedProofImpl<
@@ -44,7 +42,7 @@ export class DeepSeekGeneratedProof extends GeneratedProofImpl<
4442
constructor(
4543
rawProof: GeneratedRawContentItem,
4644
proofGenerationContext: ProofGenerationContext,
47-
modelParams: OpenAiModelParams,
45+
modelParams: DeepSeekModelParams,
4846
llmServiceInternal: DeepSeekServiceInternal,
4947
previousProofVersions?: ProofVersion[]
5048
) {
@@ -64,10 +62,12 @@ class DeepSeekServiceInternal extends LLMServiceInternal<
6462
DeepSeekGeneratedProof,
6563
DeepSeekServiceInternal
6664
> {
65+
static readonly baseApiUrl = "https://api.deepseek.com/v1";
66+
6767
constructGeneratedProof(
6868
rawProof: GeneratedRawContentItem,
6969
proofGenerationContext: ProofGenerationContext,
70-
modelParams: OpenAiModelParams,
70+
modelParams: DeepSeekModelParams,
7171
previousProofVersions?: ProofVersion[] | undefined
7272
): DeepSeekGeneratedProof {
7373
return new DeepSeekGeneratedProof(
@@ -81,22 +81,22 @@ class DeepSeekServiceInternal extends LLMServiceInternal<
8181

8282
async generateFromChatImpl(
8383
analyzedChat: AnalyzedChatHistory,
84-
params: OpenAiModelParams,
84+
params: DeepSeekModelParams,
8585
choices: number
8686
): Promise<GeneratedRawContent> {
8787
LLMServiceInternal.validateChoices(choices);
8888

89-
const openai = new OpenAI({
89+
const openaiCompatibleApi = new OpenAI({
9090
apiKey: params.apiKey,
91-
baseURL: DeepSeekService.baseApiUrl,
91+
baseURL: DeepSeekServiceInternal.baseApiUrl,
9292
});
9393
const formattedChat = this.formatChatHistory(analyzedChat.chat, params);
9494
this.logDebug.event("Completion requested", {
9595
history: formattedChat,
9696
});
9797

9898
try {
99-
const completion = await openai.chat.completions.create({
99+
const completion = await openaiCompatibleApi.chat.completions.create({
100100
messages: formattedChat,
101101
model: params.modelName,
102102
n: choices,
@@ -107,7 +107,7 @@ class DeepSeekServiceInternal extends LLMServiceInternal<
107107
const rawContentItems = completion.choices.map((choice) => {
108108
const content = choice.message.content;
109109
if (content === null) {
110-
throw Error("response message content is null");
110+
illegalState("response message content is null");
111111
}
112112
return content;
113113
});
@@ -131,7 +131,7 @@ class DeepSeekServiceInternal extends LLMServiceInternal<
131131
rawContentItems: string[],
132132
tokensUsage: OpenAI.Completions.CompletionUsage | undefined,
133133
analyzedChat: AnalyzedChatHistory,
134-
params: OpenAiModelParams
134+
params: DeepSeekModelParams
135135
): GeneratedRawContent {
136136
const promptTokens =
137137
tokensUsage?.prompt_tokens ??
@@ -150,8 +150,8 @@ class DeepSeekServiceInternal extends LLMServiceInternal<
150150

151151
private formatChatHistory(
152152
chat: ChatHistory,
153-
modelParams: OpenAiModelParams
153+
modelParams: DeepSeekModelParams
154154
): ChatHistory {
155-
return toO1CompatibleChatHistory(chat, modelParams.modelName, "openai");
155+
return toO1CompatibleChatHistory(chat, modelParams.modelName, "deepseek");
156156
}
157157
}

src/llm/llmServices/utils/o1ClassModels.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ const o1ClassModelsOpenAI = [
99

1010
const o1ClassModelsGrazie = ["openai-o1", "openai-o1-mini"];
1111

12+
// TODO: When DeepSeek API becomes stable:
13+
// check whether the r1 model chat history is compatible with o1 model
14+
const o1ClassModelsDeepSeek = ["deepseek-reasoner"];
15+
1216
/**
1317
* As of November 2024, o1 model requires a different format of chat history.
1418
* It doesn't support the system prompt, therefore we manually
@@ -18,10 +22,15 @@ const o1ClassModelsGrazie = ["openai-o1", "openai-o1-mini"];
1822
export function toO1CompatibleChatHistory(
1923
chatHistory: ChatHistory,
2024
modelName: string,
21-
service: "openai" | "grazie"
25+
service: "openai" | "grazie" | "deepseek"
2226
): ChatHistory {
2327
const o1ClassModels =
24-
service === "openai" ? o1ClassModelsOpenAI : o1ClassModelsGrazie;
28+
service === "openai"
29+
? o1ClassModelsOpenAI
30+
: service === "grazie"
31+
? o1ClassModelsGrazie
32+
: o1ClassModelsDeepSeek;
33+
2534
if (o1ClassModels.includes(modelName)) {
2635
return chatHistory.map((message: ChatMessage) => {
2736
return {

src/test/llm/parseUserModelParams.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ suite("Parse `UserModelParams` from JSON test", () => {
6666
const validOpenAiUserModelParamsComplete = {
6767
...validUserModelParamsCompelete,
6868
modelName: "gpt-model",
69-
temperature: 36.6,
69+
temperature: 0.8,
7070
apiKey: "api-key",
7171
};
7272
const validGrazieUserModelParamsComplete = {
@@ -77,13 +77,13 @@ suite("Parse `UserModelParams` from JSON test", () => {
7777
};
7878
const validLMStudioUserModelParamsComplete = {
7979
...validUserModelParamsCompelete,
80-
temperature: 36.6,
80+
temperature: 0.8,
8181
port: 555,
8282
};
8383
const validDeepSeekUserModelParamsComplete = {
8484
...validUserModelParamsCompelete,
8585
modelName: "deepseek-chat",
86-
temperature: 36.6,
86+
temperature: 0.8,
8787
apiKey: "api-key",
8888
};
8989

0 commit comments

Comments
 (0)