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

update: debug log #26

Merged
merged 1 commit into from
Nov 20, 2023
Merged
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
4 changes: 4 additions & 0 deletions pkg/llm/client/glm-6b/client.go
Original file line number Diff line number Diff line change
@@ -27,15 +27,18 @@ import (

"github.com/basenana/friday/pkg/llm"
"github.com/basenana/friday/pkg/llm/prompts"
"github.com/basenana/friday/pkg/utils/logger"
)

type GLM struct {
log logger.Logger
baseUri string
}

func NewGLM(uri string) llm.LLM {
return &GLM{
baseUri: uri,
log: logger.NewLogger("glm"),
}
}

@@ -62,6 +65,7 @@ func (o *GLM) request(path string, method string, body io.Reader) ([]byte, error
if resp.StatusCode != 200 {
return nil, fmt.Errorf("fail to call glm-6b, status code error: %d", resp.StatusCode)
}
o.log.Debugf("openai response: %s", respBody)
return respBody, nil
}

15 changes: 1 addition & 14 deletions pkg/llm/client/openai/v1/chat.go
Original file line number Diff line number Diff line change
@@ -19,8 +19,6 @@ package v1
import (
"context"
"encoding/json"
"strings"
"time"

"github.com/basenana/friday/pkg/llm/prompts"
)
@@ -41,17 +39,7 @@ type ChatChoice struct {
}

func (o *OpenAIV1) Chat(ctx context.Context, prompt prompts.PromptTemplate, parameters map[string]string) ([]string, error) {
answer, err := o.chat(ctx, prompt, parameters)
if err != nil {
errMsg := err.Error()
if strings.Contains(errMsg, "rate_limit_exceeded") || strings.Contains(errMsg, "Rate limit reached") {
o.log.Warn("meets rate limit exceeded, sleep 30 seconds and retry")
time.Sleep(time.Duration(30) * time.Second)
return o.chat(ctx, prompt, parameters)
}
return nil, err
}
return answer, err
return o.chat(ctx, prompt, parameters)
}

func (o *OpenAIV1) chat(ctx context.Context, prompt prompts.PromptTemplate, parameters map[string]string) ([]string, error) {
@@ -62,7 +50,6 @@ func (o *OpenAIV1) chat(ctx context.Context, prompt prompts.PromptTemplate, para
if err != nil {
return nil, err
}
o.log.Debugf("final prompt: %s", p)

data := map[string]interface{}{
"model": model,
3 changes: 1 addition & 2 deletions pkg/llm/client/openai/v1/client.go
Original file line number Diff line number Diff line change
@@ -90,7 +90,6 @@ func (o *OpenAIV1) request(ctx context.Context, path string, method string, data
req.Header.Set("Content-Type", "application/json; charset=utf-8")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", o.key))

o.log.Debugf("request: %s", uri)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
@@ -108,7 +107,7 @@ func (o *OpenAIV1) request(ctx context.Context, path string, method string, data
time.Sleep(time.Second * 30)
continue
}
//o.log.Debugf("response: %s", respBody)
o.log.Debugf("openai response: %s", respBody)
return respBody, nil
}
}
14 changes: 1 addition & 13 deletions pkg/llm/client/openai/v1/completion.go
Original file line number Diff line number Diff line change
@@ -19,8 +19,6 @@ package v1
import (
"context"
"encoding/json"
"strings"
"time"

"github.com/basenana/friday/pkg/llm/prompts"
)
@@ -42,17 +40,7 @@ type Choice struct {
}

func (o *OpenAIV1) Completion(ctx context.Context, prompt prompts.PromptTemplate, parameters map[string]string) ([]string, error) {
answer, err := o.completion(ctx, prompt, parameters)
if err != nil {
errMsg := err.Error()
if strings.Contains(errMsg, "rate_limit_exceeded") {
o.log.Warn("meets rate limit exceeded, sleep 30 seconds and retry")
time.Sleep(time.Duration(30) * time.Second)
return o.completion(ctx, prompt, parameters)
}
return nil, err
}
return answer, err
return o.completion(ctx, prompt, parameters)
}

func (o *OpenAIV1) completion(ctx context.Context, prompt prompts.PromptTemplate, parameters map[string]string) ([]string, error) {
14 changes: 1 addition & 13 deletions pkg/llm/client/openai/v1/embedding.go
Original file line number Diff line number Diff line change
@@ -19,8 +19,6 @@ package v1
import (
"context"
"encoding/json"
"strings"
"time"
)

type EmbeddingResult struct {
@@ -46,17 +44,7 @@ type Usage struct {
}

func (o *OpenAIV1) Embedding(ctx context.Context, doc string) (*EmbeddingResult, error) {
answer, err := o.embedding(ctx, doc)
if err != nil {
errMsg := err.Error()
if strings.Contains(errMsg, "rate_limit_exceeded") {
o.log.Warn("meets rate limit exceeded, sleep 30 seconds and retry")
time.Sleep(time.Duration(30) * time.Second)
return o.embedding(ctx, doc)
}
return nil, err
}
return answer, err
return o.embedding(ctx, doc)
}

func (o *OpenAIV1) embedding(ctx context.Context, doc string) (*EmbeddingResult, error) {