Compare commits
No commits in common. "d404a5127e5a0946b2287e2ded789cc9e0816229" and "7de997133302c67b9627441f35f37b97ade53ec8" have entirely different histories.
d404a5127e
...
7de9971333
35
ai.go
35
ai.go
|
@ -2,12 +2,9 @@ package l_ai_address
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"gitea.cdlsxd.cn/self-tools/l_ai_address/ai/doubao"
|
"gitea.cdlsxd.cn/self-tools/l_ai_address/ai/doubao"
|
||||||
"gitea.cdlsxd.cn/self-tools/l_request"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Address struct {
|
type Address struct {
|
||||||
|
@ -16,7 +13,7 @@ type Address struct {
|
||||||
D string
|
D string
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAddress2(ctx context.Context, address, key, model string) (Address, error) {
|
func GetAddress(ctx context.Context, address, key, model string) (Address, error) {
|
||||||
|
|
||||||
modelObj := doubao.NewDouBao(model, key)
|
modelObj := doubao.NewDouBao(model, key)
|
||||||
text := []string{
|
text := []string{
|
||||||
|
@ -53,31 +50,3 @@ func GetAddress2(ctx context.Context, address, key, model string) (Address, erro
|
||||||
resSlice := strings.Split(res, ",")
|
resSlice := strings.Split(res, ",")
|
||||||
return Address{P: resSlice[0], C: resSlice[1], D: resSlice[2]}, nil
|
return Address{P: resSlice[0], C: resSlice[1], D: resSlice[2]}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAddress(ctx context.Context, orderAddress, address string) (Address, error) {
|
|
||||||
request := map[string]interface{}{
|
|
||||||
"address": orderAddress,
|
|
||||||
}
|
|
||||||
req := l_request.Request{
|
|
||||||
Method: "POST",
|
|
||||||
Url: address,
|
|
||||||
Json: request,
|
|
||||||
}
|
|
||||||
var resBert AddressBert
|
|
||||||
res, err := req.Send()
|
|
||||||
if err != nil {
|
|
||||||
return Address{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res.Content, &resBert)
|
|
||||||
adsStr := strings.Split(resBert.Predictions[0].Address, ",")
|
|
||||||
return Address{P: adsStr[0], C: adsStr[1], D: adsStr[2]}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddressBert struct {
|
|
||||||
Predictions []struct {
|
|
||||||
Address string `json:"address"`
|
|
||||||
Confidence float64 `json:"confidence"`
|
|
||||||
} `json:"predictions"`
|
|
||||||
Status string `json:"status"`
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,11 +2,10 @@ package doubao
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/volcengine/volcengine-go-sdk/service/arkruntime"
|
"github.com/volcengine/volcengine-go-sdk/service/arkruntime"
|
||||||
"github.com/volcengine/volcengine-go-sdk/service/arkruntime/model"
|
"github.com/volcengine/volcengine-go-sdk/service/arkruntime/model"
|
||||||
"github.com/volcengine/volcengine-go-sdk/volcengine"
|
"github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DouBao struct {
|
type DouBao struct {
|
||||||
|
@ -24,8 +23,9 @@ func NewDouBao(modelName string, key string) *DouBao {
|
||||||
func (o *DouBao) GetData(ctx context.Context, url UrlType, respHandle func(input string) (string, error), text ...string) (string, error) {
|
func (o *DouBao) GetData(ctx context.Context, url UrlType, respHandle func(input string) (string, error), text ...string) (string, error) {
|
||||||
var Message = make([]*model.ChatCompletionMessage, len(text))
|
var Message = make([]*model.ChatCompletionMessage, len(text))
|
||||||
|
|
||||||
|
key := "914ccf1d-c002-4fad-a431-f291f5e0d2ad"
|
||||||
client := arkruntime.NewClientWithApiKey(
|
client := arkruntime.NewClientWithApiKey(
|
||||||
o.Key,
|
key,
|
||||||
//arkruntime.WithBaseUrl(UrlMap[url]),
|
//arkruntime.WithBaseUrl(UrlMap[url]),
|
||||||
arkruntime.WithRegion("cn-beijing"),
|
arkruntime.WithRegion("cn-beijing"),
|
||||||
arkruntime.WithTimeout(2*time.Minute),
|
arkruntime.WithTimeout(2*time.Minute),
|
||||||
|
|
|
@ -6,6 +6,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAddress(t *testing.T) {
|
func TestAddress(t *testing.T) {
|
||||||
res, err := GetAddress(context.Background(), "四川省达州市", "http://117.175.169.61:5003/predict")
|
res, err := GetAddress(context.Background(), "上海市市辖县崇明县三星镇社区卫生服务中心", )
|
||||||
t.Log(res, err)
|
t.Log(res, err)
|
||||||
}
|
}
|
||||||
|
|
5
go.mod
5
go.mod
|
@ -2,10 +2,7 @@ module gitea.cdlsxd.cn/self-tools/l_ai_address
|
||||||
|
|
||||||
go 1.23.6
|
go 1.23.6
|
||||||
|
|
||||||
require (
|
require github.com/volcengine/volcengine-go-sdk v1.0.184
|
||||||
gitea.cdlsxd.cn/self-tools/l_request v1.0.8
|
|
||||||
github.com/volcengine/volcengine-go-sdk v1.1.23
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
|
|
Loading…
Reference in New Issue