Skip to content

Commit

Permalink
#163: Made it clear what workflow generated a log
Browse files Browse the repository at this point in the history
  • Loading branch information
roma-glushko committed Mar 6, 2024
1 parent a333c19 commit 0ab67cc
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions pkg/routers/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (r *LangRouter) Chat(ctx context.Context, request *schemas.ChatRequest) (*s

resp, err := langModel.Chat(ctx, request)
if err != nil {
r.telemetry.Logger.Warn(
r.telemetry.L().Warn(
"Lang model failed processing chat request",
zap.String("routerID", r.ID()),
zap.String("modelID", langModel.ID()),
Expand All @@ -107,7 +107,7 @@ func (r *LangRouter) Chat(ctx context.Context, request *schemas.ChatRequest) (*s

// no providers were available to handle the request,
// so we have to wait a bit with a hope there is some available next time
r.telemetry.Logger.Warn("No healthy model found, wait and retry", zap.String("routerID", r.ID()))
r.telemetry.L().Warn("No healthy model found to serve chat request, wait and retry", zap.String("routerID", r.ID()))

err := retryIterator.WaitNext(ctx)
if err != nil {
Expand All @@ -117,7 +117,7 @@ func (r *LangRouter) Chat(ctx context.Context, request *schemas.ChatRequest) (*s
}

// if we reach this part, then we are in trouble
r.telemetry.Logger.Error("No model was available to handle request", zap.String("routerID", r.ID()))
r.telemetry.L().Error("No model was available to handle chat request", zap.String("routerID", r.ID()))

return nil, ErrNoModelAvailable
}
Expand All @@ -142,20 +142,10 @@ func (r *LangRouter) ChatStream(ctx context.Context, request *schemas.ChatReques

langModel := model.(providers.LangModel)

if !langModel.SupportChatStream() {
r.telemetry.Logger.Warn("Lang model doesn't support streaming chat API",
zap.String("routerID", r.ID()),
zap.String("modelID", langModel.ID()),
zap.String("provider", langModel.Provider()),
)

continue
}

err = langModel.ChatStream(ctx, request, responseC)
if err != nil {
r.telemetry.Logger.Warn(
"Lang model failed processing chat request",
r.telemetry.L().Warn(
"Lang model failed processing streaming chat request",
zap.String("routerID", r.ID()),
zap.String("modelID", langModel.ID()),
zap.String("provider", langModel.Provider()),
Expand All @@ -170,7 +160,7 @@ func (r *LangRouter) ChatStream(ctx context.Context, request *schemas.ChatReques

// no providers were available to handle the request,
// so we have to wait a bit with a hope there is some available next time
r.telemetry.Logger.Warn("No healthy model found, wait and retry", zap.String("routerID", r.ID()))
r.telemetry.L().Warn("No healthy model found to serve streaming chat request, wait and retry", zap.String("routerID", r.ID()))

err := retryIterator.WaitNext(ctx)
if err != nil {
Expand All @@ -180,8 +170,8 @@ func (r *LangRouter) ChatStream(ctx context.Context, request *schemas.ChatReques
}

// if we reach this part, then we are in trouble
r.telemetry.Logger.Error(
"No model was available to handle request. Try to configure more fallback models to avoid this",
r.telemetry.L().Error(
"No model was available to handle streaming chat request. Try to configure more fallback models to avoid this",
zap.String("routerID", r.ID()),
)

Expand Down

0 comments on commit 0ab67cc

Please sign in to comment.