40 lines
822 B
Go
40 lines
822 B
Go
package remote_http
|
|
|
|
import (
|
|
"ai-gateway/common/dto"
|
|
"ai-gateway/common/utils"
|
|
"code.freebrio.com/fb-go/lib/context"
|
|
"fmt"
|
|
)
|
|
|
|
type aiApiImpl struct {
|
|
}
|
|
|
|
func (aiApiImpl) Completions(ctx context.GormWithZap, prompt, groupId string) (*dto.AiRes, error) {
|
|
logger := utils.NewLog("")
|
|
|
|
url := "http://ai.mylomen.com/text/v6/completions"
|
|
|
|
var aiResult Result[dto.AiRes]
|
|
resp, err := httpClient.R().
|
|
SetBody(map[string]interface{}{
|
|
"prompt": prompt,
|
|
"maxTokens": 500,
|
|
"groupId": groupId,
|
|
}).
|
|
SetSuccessResult(&aiResult).
|
|
Post(url)
|
|
if err != nil {
|
|
|
|
logger.Error(fmt.Sprintf("remote_http_wx_SendMsg error: %s", err.Error()))
|
|
return nil, err
|
|
}
|
|
|
|
if !resp.IsSuccessState() {
|
|
logger.Error(fmt.Sprintf("remote_http_wx_SendMsg resp:%+v", resp))
|
|
return nil, err
|
|
}
|
|
|
|
return &aiResult.Data, nil
|
|
}
|