Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add unmarshall func to reponse #76

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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