@@ -11,11 +11,11 @@ import { ProofVersion } from "../commonStructures/proofVersion";
11
11
import { GeneratedProofImpl } from "../generatedProof" ;
12
12
import { LLMServiceImpl } from "../llmService" ;
13
13
import { LLMServiceInternal } from "../llmServiceInternal" ;
14
- import { OpenAiModelParams } from "../modelParams" ;
15
14
import { DeepSeekModelParams } from "../modelParams" ;
16
15
import { toO1CompatibleChatHistory } from "../utils/o1ClassModels" ;
17
16
18
17
import { DeepSeekModelParamsResolver } from "./deepSeekModelParamsResolver" ;
18
+ import { illegalState } from "../../../utils/throwErrors" ;
19
19
20
20
export class DeepSeekService extends LLMServiceImpl <
21
21
DeepSeekUserModelParams ,
@@ -31,8 +31,6 @@ export class DeepSeekService extends LLMServiceImpl<
31
31
this . generationsLoggerBuilder
32
32
) ;
33
33
protected readonly modelParamsResolver = new DeepSeekModelParamsResolver ( ) ;
34
-
35
- static readonly baseApiUrl = "https://api.deepseek.com/v1" ;
36
34
}
37
35
38
36
export class DeepSeekGeneratedProof extends GeneratedProofImpl <
@@ -44,7 +42,7 @@ export class DeepSeekGeneratedProof extends GeneratedProofImpl<
44
42
constructor (
45
43
rawProof : GeneratedRawContentItem ,
46
44
proofGenerationContext : ProofGenerationContext ,
47
- modelParams : OpenAiModelParams ,
45
+ modelParams : DeepSeekModelParams ,
48
46
llmServiceInternal : DeepSeekServiceInternal ,
49
47
previousProofVersions ?: ProofVersion [ ]
50
48
) {
@@ -64,10 +62,12 @@ class DeepSeekServiceInternal extends LLMServiceInternal<
64
62
DeepSeekGeneratedProof ,
65
63
DeepSeekServiceInternal
66
64
> {
65
+ static readonly baseApiUrl = "https://api.deepseek.com/v1" ;
66
+
67
67
constructGeneratedProof (
68
68
rawProof : GeneratedRawContentItem ,
69
69
proofGenerationContext : ProofGenerationContext ,
70
- modelParams : OpenAiModelParams ,
70
+ modelParams : DeepSeekModelParams ,
71
71
previousProofVersions ?: ProofVersion [ ] | undefined
72
72
) : DeepSeekGeneratedProof {
73
73
return new DeepSeekGeneratedProof (
@@ -81,22 +81,22 @@ class DeepSeekServiceInternal extends LLMServiceInternal<
81
81
82
82
async generateFromChatImpl (
83
83
analyzedChat : AnalyzedChatHistory ,
84
- params : OpenAiModelParams ,
84
+ params : DeepSeekModelParams ,
85
85
choices : number
86
86
) : Promise < GeneratedRawContent > {
87
87
LLMServiceInternal . validateChoices ( choices ) ;
88
88
89
- const openai = new OpenAI ( {
89
+ const openaiCompatibleApi = new OpenAI ( {
90
90
apiKey : params . apiKey ,
91
- baseURL : DeepSeekService . baseApiUrl ,
91
+ baseURL : DeepSeekServiceInternal . baseApiUrl ,
92
92
} ) ;
93
93
const formattedChat = this . formatChatHistory ( analyzedChat . chat , params ) ;
94
94
this . logDebug . event ( "Completion requested" , {
95
95
history : formattedChat ,
96
96
} ) ;
97
97
98
98
try {
99
- const completion = await openai . chat . completions . create ( {
99
+ const completion = await openaiCompatibleApi . chat . completions . create ( {
100
100
messages : formattedChat ,
101
101
model : params . modelName ,
102
102
n : choices ,
@@ -107,7 +107,7 @@ class DeepSeekServiceInternal extends LLMServiceInternal<
107
107
const rawContentItems = completion . choices . map ( ( choice ) => {
108
108
const content = choice . message . content ;
109
109
if ( content === null ) {
110
- throw Error ( "response message content is null" ) ;
110
+ illegalState ( "response message content is null" ) ;
111
111
}
112
112
return content ;
113
113
} ) ;
@@ -131,7 +131,7 @@ class DeepSeekServiceInternal extends LLMServiceInternal<
131
131
rawContentItems : string [ ] ,
132
132
tokensUsage : OpenAI . Completions . CompletionUsage | undefined ,
133
133
analyzedChat : AnalyzedChatHistory ,
134
- params : OpenAiModelParams
134
+ params : DeepSeekModelParams
135
135
) : GeneratedRawContent {
136
136
const promptTokens =
137
137
tokensUsage ?. prompt_tokens ??
@@ -150,8 +150,8 @@ class DeepSeekServiceInternal extends LLMServiceInternal<
150
150
151
151
private formatChatHistory (
152
152
chat : ChatHistory ,
153
- modelParams : OpenAiModelParams
153
+ modelParams : DeepSeekModelParams
154
154
) : ChatHistory {
155
- return toO1CompatibleChatHistory ( chat , modelParams . modelName , "openai " ) ;
155
+ return toO1CompatibleChatHistory ( chat , modelParams . modelName , "deepseek " ) ;
156
156
}
157
157
}
0 commit comments