first commit
This commit is contained in:
parent
03ba799e53
commit
36504f6e33
35
ai.go
35
ai.go
|
@ -2,9 +2,12 @@ package l_ai_address
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitea.cdlsxd.cn/self-tools/l_ai_address/ai/doubao"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"gitea.cdlsxd.cn/self-tools/l_ai_address/ai/doubao"
|
||||||
|
"gitea.cdlsxd.cn/self-tools/l_request"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Address struct {
|
type Address struct {
|
||||||
|
@ -13,7 +16,7 @@ type Address struct {
|
||||||
D string
|
D string
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAddress(ctx context.Context, address, key, model string) (Address, error) {
|
func GetAddress2(ctx context.Context, address, key, model string) (Address, error) {
|
||||||
|
|
||||||
modelObj := doubao.NewDouBao(model, key)
|
modelObj := doubao.NewDouBao(model, key)
|
||||||
text := []string{
|
text := []string{
|
||||||
|
@ -50,3 +53,31 @@ func GetAddress(ctx context.Context, address, key, model string) (Address, error
|
||||||
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,10 +2,11 @@ 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 {
|
||||||
|
@ -23,9 +24,8 @@ 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(
|
||||||
key,
|
o.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(), "上海市市辖县崇明县三星镇社区卫生服务中心", "236ba4b6-9daa-4755-b22f-2fd274cd223a", "doubao-1-5-lite-32k-250115")
|
res, err := GetAddress(context.Background(), "四川省达州市", "http://117.175.169.61:5003/predict")
|
||||||
t.Log(res, err)
|
t.Log(res, err)
|
||||||
}
|
}
|
||||||
|
|
5
go.mod
5
go.mod
|
@ -2,7 +2,10 @@ module gitea.cdlsxd.cn/self-tools/l_ai_address
|
||||||
|
|
||||||
go 1.23.6
|
go 1.23.6
|
||||||
|
|
||||||
require github.com/volcengine/volcengine-go-sdk v1.0.184
|
require (
|
||||||
|
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