12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package model
- import (
- "aiChat/internal/consts"
- "context"
- "github.com/gogf/gf/v2/frame/g"
- "github.com/gogf/gf/v2/net/gclient"
- "github.com/gogf/gf/v2/util/gconv"
- "github.com/gogf/gf/v2/util/grand"
- )
- type GPTReq struct {
- *BaseQuestion
- Identity string `json:"identity"`
- }
- type GPTRes struct {
- Status int `json:"status"`
- Response string `json:"response"`
- History [][]string `json:"history"`
- Time string `json:"time"`
- }
- var (
- ChatGpt = &cChatGpt{}
- )
- type cChatGpt struct {
- }
- var (
- tmp = []string{
- "smart_潜在客户_smart",
- }
- )
- func (c *cChatGpt) Do(ctx context.Context, qReq *QuestionReq) (res *GPTRes, err error) {
- //模拟请求
- return &GPTRes{
- Status: 0,
- Response: tmp[grand.Intn(len(tmp)-1)],
- History: nil,
- }, nil
- //
- gReq := GPTReq{
- BaseQuestion: qReq.BaseQuestion,
- Identity: g.Config().MustGet(ctx, "chat.api.identity", "剑鱼chat").String(),
- }
- //g.Dump(gReq)
- var gRes *gclient.Response
- gRes, err = g.Client().Header(consts.RequestJsonHeader).Post(ctx, g.Config().MustGet(ctx, "chat.api.addr", "").String(), gReq)
- if err != nil {
- return nil, err
- }
- res = &GPTRes{}
- err = gconv.Struct(gRes.ReadAll(), res)
- if err != nil {
- return nil, err
- }
- return
- }
|