This commit is contained in:
renzhiyuan 2025-07-21 15:19:21 +08:00
commit 5ba4fbcb03
5 changed files with 135 additions and 0 deletions

27
ai.go Normal file
View File

@ -0,0 +1,27 @@
package l_ai_excel_header_match
import (
"context"
"encoding/json"
"gitea.cdlsxd.cn/self-tools/l_ai_address/ai/doubao"
"strings"
)
func ExcelMatch(ctx context.Context, matchToExcelHeader, selfExcelHeader []string, key string, model string) (result map[string]interface{}, err error) {
modelObj := doubao.NewDouBao(model, key)
text := []string{
"第一张表表头为key第二张表表头为value如果未匹配到则返回空",
"-第一个表头:[" + strings.Join(selfExcelHeader, ",") + "]",
"-第二个表头:[" + strings.Join(matchToExcelHeader, ",") + "]",
"-第一张表表头为key,第二张表表头为value,返回一个map映射的json字符串",
"-不需要其他额外的表述以及格式",
}
res, err := modelObj.GetData(ctx, doubao.Text, func(input string) (string, error) {
return input, nil
}, text...)
err = json.Unmarshal([]byte(res), &result)
return
}

21
ai_test.go Normal file
View File

@ -0,0 +1,21 @@
package l_ai_excel_header_match
import (
"context"
"testing"
)
func TestAddress(t *testing.T) {
res, err := ExcelMatch(context.Background(), a, b, "", "")
t.Log(res, err)
}
var (
a = []string{
"条码", "分类名称", "货品名称", "货品编号", "商品货号", "品牌", "单位", "规格参数", "货品说明", "保质期", "保质期单位", "链接", "货品图片", "电商销售价格", "销售价", "供应商报价", "税率", "默认供应商", "默认存放仓库", "第三方商品编码", "备注", "长", "宽", "高", "重量", "SPU编码", "SPU名称",
}
b = []string{
"商品名称(手工输入)", "品牌(单选)", "商品型号(手工输入)", "商品条码/ISBN/ISSN(手工输入)", "条形码资质1(手工输入)", "条形码资质2(手工输入)", "条形码资质3(手工输入)", "产地(国家)(单选)", "产地(省份)(单选)", "产地(市)(单选)", "长度(手工输入,单位:毫米)", "宽度(手工输入,单位:毫米)", "高度(手工输入,单位:毫米)", "体积(手工输入,单位:立方厘米)", "毛重(手工输入,单位:千克)", "厂家包装含量(手工输入)", "商品税率(单选)(单选)", "采购单位", "供应商商品编码(手工输入)", "商品详情(手工输入)", "发货清单1(手工输入)", "发货清单2(手工输入)", "发货清单3(手工输入)", "发货清单4(手工输入)", "发货清单5(手工输入)", "商品标题(手工输入)", "商品卖点(手工输入)", "促销常规卖点(手工输入)", "促销常规卖点生效时间", "促销常规卖点失效时间", "促销高级卖点(手工输入)", "促销高级卖点生效时间", "促销高级卖点失效时间", "活动关联文案(手工输入)", "电脑端链接(手工输入)", "移动端链接(手工输入)", "活动链接生效时间", "活动链接失效时间", "商品图片1(手工输入)", "商品图片2(手工输入)", "商品图片3(手工输入)", "商品图片4(手工输入)", "商品图片5(手工输入)", "生产者(制造商)名称(手工输入)", "生产商(制造商)地址(手工输入)", "执行标准(手工输入)", "类别(单选)", "茶具类型(单选)", "国产/进口(单选)", "茶具材质(单选)", "上市时间(月)(手工输入)", "茶盘材质(多选)(可选项为:石质,电木,树脂,陶瓷,竹质,木质,其它)", "工艺(单选)", "风格(单选)", "适用人数(单选)", "功能(单选)", "容量(手工输入,单位:毫升)",
}
)

17
doubao/constant.go Normal file
View File

@ -0,0 +1,17 @@
package doubao
var UrlMap = map[UrlType]string{
Text: "https://ark.cn-beijing.volces.com/api/v3/chat/completions",
Video: "https://ark.cn-beijing.volces.com/api/v3/contents/generations/tasks",
Embedding: "https://ark.cn-beijing.volces.com/api/v3/embeddings",
Token: "https://ark.cn-beijing.volces.com/api/v3/tokenization",
}
type UrlType string
const (
Text UrlType = "text"
Video UrlType = "video"
Embedding UrlType = "embedding"
Token UrlType = "token"
)

53
doubao/doubao.go Normal file
View File

@ -0,0 +1,53 @@
package doubao
import (
"context"
"github.com/volcengine/volcengine-go-sdk/service/arkruntime"
"github.com/volcengine/volcengine-go-sdk/service/arkruntime/model"
"github.com/volcengine/volcengine-go-sdk/volcengine"
"time"
)
type DouBao struct {
Model string
Key string
}
func NewDouBao(modelName string, key string) *DouBao {
return &DouBao{
Model: modelName,
Key: key,
}
}
func (o *DouBao) GetData(ctx context.Context, respHandle func(input string) (string, error), text ...string) (string, error) {
var Message = make([]*model.ChatCompletionMessage, len(text))
client := arkruntime.NewClientWithApiKey(
o.Key,
//arkruntime.WithBaseUrl(UrlMap[url]),
arkruntime.WithRegion("cn-beijing"),
arkruntime.WithTimeout(2*time.Minute),
arkruntime.WithRetryTimes(2),
)
for k, v := range text {
Message[k] = &model.ChatCompletionMessage{
Role: model.ChatMessageRoleSystem,
Content: &model.ChatCompletionMessageContent{
StringValue: volcengine.String(v),
},
}
}
req := model.CreateChatCompletionRequest{
Model: o.Model,
Messages: Message,
}
resp, err := client.CreateChatCompletion(ctx, req)
if err != nil {
return "", err
}
result, err := respHandle(*resp.Choices[0].Message.Content.StringValue)
return result, err
}

17
go.mod Normal file
View File

@ -0,0 +1,17 @@
module l-ai-excel-header-match
go 1.23.6
toolchain go1.23.10
require (
gitea.cdlsxd.cn/self-tools/l_ai_address v1.2.0
github.com/volcengine/volcengine-go-sdk v1.1.23
)
require (
github.com/google/uuid v1.3.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/volcengine/volc-sdk-golang v1.0.23 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)