Skip to content

Commit

Permalink
fix: add unmarshall func to reponse
Browse files Browse the repository at this point in the history
Signed-off-by: bjwswang <[email protected]>
  • Loading branch information
bjwswang committed Sep 4, 2023
1 parent aa617ad commit abcbdc4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/llms/llms.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Response interface {
Type() LLMType
String() string
Bytes() []byte
Unmarshall([]byte) error
}

type UnknowLLM struct{}
Expand Down
7 changes: 6 additions & 1 deletion pkg/llms/openai/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ package openai
import (
"encoding/json"
"fmt"
"github.com/kubeagi/arcadia/pkg/llms"
"net/http"

"github.com/kubeagi/arcadia/pkg/llms"
)

type Response struct {
Expand All @@ -46,6 +47,10 @@ func (response *Response) String() string {
return string(response.Bytes())
}

func (response *Response) Unmarshall(bytes []byte) error {
return json.Unmarshal(bytes, response)
}

func parseHTTPResponse(resp *http.Response) (*Response, error) {
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("exception: %s", resp.Status)
Expand Down
4 changes: 4 additions & 0 deletions pkg/llms/zhipuai/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ type EmbeddingResponse struct {
Success bool `json:"success"`
}

func (response *Response) Unmarshall(bytes []byte) error {
return json.Unmarshal(response.Bytes(), response)
}

func (response *Response) Type() llms.LLMType {
return llms.ZhiPuAI
}
Expand Down

0 comments on commit abcbdc4

Please sign in to comment.