diff --git a/ai.go b/ai.go index 59ab9f8..b505efd 100644 --- a/ai.go +++ b/ai.go @@ -2,6 +2,7 @@ package l_ai_address import ( "context" + "fmt" "gitea.cdlsxd.cn/self-tools/l_ai_address/ai/doubao" "strings" ) @@ -23,7 +24,25 @@ func GetAddress(ctx context.Context, address, key, model string) (Address, error "-区给具体的名称,不要返回市辖区", } res, err := modelObj.GetData(ctx, doubao.Text, func(input string) (string, error) { - return input, nil + var resStr string + inputSlice := strings.Split(input, ",") + + if len(inputSlice) < 3 { + switch len(inputSlice) { + case 2: + if strings.HasSuffix(inputSlice[0], "市") { + runes := []rune(inputSlice[0]) + resStr = fmt.Sprintf("%s,%s", string(runes[:len(runes)-1]), input) + } else { + resStr = fmt.Sprintf("%s,%s,%s", inputSlice[0], inputSlice[0]+"市", inputSlice[1]) + } + default: + return input, fmt.Errorf("地址解析失败:%s", input) + } + } else { + resStr = input + } + return resStr, nil }, text...) if err != nil { return Address{}, err diff --git a/ai_test.go b/ai_test.go index e955f2d..dfc58fd 100644 --- a/ai_test.go +++ b/ai_test.go @@ -6,6 +6,6 @@ import ( ) func TestAddress(t *testing.T) { - res, err := GetAddress(context.Background(), "广西壮族自治区钦州市市辖区乘风大道乘风小区", "236ba4b6-9daa-4755-b22f-2fd274cd223a", "doubao-1-5-lite-32k-250115") + res, err := GetAddress(context.Background(), "上海市市辖县崇明县三星镇社区卫生服务中心", "236ba4b6-9daa-4755-b22f-2fd274cd223a", "doubao-1-5-lite-32k-250115") t.Log(res, err) }