Skip to content

Commit

Permalink
retry when receiving an invalid response
Browse files Browse the repository at this point in the history
  • Loading branch information
franktip committed Dec 20, 2024
1 parent 35c877a commit ba3d438
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/model/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,20 @@ export class Model implements IModel {
};

performance.mark("llm-query-start");
let res;
let res: any;
try {
res = await retry(
() =>
this.rateLimiter.next(() =>
axios.post(Model.LLMORPHEUS_LLM_API_ENDPOINT, body, {
this.rateLimiter.next(async () => {
const result = await axios.post(Model.LLMORPHEUS_LLM_API_ENDPOINT, body, {
headers: Model.LLMORPHEUS_LLM_AUTH_HEADERS,
})
),
});
// sometimes, we get a response with no prompt tokens. In such cases, throw an exception to force a retry
if (!result || !result.data.usage.prompt_tokens || result.data.usage.prompt_tokens === 0) {
throw new Error("invalid response: no prompt tokens");
}
return result;
}),
this.metaInfo.nrAttempts,
() => {
this.counter.nrRetries++;
Expand Down

0 comments on commit ba3d438

Please sign in to comment.