Skip to content

Commit

Permalink
update tests and LLM latency score
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-astra-video committed Jan 7, 2025
1 parent 6a31695 commit ddb3a7c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion core/ai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,10 @@ func (a *stubAIWorker) SegmentAnything2(ctx context.Context, req worker.GenSegme
}

func (a *stubAIWorker) LLM(ctx context.Context, req worker.GenLLMJSONRequestBody) (interface{}, error) {
return &worker.LLMResponse{Response: "response tokens", TokensUsed: 10}, nil
var choices []worker.LLMChoice
choices = append(choices, worker.LLMChoice{Delta: worker.LLMMessage{Content: "choice1", Role: "assistant"}, Index: 0})
tokensUsed := worker.LLMTokenUsage{PromptTokens: 40, CompletionTokens: 10, TotalTokens: 50}
return &worker.LLMResponse{Choices: choices, Created: 1, Model: "llm_model", TokensUsed: tokensUsed}, nil
}

func (a *stubAIWorker) ImageToText(ctx context.Context, req worker.GenImageToTextMultipartRequestBody) (*worker.ImageToTextResponse, error) {
Expand Down
2 changes: 1 addition & 1 deletion server/ai_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ func handleNonStreamingResponse(ctx context.Context, body io.ReadCloser, sess *A
}

took := time.Since(start)
sess.LatencyScore = CalculateLLMLatencyScore(took, res.TokensUsed)
sess.LatencyScore = CalculateLLMLatencyScore(took, res.TokensUsed.TotalTokens)

if monitor.Enabled {
var pricePerAIUnit float64
Expand Down
5 changes: 4 additions & 1 deletion server/ai_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,10 @@ func (a *stubAIWorker) LLM(ctx context.Context, req worker.GenLLMJSONRequestBody
if a.Err != nil {
return nil, a.Err
} else {
return &worker.LLMResponse{Response: "output tokens", TokensUsed: 10}, nil
var choices []worker.LLMChoice
choices = append(choices, worker.LLMChoice{Delta: worker.LLMMessage{Content: "choice1", Role: "assistant"}, Index: 0})
tokensUsed := worker.LLMTokenUsage{PromptTokens: 40, CompletionTokens: 10, TotalTokens: 50}
return &worker.LLMResponse{Choices: choices, Created: 1, Model: "llm_model", TokensUsed: tokensUsed}, nil
}
}

Expand Down

0 comments on commit ddb3a7c

Please sign in to comment.