@@ -12,14 +12,27 @@ import { LocalizationManager } from "../../utils/LocalizationManager";
12
12
import { generateWithRetry , getSystemPrompt } from "../utils/generateHelper" ;
13
13
import { getWeeklyReportPrompt } from "../../prompt/weeklyReport" ;
14
14
15
+ /**
16
+ * Ollama AI服务提供者实现类
17
+ * 提供对本地部署的Ollama服务的访问能力
18
+ */
15
19
export class OllamaProvider implements AIProvider {
20
+ /** Ollama客户端实例 */
16
21
private ollama : Ollama ;
22
+
23
+ /** 提供者标识信息 */
17
24
private readonly provider = {
18
25
id : "ollama" as AIProviders ,
19
26
name : "Ollama" ,
20
27
} as const ;
28
+
29
+ /** 配置管理器实例 */
21
30
private configManager : ConfigurationManager ;
22
31
32
+ /**
33
+ * 创建Ollama提供者实例
34
+ * 初始化Ollama客户端并配置基础URL
35
+ */
23
36
constructor ( ) {
24
37
this . configManager = ConfigurationManager . getInstance ( ) ;
25
38
const baseUrl = this . getBaseUrl ( ) ;
@@ -28,13 +41,23 @@ export class OllamaProvider implements AIProvider {
28
41
} ) ;
29
42
}
30
43
44
+ /**
45
+ * 获取Ollama服务的基础URL
46
+ * @returns 配置的URL或默认的localhost URL
47
+ * @private
48
+ */
31
49
private getBaseUrl ( ) : string {
32
50
return (
33
51
this . configManager . getConfig ( "PROVIDERS_OLLAMA_BASEURL" ) ||
34
52
"http://localhost:11434"
35
53
) ;
36
54
}
37
55
56
+ /**
57
+ * 刷新可用的Ollama模型列表
58
+ * @returns 返回模型名称的数组
59
+ * @throws 如果获取失败则返回空数组并显示错误通知
60
+ */
38
61
async refreshModels ( ) : Promise < string [ ] > {
39
62
try {
40
63
const response = await this . ollama . list ( ) ;
@@ -53,6 +76,12 @@ export class OllamaProvider implements AIProvider {
53
76
}
54
77
}
55
78
79
+ /**
80
+ * 生成AI响应
81
+ * @param params - AI请求参数
82
+ * @returns 包含生成内容和使用统计的响应
83
+ * @throws 如果生成失败会通过重试机制处理
84
+ */
56
85
async generateResponse ( params : AIRequestParams ) : Promise < AIResponse > {
57
86
return generateWithRetry (
58
87
params ,
@@ -97,6 +126,12 @@ export class OllamaProvider implements AIProvider {
97
126
) ;
98
127
}
99
128
129
+ /**
130
+ * 生成周报内容
131
+ * @param commits - 提交记录数组
132
+ * @param model - 可选的指定模型
133
+ * @returns 生成的周报内容和统计信息
134
+ */
100
135
async generateWeeklyReport (
101
136
commits : string [ ] ,
102
137
model ?: AIModel
@@ -135,6 +170,10 @@ export class OllamaProvider implements AIProvider {
135
170
} ;
136
171
}
137
172
173
+ /**
174
+ * 检查Ollama服务是否可用
175
+ * @returns 如果能成功获取模型列表则返回true
176
+ */
138
177
async isAvailable ( ) : Promise < boolean > {
139
178
try {
140
179
await this . ollama . list ( ) ;
@@ -144,6 +183,11 @@ export class OllamaProvider implements AIProvider {
144
183
}
145
184
}
146
185
186
+ /**
187
+ * 获取支持的AI模型列表
188
+ * @returns 返回支持的模型配置数组
189
+ * @throws 如果获取失败则显示错误通知
190
+ */
147
191
async getModels ( ) : Promise < AIModel [ ] > {
148
192
try {
149
193
const response = await this . ollama . list ( ) ;
@@ -169,12 +213,22 @@ export class OllamaProvider implements AIProvider {
169
213
}
170
214
}
171
215
216
+ /**
217
+ * 获取提供者显示名称
218
+ */
172
219
getName ( ) : string {
173
220
return this . provider . name ;
174
221
}
175
222
223
+ /**
224
+ * 获取提供者ID
225
+ */
176
226
getId ( ) : string {
177
227
return this . provider . id ;
178
228
}
229
+
230
+ /**
231
+ * 资源释放
232
+ */
179
233
dispose ( ) { }
180
234
}
0 commit comments