mirror of
https://github.com/fumiama/deepinfra.git
synced 2026-06-05 00:32:46 +08:00
feat: add error status to Request
This commit is contained in:
10
api.go
10
api.go
@@ -1,7 +1,10 @@
|
|||||||
package deepinfra
|
package deepinfra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -29,6 +32,13 @@ func (api *API) Request(model Model) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
sb := strings.Builder{}
|
||||||
|
sb.WriteString(resp.Status)
|
||||||
|
sb.WriteByte(' ')
|
||||||
|
_, _ = io.Copy(&sb, resp.Body)
|
||||||
|
return "", errors.New(sb.String())
|
||||||
|
}
|
||||||
err = model.Parse(resp.Body)
|
err = model.Parse(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|||||||
15
model.go
15
model.go
@@ -1,8 +1,6 @@
|
|||||||
package deepinfra
|
package deepinfra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/fumiama/deepinfra/model"
|
"github.com/fumiama/deepinfra/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -10,16 +8,3 @@ type Model interface {
|
|||||||
model.Inputer
|
model.Inputer
|
||||||
model.Outputer
|
model.Outputer
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
api := NewAPI(APIDeepInfra, "PUT YOUR API KEY HERE")
|
|
||||||
txt, err := api.Request(model.NewOpenAI("fumiama/ninus", "", 0.7, 0.9, 1024).
|
|
||||||
System("你正在QQ群与用户聊天,用户发送了消息。按自己的心情简短思考后,条理清晰地回应**一句话**,禁止回应多句。").
|
|
||||||
User("总不能什么都查吧").User("后面DOGE就成恶龙了 很常见的场景"),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
fmt.Println(txt)
|
|
||||||
// 要不我给你查一下?
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user