Skip to content

Commit ffcc61e

Browse files
committed
feat: 添加GLM-4.5模型支持并优化Git代理配置
refactor: 重构Git服务以支持代理设置并改进错误处理 style: 统一文档处理步骤的方法签名格式 perf: 为知识图谱和目录生成添加重试机制 fix: 修复头像上传和设置页面的加载状态显示 docs: 更新架构分析和提示模板以增强AI理解
1 parent 6dab9cd commit ffcc61e

17 files changed

+1051
-829
lines changed

src/KoalaWiki/Git/GitService.cs

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.ComponentModel;
22
using KoalaWiki.Core;
3+
using KoalaWiki.Options;
34
using LibGit2Sharp;
45

56
namespace KoalaWiki.Git;
@@ -43,18 +44,26 @@ public static (List<Commit> commits, string Sha) PullRepository(
4344
string userName = "",
4445
string password = "")
4546
{
47+
var fetchOptions = new FetchOptions()
48+
{
49+
CertificateCheck = (_, _, _) => true,
50+
CredentialsProvider = (_url, _user, _cred) =>
51+
new UsernamePasswordCredentials
52+
{
53+
Username = userName,
54+
Password = password
55+
}
56+
};
57+
58+
// 设置代理
59+
if (!string.IsNullOrEmpty(DocumentOptions.Proxy))
60+
{
61+
fetchOptions.ProxyOptions.Url = DocumentOptions.Proxy;
62+
}
63+
4664
var pullOptions = new PullOptions
4765
{
48-
FetchOptions = new FetchOptions()
49-
{
50-
CertificateCheck = (_, _, _) => true,
51-
CredentialsProvider = (_url, _user, _cred) =>
52-
new UsernamePasswordCredentials
53-
{
54-
Username = userName,
55-
Password = password
56-
}
57-
}
66+
FetchOptions = fetchOptions
5867
};
5968

6069
// 先克隆
@@ -107,13 +116,20 @@ public static GitRepositoryInfo CloneRepository(
107116
{
108117
var (localPath, organization) = GetRepositoryPath(repositoryUrl);
109118

110-
var cloneOptions = new CloneOptions
119+
var fetchOptions = new FetchOptions
120+
{
121+
CertificateCheck = (_, _, _) => true,
122+
Depth = 0,
123+
};
124+
125+
// 设置代理
126+
if (!string.IsNullOrEmpty(DocumentOptions.Proxy))
127+
{
128+
fetchOptions.ProxyOptions.Url = DocumentOptions.Proxy;
129+
}
130+
131+
var cloneOptions = new CloneOptions(fetchOptions)
111132
{
112-
FetchOptions =
113-
{
114-
CertificateCheck = (_, _, _) => true,
115-
Depth = 0,
116-
},
117133
BranchName = branch
118134
};
119135

@@ -149,24 +165,31 @@ public static GitRepositoryInfo CloneRepository(
149165
// 删除目录以后在尝试一次
150166
Directory.Delete(localPath, true);
151167

152-
cloneOptions = new CloneOptions
168+
var retryFetchOptions = new FetchOptions
153169
{
154-
BranchName = branch,
155-
FetchOptions =
170+
Depth = 0,
171+
CertificateCheck = (_, _, _) => true,
172+
CredentialsProvider = (_url, _user, _cred) =>
156173
{
157-
Depth = 0,
158-
CertificateCheck = (_, _, _) => true,
159-
CredentialsProvider = (_url, _user, _cred) =>
174+
return new UsernamePasswordCredentials
160175
{
161-
return new UsernamePasswordCredentials
162-
{
163-
Username = userName, // 对于Token认证,Username可以随便填
164-
Password = password
165-
};
166-
}
176+
Username = userName, // 对于Token认证,Username可以随便填
177+
Password = password
178+
};
167179
}
168180
};
169181

182+
// 设置代理
183+
if (!string.IsNullOrEmpty(DocumentOptions.Proxy))
184+
{
185+
retryFetchOptions.ProxyOptions.Url = DocumentOptions.Proxy;
186+
}
187+
188+
cloneOptions = new CloneOptions(retryFetchOptions)
189+
{
190+
BranchName = branch,
191+
};
192+
170193
Repository.Clone(repositoryUrl, localPath, cloneOptions);
171194
// 获取当前仓库的git分支
172195
using var repo = new Repository(localPath);
@@ -195,24 +218,31 @@ public static GitRepositoryInfo CloneRepository(
195218
{
196219
var info = Directory.CreateDirectory(localPath);
197220

198-
cloneOptions = new CloneOptions
221+
var authFetchOptions = new FetchOptions
199222
{
200-
BranchName = branch,
201-
FetchOptions =
223+
Depth = 0,
224+
CertificateCheck = (_, _, _) => true,
225+
CredentialsProvider = (_url, _user, _cred) =>
202226
{
203-
Depth = 0,
204-
CertificateCheck = (_, _, _) => true,
205-
CredentialsProvider = (_url, _user, _cred) =>
227+
return new UsernamePasswordCredentials
206228
{
207-
return new UsernamePasswordCredentials
208-
{
209-
Username = userName, // 对于Token认证,Username可以随便填
210-
Password = password
211-
};
212-
}
229+
Username = userName, // 对于Token认证,Username可以随便填
230+
Password = password
231+
};
213232
}
214233
};
215234

235+
// 设置代理
236+
if (!string.IsNullOrEmpty(DocumentOptions.Proxy))
237+
{
238+
authFetchOptions.ProxyOptions.Url = DocumentOptions.Proxy;
239+
}
240+
241+
cloneOptions = new CloneOptions(authFetchOptions)
242+
{
243+
BranchName = branch,
244+
};
245+
216246
Repository.Clone(repositoryUrl, localPath, cloneOptions);
217247
}
218248

src/KoalaWiki/Infrastructure/DocumentsHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ public static async Task<string> ReadMeFile(string path)
136136
"gemini-2.5-pro" => 32768,
137137
"gemini-2.5-flash" => 32768,
138138
"Qwen3-32B" => 32768,
139+
"glm-4.5" => 32768,
140+
"glm-4.5v" => 32768,
139141
"deepseek-r1:32b-qwen-distill-fp16" => 32768,
140142
_ => null
141143
};

src/KoalaWiki/KoalaWarehouse/GenerateThinkCatalogue/GenerateThinkCatalogueService.Prompt.cs

Lines changed: 36 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public static async Task<string> GenerateThinkCataloguePromptAsync(ClassifyType?
2121
var enhancementLevel = Math.Min(attemptNumber, 3);
2222
var enhancement = enhancementLevel switch
2323
{
24-
0 => "\n\nPlease provide a comprehensive analysis in JSON format within <documentation_structure> tags.",
24+
0 => "\n\nGenerate documentation catalog in the specified hierarchical JSON format within <documentation_structure> tags.",
2525
1 =>
26-
"\n\nIMPORTANT: You must respond with valid JSON wrapped in <documentation_structure> tags. Ensure the JSON is properly formatted and complete.",
26+
"\n\nIMPORTANT: You must respond with valid JSON using the items/children structure within <documentation_structure> tags. Follow the exact format specified.",
2727
2 =>
28-
"\n\nCRITICAL: Previous attempts failed. Please provide ONLY valid JSON within <documentation_structure> tags. Double-check JSON syntax before responding.",
28+
"\n\nCRITICAL: Previous attempts failed. Generate ONLY valid JSON within <documentation_structure> tags. Use the hierarchical items structure with title, name, and children fields.",
2929
_ =>
30-
"\n\nFINAL ATTEMPT: Respond with MINIMAL but VALID JSON in <documentation_structure> tags. Focus on basic structure: {\"categories\":[{\"name\":\"...\",\"description\":\"...\"}],\"architecture_overview\":\"...\"}. Ensure valid JSON syntax."
30+
"\n\nFINAL ATTEMPT: Generate minimal but valid JSON structure. Must include: {\"items\":[{\"title\":\"getting-started\",\"name\":\"入门指南\",\"children\":[...]},{\"title\":\"deep-dive\",\"name\":\"深入解剖\",\"children\":[...]}]}."
3131
};
3232

3333
return basePrompt + enhancement;
@@ -40,109 +40,85 @@ private static string GetProjectTypeDescription(ClassifyType? classifyType)
4040
{
4141
return """
4242
## Application System
43-
You are generating a documentation catalogue for an enterprise application system. Focus on:
44-
- **Business Domain**: Core business logic, domain models, and value propositions
45-
- **Architecture**: System design patterns, data flow, and component interactions
46-
- **User Experience**: Interface design, user journeys, and accessibility considerations
47-
- **Deployment**: Production deployment strategies, scaling considerations, and operational monitoring
48-
- **Integration**: External service dependencies, API contracts, and data exchange patterns
49-
Structure the documentation to cover all key aspects of the application system.
43+
Focus on application-specific documentation needs:
44+
- **Getting Started**: Business purpose, quick setup, basic usage patterns
45+
- **Deep Dive**: System architecture, core features, technical implementation, integration points
46+
Emphasize user workflows, business logic, and deployment considerations.
5047
""";
5148
}
5249

5350
if (classifyType == ClassifyType.Frameworks)
5451
{
5552
return """
5653
## Development Framework
57-
You are generating a documentation catalogue for a development framework. Focus on:
58-
- **Core Architecture**: Framework design patterns, plugin systems, and extensibility mechanisms
59-
- **Developer Experience**: API consistency, documentation quality, and learning curve
60-
- **Ecosystem**: Compatible tools, community contributions, and third-party integrations
61-
- **Performance**: Runtime efficiency, memory usage, and optimization strategies
62-
- **Standards**: Code conventions, best practices, and architectural guidelines
63-
Structure the documentation to showcase framework capabilities and usage patterns.
54+
Focus on framework-specific documentation needs:
55+
- **Getting Started**: Framework purpose, quick setup, basic concepts, simple examples
56+
- **Deep Dive**: Architecture patterns, extensibility mechanisms, API design, performance optimization
57+
Emphasize developer experience, plugin systems, and integration workflows.
6458
""";
6559
}
6660

6761
if (classifyType == ClassifyType.Libraries)
6862
{
6963
return """
7064
## Reusable Code Library
71-
You are generating a documentation catalogue for a reusable code library. Focus on:
72-
- **API Design**: Interface consistency, method signatures, and parameter patterns
73-
- **Integration Patterns**: Installation methods, dependency management, and compatibility
74-
- **Usage Examples**: Common use cases, code samples, and implementation patterns
75-
- **Performance**: Efficiency benchmarks, resource usage, and optimization techniques
76-
- **Maintenance**: Version compatibility, breaking changes, and migration guides
77-
Structure the documentation to facilitate library adoption and integration.
65+
Focus on library-specific documentation needs:
66+
- **Getting Started**: Library purpose, installation, basic usage, common examples
67+
- **Deep Dive**: API design, advanced features, performance characteristics, customization options
68+
Emphasize practical usage patterns, integration strategies, and version compatibility.
7869
""";
7970
}
8071

8172
if (classifyType == ClassifyType.DevelopmentTools)
8273
{
8374
return """
8475
## Development Tool
85-
You are generating a documentation catalogue for a development tool. Focus on:
86-
- **Productivity Features**: Core capabilities, automation features, and workflow optimization
87-
- **Configuration**: Setup procedures, customization options, and environment integration
88-
- **Integration**: IDE support, build system compatibility, and toolchain integration
89-
- **User Interface**: Command syntax, GUI elements, and user interaction patterns
90-
- **Performance**: Execution speed, resource consumption, and scalability limits
91-
Structure the documentation to guide users through setup and effective usage.
76+
Focus on tool-specific documentation needs:
77+
- **Getting Started**: Tool purpose, installation, basic configuration, first workflow
78+
- **Deep Dive**: Advanced features, customization options, integration patterns, optimization techniques
79+
Emphasize practical workflows, automation capabilities, and IDE integration.
9280
""";
9381
}
9482

9583
if (classifyType == ClassifyType.CLITools)
9684
{
9785
return """
9886
## Command-Line Interface Tool
99-
You are generating a documentation catalogue for a CLI tool. Focus on:
100-
- **Command Structure**: Command hierarchy, argument patterns, and option consistency
101-
- **Usability**: Help systems, error messages, and user guidance features
102-
- **Automation**: Scripting capabilities, batch operations, and pipeline integration
103-
- **Configuration**: Config files, environment variables, and persistent settings
104-
- **Performance**: Execution efficiency, startup time, and resource optimization
105-
Structure the documentation to enable efficient command-line usage and automation.
87+
Focus on CLI-specific documentation needs:
88+
- **Getting Started**: Tool purpose, installation, basic commands, common workflows
89+
- **Deep Dive**: Command reference, advanced usage, scripting integration, configuration options
90+
Emphasize command syntax, automation capabilities, and pipeline integration.
10691
""";
10792
}
10893

10994
if (classifyType == ClassifyType.DevOpsConfiguration)
11095
{
11196
return """
11297
## DevOps & Infrastructure Configuration
113-
You are generating a documentation catalogue for a DevOps configuration project. Focus on:
114-
- **Infrastructure Patterns**: Deployment architectures, scaling strategies, and resource management
115-
- **Automation**: CI/CD pipelines, deployment scripts, and infrastructure as code
116-
- **Monitoring**: Logging strategies, metrics collection, and alerting configurations
117-
- **Security**: Access controls, secret management, and compliance requirements
118-
- **Operations**: Maintenance procedures, backup strategies, and disaster recovery
119-
Structure the documentation to support operational excellence and reliable deployments.
98+
Focus on DevOps-specific documentation needs:
99+
- **Getting Started**: Infrastructure purpose, basic setup, deployment workflow, monitoring basics
100+
- **Deep Dive**: Advanced automation, security configuration, scaling strategies, operational procedures
101+
Emphasize deployment patterns, infrastructure as code, and operational excellence.
120102
""";
121103
}
122104

123105
if (classifyType == ClassifyType.Documentation)
124106
{
125107
return """
126108
## Documentation & Testing Project
127-
You are generating a documentation catalogue for a documentation or testing project. Focus on:
128-
- **Content Structure**: Information architecture, navigation patterns, and content organization
129-
- **Quality Assurance**: Testing methodologies, coverage strategies, and validation processes
130-
- **Maintenance**: Content lifecycle, update procedures, and version management
131-
- **Accessibility**: Documentation formats, search capabilities, and user experience
132-
- **Standards**: Style guides, contribution guidelines, and quality metrics
133-
Structure the documentation to ensure comprehensive coverage and usability.
109+
Focus on documentation-specific needs:
110+
- **Getting Started**: Project purpose, content overview, contribution basics, style guidelines
111+
- **Deep Dive**: Content architecture, testing methodologies, maintenance procedures, quality standards
112+
Emphasize content organization, quality assurance, and contributor workflows.
134113
""";
135114
}
136115

137116
return """
138117
## General Project Analysis
139-
You are generating a documentation catalogue for a general software project. Focus on:
140-
- **Architecture**: System design, component relationships, and technical decisions
141-
- **Implementation**: Code quality, design patterns, and development practices
142-
- **Features**: Core functionality, user capabilities, and system behaviors
143-
- **Setup**: Installation procedures, configuration requirements, and environment setup
144-
- **Usage**: Common workflows, integration patterns, and practical applications
145-
Structure the documentation to provide comprehensive coverage of all project aspects.
118+
Focus on general project documentation needs:
119+
- **Getting Started**: Project purpose, setup instructions, basic concepts, common usage
120+
- **Deep Dive**: System architecture, core features, technical implementation, advanced customization
121+
Provide comprehensive coverage balancing accessibility with technical depth.
146122
""";
147123
}
148124
}

src/KoalaWiki/KoalaWarehouse/GenerateThinkCatalogue/GenerateThinkCatalogueService.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ Ensure all components are properly categorized.
149149
MaxTokens = DocumentsHelper.GetMaxTokens(OpenAIOptions.AnalysisModel)
150150
};
151151

152+
int retry = 1;
153+
retry:
154+
152155
// 流式获取响应
153156
await foreach (var item in chat.GetStreamingChatMessageContentsAsync(history, settings, analysisModel))
154157
{
@@ -158,9 +161,21 @@ Ensure all components are properly categorized.
158161
}
159162
}
160163

164+
// str先清空<think>标签
165+
var thinkTagRegex = new Regex(@"<think>.*?</think>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
166+
var thinkContent = thinkTagRegex.Match(str.ToString());
167+
str = new StringBuilder(thinkTagRegex.Replace(str.ToString(), string.Empty).Trim());
168+
169+
161170
if (str.Length == 0)
162171
{
163-
throw new InvalidOperationException("AI 返回了空响应");
172+
history.AddAssistantMessage(thinkContent.Value);
173+
retry++;
174+
if (retry > 3)
175+
{
176+
throw new Exception("AI生成目录的时候重复多次响应空内容");
177+
}
178+
goto retry;
164179
}
165180

166181
// 质量增强逻辑

0 commit comments

Comments
 (0)