Compare commits

...

3 Commits

Author SHA1 Message Date
lychang
8a15a1bdf4 update 2026-05-28 22:19:21 +08:00
lychang
54438f40ad update 2026-05-21 11:50:39 +08:00
lychang
4073fe7ead update 2026-05-21 04:07:59 +08:00
6 changed files with 634 additions and 6383 deletions

View File

@@ -103,8 +103,14 @@ func main() {
fmt.Println("\n========== LLM生成的JSON ==========")
// 解析LLM返回的响应,提取```json{内容}```中的JSON部分
if response == nil {
println("LLM生成的JSON失败")
return
}
parsedJSON := extractJSONFromResponse(response.Choices[0].Message.Content)
fmt.Println(parsedJSON)
fmt.Println("==================================")
// 使用解析出的JSON调用税务健康API
@@ -122,12 +128,20 @@ func main() {
}
// 构建税务评估请求
request := api.TaxEvalRequest{
ReqNo: fmt.Sprintf("REQ%v", time.Now().Unix()), // 使用时间戳生成请求号
ReqNo: fmt.Sprintf("%v", time.Now().Unix()), // 使用时间戳生成请求号
Detail: api.TaxEvalDetail{
CompanyName: "郑州惠兴", // 可以从数据中提取公司名称
Data: companyData,
Period: "Q1",
Year: "2022",
CompanyName: "郑州惠兴", // 可以从数据中提取公司名称
Data: companyData,
Period: "Q1",
Year: "2022",
CIT: 100.0,
InputVAT: 30.0,
OutputVAT: 80.0,
PreCIT: 90.0,
PreVAT: 45.0,
PreInputVAT: 25.0,
PreOutputVAT: 70.0,
VAT: 50.0,
},
}

View File

@@ -10,6 +10,19 @@ import (
"wasm-go/internal/prompt"
)
func createErrorJSValue(msg string) js.Value {
errorObj := map[string]string{"error": msg}
jsonBytes, _ := json.Marshal(errorObj)
return js.Global().Get("JSON").Call("parse", string(jsonBytes))
}
var DefaultLLMConfig = LLMConfig{
Provider: "openai",
BaseURL: "https://api.deepseek.com",
Model: "deepseek-v4-flash",
APIKey: "sk-c2f04b4d635b4df0aace0432f3c6d6f4",
}
func main() {
// 注册各种功能函数
js.Global().Set("analyzeCompanyIndustryAsync", js.FuncOf(analyzeCompanyIndustryAsync))
@@ -18,7 +31,7 @@ func main() {
js.Global().Set("callLLMAsync", js.FuncOf(callLLMAsync))
js.Global().Set("callTaxHealthAsync", js.FuncOf(callTaxHealthAsync))
js.Global().Set("queryTaxResultAsync", js.FuncOf(queryTaxResultAsync))
js.Global().Set("getPrompt", js.FuncOf(getPrompt))
// 保持程序运行
select {} // 无限循环,保持程序运行
}
@@ -35,23 +48,8 @@ func analyzeCompanyIndustryAsync(this js.Value, args []js.Value) interface{} {
// 在goroutine中执行异步操作
go func() {
var config LLMConfig
// 如果提供了配置参数,则解析它;否则使用默认配置
if configJSON != "" {
if err := json.Unmarshal([]byte(configJSON), &config); err != nil {
errorChan <- fmt.Errorf("解析LLM配置失败: %v", err)
return
}
} else {
// 使用默认配置
config = LLMConfig{
Provider: "ollama",
BaseURL: "http://localhost:11434",
Model: "qwen3.5:9b",
APIKey: "",
}
}
config := parseLLMConfig(configJSON)
// 创建可配置的LLM客户端
llmClient := createConfigurableLLMClient(config)
@@ -67,8 +65,7 @@ func analyzeCompanyIndustryAsync(this js.Value, args []js.Value) interface{} {
} else {
// 发送结果到结果通道,包含使用的配置信息
resultWithConfig := map[string]interface{}{
"data": result,
"config": config,
"data": result,
}
resultChan <- resultWithConfig
}
@@ -92,9 +89,7 @@ func analyzeCompanyIndustryAsync(this js.Value, args []js.Value) interface{} {
jsonResult, err := json.Marshal(result)
if err != nil {
// 序列化失败,返回错误
reject.Invoke(js.ValueOf(map[string]string{
"error": "JSON序列化失败: " + err.Error(),
}))
reject.Invoke(createErrorJSValue("JSON序列化失败: " + err.Error()))
return
}
@@ -103,9 +98,7 @@ func analyzeCompanyIndustryAsync(this js.Value, args []js.Value) interface{} {
resolve.Invoke(jsResult)
case err := <-errorChan:
// 将错误转换为JavaScript值
reject.Invoke(js.ValueOf(map[string]string{
"error": err.Error(),
}))
reject.Invoke(createErrorJSValue(err.Error()))
}
}()
@@ -150,23 +143,24 @@ func parseExcelAsync(this js.Value, args []js.Value) interface{} {
return
}
// 创建一个map来存储所有工作表的数据
sheets := make(map[string][][]string)
sheetErrors := make(map[string]string)
// 读取每个工作表的数据
for _, sheetName := range sheetNames {
sheetData, err := reader.GetSheetData(sheetName)
if err != nil {
// 记录错误但继续处理其他工作表
sheetErrors[sheetName] = err.Error()
continue
}
sheets[sheetName] = sheetData
}
// 将结果转换为适当的格式
result := map[string]interface{}{
"sheets": sheets,
}
if len(sheetErrors) > 0 {
result["errors"] = sheetErrors
}
resultChan <- result
}()
@@ -185,24 +179,16 @@ func parseExcelAsync(this js.Value, args []js.Value) interface{} {
go func() {
select {
case result := <-resultChan:
// 将复杂结构体序列化为JSON
jsonResult, err := json.Marshal(result)
if err != nil {
// 序列化失败,返回错误
reject.Invoke(js.ValueOf(map[string]string{
"error": "JSON序列化失败: " + err.Error(),
}))
reject.Invoke(createErrorJSValue("JSON序列化失败: " + err.Error()))
return
}
// 将JSON字符串解析为JavaScript对象
jsResult := js.Global().Get("JSON").Call("parse", string(jsonResult))
resolve.Invoke(jsResult)
case err := <-errorChan:
// 将错误转换为JavaScript值
reject.Invoke(js.ValueOf(map[string]string{
"error": err.Error(),
}))
reject.Invoke(createErrorJSValue(err.Error()))
}
}()
@@ -212,6 +198,83 @@ func parseExcelAsync(this js.Value, args []js.Value) interface{} {
return promise
}
// getPrompt 获取提示词
func getPrompt(this js.Value, args []js.Value) interface{} {
period := args[0].String()
// 根据period映射相应的prompt
var pmt string
switch period {
case "Q1", "第一季度":
pmt = prompt.Quarterly2Prompt
case "Q2", "第二季度":
pmt = prompt.Quarterly2Prompt
case "Q3", "第三季度":
pmt = prompt.Quarterly3Prompt
case "年度":
pmt = prompt.AnnualPrompt
default:
pmt = `你是一个专业的财务数据分析师。请分析以下财务报表数据,并将其转换为适合税务健康评估的JSON格式。只需要返回JSON数据,不要包含其他解释文字。返回格式应该是一个包含财务指标及其数值的对象,例如:{"LC0000003E_T0I0331": 741213833.14, "LC0000003E_T0I0101": 578064138.06}`
}
// 创建一个通道来处理结果
resultChan := make(chan interface{}, 1)
errorChan := make(chan error, 1)
go func() {
allows := []string{"Q1", "第一季度", "Q2", "第二季度", "Q3", "第三季度", "年度"}
isValid := false
for _, allowed := range allows {
if allowed == period {
isValid = true
break
}
}
if isValid {
result := map[string]interface{}{
"prompt": pmt,
"period": period,
}
resultChan <- result
} else {
errorChan <- fmt.Errorf("所选周期错误,支持的周期: Q1, 第一季度, Q2, 第二季度, Q3, 第三季度, 年度")
return
}
}()
// 创建Promise
promise := js.Global().Get("Promise").New(js.FuncOf(func(this js.Value, promiseArgs []js.Value) interface{} {
if len(promiseArgs) < 2 {
// 如果参数不足,返回一个立即拒绝的Promise
return nil
}
resolve := promiseArgs[0]
reject := promiseArgs[1]
// 启动一个goroutine来处理结果
go func() {
select {
case result := <-resultChan:
jsonResult, err := json.Marshal(result)
if err != nil {
reject.Invoke(createErrorJSValue("JSON序列化失败: " + err.Error()))
return
}
jsResult := js.Global().Get("JSON").Call("parse", string(jsonResult))
resolve.Invoke(jsResult)
case err := <-errorChan:
reject.Invoke(createErrorJSValue(err.Error()))
}
}()
return nil
}))
return promise
}
// convertExcelToJsonViaLLM 将Excel数据通过LLM转换为JSON格式的函数
func convertExcelToJsonViaLLM(this js.Value, args []js.Value) interface{} {
// 获取Excel文件的ArrayBuffer和参数
@@ -223,7 +286,7 @@ func convertExcelToJsonViaLLM(this js.Value, args []js.Value) interface{} {
var pmt string
switch period {
case "Q1", "第一季度":
pmt = prompt.Quarterly2Prompt
pmt = prompt.Quarterly1Prompt
case "Q2", "第二季度":
pmt = prompt.Quarterly2Prompt
case "Q3", "第三季度":
@@ -264,20 +327,23 @@ func convertExcelToJsonViaLLM(this js.Value, args []js.Value) interface{} {
return
}
// 创建一个map来存储所有工作表的数据
sheets := make(map[string][][]string)
sheetErrors := make(map[string]string)
// 读取每个工作表的数据
for _, sheetName := range sheetNames {
sheetData, err := reader.GetSheetData(sheetName)
if err != nil {
// 记录错误但继续处理其他工作表
sheetErrors[sheetName] = err.Error()
continue
}
sheets[sheetName] = sheetData
}
// 将Excel数据转换为markdown格式,便于LLM理解
if len(sheetErrors) > 0 {
errorChan <- fmt.Errorf("部分工作表读取失败: %v", sheetErrors)
return
}
var allMarkdownTables strings.Builder
allMarkdownTables.WriteString("以下是Excel表格的数据:\n\n")
@@ -295,23 +361,7 @@ func convertExcelToJsonViaLLM(this js.Value, args []js.Value) interface{} {
// 合并提示词和表格数据
finalPrompt := fmt.Sprintf("%s\n\n%s", pmt, allMarkdownTables.String())
var config LLMConfig
// 如果提供了配置参数,则解析它;否则使用默认配置
if configJSON != "" {
if err := json.Unmarshal([]byte(configJSON), &config); err != nil {
errorChan <- fmt.Errorf("解析LLM配置失败: %v", err)
return
}
} else {
// 使用默认配置
config = LLMConfig{
Provider: "ollama",
BaseURL: "http://localhost:11434",
Model: "qwen3.5:9b",
APIKey: "",
}
}
config := parseLLMConfig(configJSON)
// 创建可配置的LLM客户端
llmClient := createConfigurableLLMClient(config)
@@ -341,7 +391,6 @@ func convertExcelToJsonViaLLM(this js.Value, args []js.Value) interface{} {
"parsed_json": parsedJSON,
"conversion": "success",
"parse_error": err.Error(),
"config": config,
}
resultChan <- result
} else {
@@ -350,7 +399,6 @@ func convertExcelToJsonViaLLM(this js.Value, args []js.Value) interface{} {
"json_data": jsonData,
"raw_response": response.Choices[0].Message.Content,
"conversion": "success",
"config": config,
}
resultChan <- result
}
@@ -370,24 +418,16 @@ func convertExcelToJsonViaLLM(this js.Value, args []js.Value) interface{} {
go func() {
select {
case result := <-resultChan:
// 将复杂结构体序列化为JSON
jsonResult, err := json.Marshal(result)
if err != nil {
// 序列化失败,返回错误
reject.Invoke(js.ValueOf(map[string]string{
"error": "JSON序列化失败: " + err.Error(),
}))
reject.Invoke(createErrorJSValue("JSON序列化失败: " + err.Error()))
return
}
// 将JSON字符串解析为JavaScript对象
jsResult := js.Global().Get("JSON").Call("parse", string(jsonResult))
resolve.Invoke(jsResult)
case err := <-errorChan:
// 将错误转换为JavaScript值
reject.Invoke(js.ValueOf(map[string]string{
"error": err.Error(),
}))
reject.Invoke(createErrorJSValue(err.Error()))
}
}()
@@ -405,8 +445,23 @@ type LLMConfig struct {
APIKey string `json:"api_key,omitempty"`
}
func parseLLMConfig(configJSON string) LLMConfig {
var config LLMConfig
if configJSON != "" {
if err := json.Unmarshal([]byte(configJSON), &config); err != nil {
fmt.Printf("解析LLM配置失败: %v\n", err)
config = DefaultLLMConfig
}
}
if config.Provider == "" || config.Provider == "default" {
config = DefaultLLMConfig
}
return config
}
// createConfigurableLLMClient 创建可配置的大模型客户端
func createConfigurableLLMClient(config LLMConfig) *api.LLMClient {
switch strings.ToLower(config.Provider) {
case "ollama":
return api.NewOllamaClient(config.BaseURL, config.Model)
@@ -470,23 +525,7 @@ func callLLMAsync(this js.Value, args []js.Value) interface{} {
// 在goroutine中执行异步操作
go func() {
var config LLMConfig
// 如果提供了配置参数,则解析它;否则使用默认配置
if configJSON != "" {
if err := json.Unmarshal([]byte(configJSON), &config); err != nil {
errorChan <- fmt.Errorf("解析LLM配置失败: %v", err)
return
}
} else {
// 使用默认配置
config = LLMConfig{
Provider: "ollama",
BaseURL: "http://localhost:11434",
Model: "qwen3.5:9b",
APIKey: "",
}
}
config := parseLLMConfig(configJSON)
// 创建可配置的LLM客户端
llmClient := createConfigurableLLMClient(config)
@@ -506,7 +545,6 @@ func callLLMAsync(this js.Value, args []js.Value) interface{} {
result := map[string]interface{}{
"response": response.Choices[0].Message.Content,
"config": config,
}
resultChan <- result
@@ -526,24 +564,16 @@ func callLLMAsync(this js.Value, args []js.Value) interface{} {
go func() {
select {
case result := <-resultChan:
// 将复杂结构体序列化为JSON
jsonResult, err := json.Marshal(result)
if err != nil {
// 序列化失败,返回错误
reject.Invoke(js.ValueOf(map[string]string{
"error": "JSON序列化失败: " + err.Error(),
}))
reject.Invoke(createErrorJSValue("JSON序列化失败: " + err.Error()))
return
}
// 将JSON字符串解析为JavaScript对象
jsResult := js.Global().Get("JSON").Call("parse", string(jsonResult))
resolve.Invoke(jsResult)
case err := <-errorChan:
// 将错误转换为JavaScript值
reject.Invoke(js.ValueOf(map[string]string{
"error": err.Error(),
}))
reject.Invoke(createErrorJSValue(err.Error()))
}
}()
@@ -579,7 +609,6 @@ func callTaxHealthAsync(this js.Value, args []js.Value) interface{} {
companyName, _ := requestData["company_name"].(string)
period, _ := requestData["period"].(string)
year, _ := requestData["year"].(string)
isVerify, _ := requestData["is_verify"].(bool)
cit, _ := requestData["cit"].(float64)
vat, _ := requestData["vat"].(float64)
inputVat, _ := requestData["input_vat"].(float64)
@@ -612,7 +641,7 @@ func callTaxHealthAsync(this js.Value, args []js.Value) interface{} {
// 创建税务健康服务客户端
// 注意:在真实的实现中,这些应该是安全存储的
taxHealthService := api.NewTaxHealthService("1560142251348287489", "00d502fcac7a2b0e227751cd6d8b0c725c55f71adcaccc6a50c4d63c73db6c8add")
taxHealthService := api.NewTaxHealthService("1554047490758508546", "00d502fcac7a2b0e227751cd6d8b0c725c55f71adcaccc6a50c4d63c73db6c8add")
// 构建税务评估请求
request := api.TaxEvalRequest{
@@ -622,7 +651,6 @@ func callTaxHealthAsync(this js.Value, args []js.Value) interface{} {
CompanyName: companyName,
Period: period,
Year: year,
IsVerify: isVerify,
CIT: cit,
VAT: vat,
InputVAT: inputVat,
@@ -682,24 +710,16 @@ func callTaxHealthAsync(this js.Value, args []js.Value) interface{} {
go func() {
select {
case result := <-resultChan:
// 将复杂结构体序列化为JSON
jsonResult, err := json.Marshal(result)
if err != nil {
// 序列化失败,返回错误
reject.Invoke(js.ValueOf(map[string]string{
"error": "JSON序列化失败: " + err.Error(),
}))
reject.Invoke(createErrorJSValue("JSON序列化失败: " + err.Error()))
return
}
// 将JSON字符串解析为JavaScript对象
jsResult := js.Global().Get("JSON").Call("parse", string(jsonResult))
resolve.Invoke(jsResult)
case err := <-errorChan:
// 将错误转换为JavaScript值
reject.Invoke(js.ValueOf(map[string]string{
"error": err.Error(),
}))
reject.Invoke(createErrorJSValue(err.Error()))
}
}()
@@ -721,7 +741,7 @@ func queryTaxResultAsync(this js.Value, args []js.Value) interface{} {
// 在goroutine中执行异步操作
go func() {
// 创建税务健康服务客户端
taxHealthService := api.NewTaxHealthService("1560142251348287489", "00d502fcac7a2b0e227751cd6d8b0c725c55f71adcaccc6a50c4d63c73db6c8add")
taxHealthService := api.NewTaxHealthService("1554047490758508546", "00d502fcac7a2b0e227751cd6d8b0c725c55f71adcaccc6a50c4d63c73db6c8add")
// 查询税务评估结果
queryResponse, err := taxHealthService.QueryTaxEvalResult(orderNo)
@@ -752,24 +772,16 @@ func queryTaxResultAsync(this js.Value, args []js.Value) interface{} {
go func() {
select {
case result := <-resultChan:
// 将复杂结构体序列化为JSON
jsonResult, err := json.Marshal(result)
if err != nil {
// 序列化失败,返回错误
reject.Invoke(js.ValueOf(map[string]string{
"error": "JSON序列化失败: " + err.Error(),
}))
reject.Invoke(createErrorJSValue("JSON序列化失败: " + err.Error()))
return
}
// 将JSON字符串解析为JavaScript对象
jsResult := js.Global().Get("JSON").Call("parse", string(jsonResult))
resolve.Invoke(jsResult)
case err := <-errorChan:
// 将错误转换为JavaScript值
reject.Invoke(js.ValueOf(map[string]string{
"error": err.Error(),
}))
reject.Invoke(createErrorJSValue(err.Error()))
}
}()

View File

@@ -136,11 +136,6 @@ func NewTaxHealthService(userID, privateKey string) *TaxHealthService {
// GetCompanyInfo 查询公司信息
func (s *CompanyInfoService) GetCompanyInfo(companyName string, apis []string) (*CompanyInfoResponse, error) {
// 生成随机数和时间戳
r, _ := rand.Int(rand.Reader, big.NewInt(10000))
nonce := strconv.FormatInt(r.Int64(), 10)
timestamp := strconv.FormatInt(time.Now().Unix()*1000, 10)
// 构建查询参数
params := url.Values{}
params.Set("name", companyName)
@@ -148,20 +143,9 @@ func (s *CompanyInfoService) GetCompanyInfo(companyName string, apis []string) (
apiURL := "https://a.cmdp.cn/cmds/v1/company/info-rest/custom?" + params.Encode()
// 生成签名
signData := s.userID + timestamp + nonce + apiURL
signature, err := s.generateSignature([]byte(signData))
if err != nil {
return nil, fmt.Errorf("生成签名失败: %v", err)
}
// 设置请求头
headers := map[string]string{
"Accept": "application/json",
"x-gi-user-id": s.userID,
"x-gi-user-sig": signature,
"x-gi-nonce": nonce,
"x-gi-timestamp": timestamp,
"Accept": "application/json",
}
// 发送GET请求
@@ -182,7 +166,7 @@ func (s *CompanyInfoService) GetCompanyInfo(companyName string, apis []string) (
// EvaluateTaxHealth 执行税务健康测评
func (s *TaxHealthService) EvaluateTaxHealth(request TaxEvalRequest) (*TaxEvalResponse, error) {
// 生成随机数和时间戳
nonce := "12345"
nonce := "123456"
timestamp := strconv.FormatInt(time.Now().Unix()*1000, 10)
apiURL := "https://api.cmdp.cn/v1/eval/tax-risk"
// 序列化请求体
@@ -203,8 +187,6 @@ func (s *TaxHealthService) EvaluateTaxHealth(request TaxEvalRequest) (*TaxEvalRe
headers := map[string]string{
"Content-Type": "application/json",
"Accept": "application/json",
"Host": "api.cmdp.cn",
"origin": "https://api.cmdp.cn",
"x-gi-user-id": s.userID,
"x-gi-user-sig": signature,
"x-gi-nonce": nonce,
@@ -227,9 +209,8 @@ func (s *TaxHealthService) EvaluateTaxHealth(request TaxEvalRequest) (*TaxEvalRe
// QueryTaxEvalResult 查询税务测评结果
func (s *TaxHealthService) QueryTaxEvalResult(orderNo string) (*TaxEvalQueryResponse, error) {
// 生成随机数和时间戳
r, _ := rand.Int(rand.Reader, big.NewInt(10000))
nonce := strconv.FormatInt(time.Now().UnixNano(), 36) + strconv.FormatInt(r.Int64(), 10)
timestamp := strconv.FormatInt(time.Now().Unix(), 10)
nonce := "123456"
timestamp := strconv.FormatInt(time.Now().Unix()*1000, 10)
apiURL := fmt.Sprintf("https://api.cmdp.cn/v1/eval/order/%s", orderNo)
@@ -243,15 +224,11 @@ func (s *TaxHealthService) QueryTaxEvalResult(orderNo string) (*TaxEvalQueryResp
// 设置请求头
headers := map[string]string{
"Accept": "application/json",
"Host": "api.cmdp.cn",
"origin": "https://api.cmdp.cn",
"x-gi-user-id": s.userID,
"x-gi-user-sig": signature,
"x-gi-nonce": nonce,
"x-gi-timestamp": timestamp,
}
fmt.Println(headers)
fmt.Println(apiURL)
// 发送GET请求
response, err := s.httpClient.Get(apiURL, headers)
if err != nil {

View File

@@ -25,11 +25,10 @@ func TestCreateTaxEvalRequest(t *testing.T) {
request := TaxEvalRequest{
ReqNo: fmt.Sprintf("%v", time.Now().Unix()), // 使用时间戳生成请求号
Detail: TaxEvalDetail{
FileURL: "",
Data: companyData,
CompanyName: "顺丰", // 可以从数据中提取公司名称
CompanyName: "郑州惠兴", // 可以从数据中提取公司名称
Period: "Q1",
Year: "2023",
Year: "2022",
},
}

File diff suppressed because it is too large Load Diff

View File

@@ -13,7 +13,6 @@
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
min-height: 100vh;
}
.container {
background-color: white;
border-radius: 15px;
@@ -292,6 +291,84 @@
.config-panel.active {
display: block;
}
.prompt-description, .prompt-input-section, .prompt-params-section,
.prompt-expected-section, .prompt-result-section, .prompt-usage {
margin-bottom: 25px;
padding: 20px;
background-color: white;
border-radius: 10px;
border-left: 5px solid #2196F3;
}
.prompt-description h4, .prompt-params-section h4,
.prompt-expected-section h4, .prompt-result-section h4, .prompt-usage h4 {
margin-top: 0;
color: #2c3e50;
font-size: 1.1em;
}
.prompt-description p {
color: #7f8c8d;
line-height: 1.6;
}
.param-note {
font-size: 0.9em;
color: #95a5a6;
margin-top: 10px;
}
.prompt-result-section {
display: none;
border-left-color: #4caf50;
}
.prompt-result-section.show {
display: block;
animation: fadeIn 0.5s;
}
.prompt-usage ul {
margin: 0;
padding-left: 20px;
color: #7f8c8d;
}
.prompt-usage li {
margin-bottom: 8px;
}
select {
width: 100%;
padding: 12px;
border: 2px solid #bbdefb;
border-radius: 8px;
font-size: 16px;
box-sizing: border-box;
margin-bottom: 15px;
background-color: white;
}
select:focus {
outline: none;
border-color: #64b5f6;
}
@media (max-width: 768px) {
.container {
padding: 20px;
}
.tab button {
padding: 10px 12px;
font-size: 14px;
}
h1 {
font-size: 1.8em;
}
}
</style>
</head>
<body>
@@ -317,15 +394,16 @@
<label for="llmProviderSelect">Provider:</label>
<select id="llmProviderSelect">
<option value="default">default</option>
<option value="ollama">Ollama</option>
<option value="openai">OpenAI</option>
</select>
<label for="llmBaseUrlInput">Base URL:</label>
<input type="text" id="llmBaseUrlInput" placeholder="输入API基础URL" value="http://localhost:11434">
<input type="text" id="llmBaseUrlInput" placeholder="https://api.deepseek.com" value="">
<label for="llmModelInput">Model:</label>
<input type="text" id="llmModelInput" placeholder="输入模型名称" value="qwen3.5:9b">
<input type="text" id="llmModelInput" placeholder="deepseek-v4-flash" value="">
<label for="llmApiKeyInput">API Key:</label>
<input type="password" id="llmApiKeyInput" placeholder="输入API密钥(如果需要)">
@@ -340,6 +418,7 @@
<button class="tablinks active" onclick="openTab(event, 'company')">企业行业分析</button>
<button class="tablinks" onclick="openTab(event, 'excel')">Excel解析</button>
<button class="tablinks" onclick="openTab(event, 'llm')">AI分析</button>
<button class="tablinks" onclick="openTab(event, 'prompt')">Prompt管理</button>
<button class="tablinks" onclick="openTab(event, 'tax')">税务健康</button>
</div>
@@ -370,6 +449,64 @@
</div>
</div>
<!-- Prompt管理标签页 -->
<div id="prompt" class="tabcontent">
<div class="section">
<h3>📝 getPrompt 方法功能展示</h3>
<div class="prompt-description">
<h4>功能描述</h4>
<p>getPrompt 方法用于根据指定的财务报表周期获取对应的提示词模板。系统支持多种周期类型,包括季度(Q1-Q3)和年度报告,每种周期对应专门设计的财务分析提示词,用于指导大模型进行税务健康评估数据转换。</p>
</div>
<div class="prompt-input-section">
<label for="promptPeriodSelect">📅 选择财务周期:</label>
<select id="promptPeriodSelect">
<option value="Q1">Q1 (第一季度)</option>
<option value="第一季度">第一季度</option>
<option value="Q2">Q2 (第二季度)</option>
<option value="第二季度">第二季度</option>
<option value="Q3">Q3 (第三季度)</option>
<option value="第三季度">第三季度</option>
<option value="年度">年度</option>
</select>
</div>
<div class="prompt-params-section">
<h4>📋 输入参数示例</h4>
<div class="json-output" style="background: #fff3e0; border: 1px solid #ff9800; color: #e65100;">
{"period": "Q1"}
</div>
<p class="param-note">参数说明: period 为字符串类型,支持的值包括 Q1、第一季度、Q2、第二季度、Q3、第三季度、年度</p>
</div>
<div class="prompt-expected-section">
<h4>🎯 预期输出结果</h4>
<div class="json-output" style="background: #e8f5e9; border: 1px solid #4caf50; color: #2e7d32;">
{"prompt": "根据选择的周期返回对应的提示词模板", "period": "所选周期"}
</div>
<p class="param-note">返回格式: JSON对象,包含 prompt(提示词内容) 和 period(所选周期) 字段</p>
</div>
<button id="getPromptBtn" disabled>🚀 获取提示词</button>
<div class="prompt-result-section" id="promptResultSection">
<h4>✅ 实际执行结果</h4>
<div id="promptResultContent"></div>
</div>
<div class="prompt-usage">
<h4>📖 使用说明</h4>
<ul>
<li>1. 从下拉菜单中选择一个财务周期</li>
<li>2. 点击「获取提示词」按钮执行 getPrompt 方法</li>
<li>3. 在下方「实际执行结果」区域查看返回的提示词内容</li>
<li>4. 如果选择了不支持的周期,系统会返回错误信息</li>
</ul>
</div>
</div>
</div>
<!-- 税务健康标签页 -->
<div id="tax" class="tabcontent">
<div class="section">
@@ -388,7 +525,7 @@
</select>
<label for="yearInput">📅 报告期:</label>
<input type="number" id="yearInput" placeholder="年份" value="2025" min="1900" max="2100">
<input type="number" id="yearInput" placeholder="年份" value="2021" min="1900" max="2022">
<label for="citInput">💰 企业所得税应纳税额合计 (万元):</label>
<input type="number" id="citInput" placeholder="单位:万元" value="100.0" step="0.01">
@@ -457,6 +594,7 @@
document.getElementById('analyzeCompanyBtn').disabled = false;
document.getElementById('parseExcelBtn').disabled = false;
document.getElementById('callLLMBtn').disabled = false;
document.getElementById('getPromptBtn').disabled = false;
document.getElementById('submitTaxBtn').disabled = false;
document.getElementById('queryResultBtn').disabled = false;
console.log('WASM模块加载完成');
@@ -502,7 +640,8 @@
displayResults('企业行业分析结果', result);
}
} catch (error) {
showError('分析过程中发生错误: ' + error.message);
const errorMsg = error.error || error.message || JSON.stringify(error);
showError('分析过程中发生错误: ' + errorMsg);
} finally {
showLoading(false);
}
@@ -534,7 +673,8 @@
displayResults('Excel解析结果', result);
}
} catch (error) {
showError('解析Excel过程中发生错误: ' + error.message);
const errorMsg = error.error || error.message || JSON.stringify(error);
showError('解析Excel过程中发生错误: ' + errorMsg);
} finally {
showLoading(false);
}
@@ -567,7 +707,8 @@
displayResults('大模型调用结果', result);
}
} catch (error) {
showError('AI分析过程中发生错误: ' + error.message);
const errorMsg = error.error || error.message || JSON.stringify(error);
showError('AI分析过程中发生错误: ' + errorMsg);
} finally {
showLoading(false);
}
@@ -623,7 +764,7 @@
try {
// 构建请求数据
let requestData = {
req_no: 'REQ' + Date.now().toString(),
req_no: Date.now().toString(),
company_name: companyName,
period: period,
year: year.toString(),
@@ -760,7 +901,8 @@
break;
}
} catch (error) {
showError('轮询过程中发生错误: ' + error.message);
const errorMsg = error.error || error.message || JSON.stringify(error);
showError('轮询过程中发生错误: ' + errorMsg);
}
};
@@ -768,7 +910,8 @@
setTimeout(pollForResult, 5000);
}
} catch (error) {
showError('税务健康评估过程中发生错误: ' + error.message);
const errorMsg = error.error || error.message || JSON.stringify(error);
showError('税务健康评估过程中发生错误: ' + errorMsg);
} finally {
showLoading(false);
}
@@ -796,7 +939,43 @@
displayResults('税务评估查询结果', result);
}
} catch (error) {
showError('查询税务评估结果过程中发生错误: ' + error.message);
const errorMsg = error.error || error.message || JSON.stringify(error);
showError('查询税务评估结果过程中发生错误: ' + errorMsg);
} finally {
showLoading(false);
}
});
// getPrompt按钮事件
const getPromptBtn = document.getElementById('getPromptBtn');
const promptPeriodSelect = document.getElementById('promptPeriodSelect');
const promptResultSection = document.getElementById('promptResultSection');
const promptResultContent = document.getElementById('promptResultContent');
getPromptBtn.addEventListener('click', async () => {
const period = promptPeriodSelect.value;
showLoading(true);
hideError();
promptResultSection.classList.remove('show');
try {
const result = await window.getPrompt(period);
if (result && result.error) {
showError(result.error);
} else {
let html = '<div class="json-output" style="background: #e8f5e9; border: 1px solid #4caf50;">';
html += '<strong>周期:</strong> ' + result.period + '<br><br>';
html += '<strong>提示词内容:</strong><br>';
html += '<pre style="white-space: pre-wrap; word-break: break-word;">' + result.prompt + '</pre>';
html += '</div>';
promptResultContent.innerHTML = html;
promptResultSection.classList.add('show');
}
} catch (error) {
const errorMsg = error.error || error.message || JSON.stringify(error);
showError('获取提示词失败: ' + errorMsg);
} finally {
showLoading(false);
}
@@ -810,6 +989,7 @@
analyzeCompanyBtn.disabled = true;
parseExcelBtn.disabled = true;
callLLMBtn.disabled = true;
getPromptBtn.disabled = true;
submitTaxBtn.disabled = true;
queryResultBtn.disabled = true;
} else {
@@ -820,6 +1000,7 @@
analyzeCompanyBtn.disabled = false;
parseExcelBtn.disabled = false;
callLLMBtn.disabled = false;
getPromptBtn.disabled = false;
submitTaxBtn.disabled = false;
queryResultBtn.disabled = false;
}, 100);
@@ -897,13 +1078,13 @@
try {
const config = JSON.parse(savedConfig);
if (document.getElementById('llmProviderSelect')) {
document.getElementById('llmProviderSelect').value = config.provider || 'ollama';
document.getElementById('llmProviderSelect').value = config.provider || 'default';
}
if (document.getElementById('llmBaseUrlInput')) {
document.getElementById('llmBaseUrlInput').value = config.base_url || 'http://localhost:11434';
document.getElementById('llmBaseUrlInput').value = config.base_url || '';
}
if (document.getElementById('llmModelInput')) {
document.getElementById('llmModelInput').value = config.model || 'qwen3.5:9b';
document.getElementById('llmModelInput').value = config.model || '';
}
if (document.getElementById('llmApiKeyInput')) {
document.getElementById('llmApiKeyInput').value = config.api_key || '';
@@ -932,9 +1113,9 @@
// 返回默认配置
return {
provider: 'ollama',
base_url: 'http://localhost:11434',
model: 'qwen3.5:9b',
provider: 'default',
base_url: '',
model: '',
api_key: ''
};
}