nomagick commited on
Commit
f3654a7
·
unverified ·
1 Parent(s): a471a61

fix: beware readerlm capacity drain

Browse files
Files changed (1) hide show
  1. src/api/crawler.ts +11 -2
src/api/crawler.ts CHANGED
@@ -35,7 +35,8 @@ import { AsyncLocalContext } from '../services/async-context';
35
  import { Context, Ctx, Method, Param, RPCReflect } from '../services/registry';
36
  import {
37
  BudgetExceededError, InsufficientBalanceError,
38
- SecurityCompromiseError, ServiceBadApproachError, ServiceBadAttemptError
 
39
  } from '../services/errors';
40
 
41
  import { countGPTToken as estimateToken } from '../shared/utils/openai';
@@ -45,6 +46,7 @@ import { JinaEmbeddingsAuthDTO } from '../dto/jina-embeddings-auth';
45
  import { RobotsTxtService } from '../services/robots-text';
46
  import { TempFileManager } from '../services/temp-file';
47
  import { MiscService } from '../services/misc';
 
48
 
49
  export interface ExtraScrappingOptions extends ScrappingOptions {
50
  withIframe?: boolean | 'quoted';
@@ -685,7 +687,14 @@ export class CrawlerHost extends RPCHost {
685
  return;
686
  }
687
 
688
- yield* this.lmControl.readerLMMarkdownFromSnapshot(finalAutoSnapshot);
 
 
 
 
 
 
 
689
 
690
  return;
691
  }
 
35
  import { Context, Ctx, Method, Param, RPCReflect } from '../services/registry';
36
  import {
37
  BudgetExceededError, InsufficientBalanceError,
38
+ SecurityCompromiseError, ServiceBadApproachError, ServiceBadAttemptError,
39
+ ServiceNodeResourceDrainError
40
  } from '../services/errors';
41
 
42
  import { countGPTToken as estimateToken } from '../shared/utils/openai';
 
46
  import { RobotsTxtService } from '../services/robots-text';
47
  import { TempFileManager } from '../services/temp-file';
48
  import { MiscService } from '../services/misc';
49
+ import { HTTPServiceError } from 'civkit';
50
 
51
  export interface ExtraScrappingOptions extends ScrappingOptions {
52
  withIframe?: boolean | 'quoted';
 
687
  return;
688
  }
689
 
690
+ try {
691
+ yield* this.lmControl.readerLMMarkdownFromSnapshot(finalAutoSnapshot);
692
+ } catch (err) {
693
+ if (err instanceof HTTPServiceError && err.status === 429) {
694
+ throw new ServiceNodeResourceDrainError(`Reader LM is at capacity, please try again later.`);
695
+ }
696
+ throw err;
697
+ }
698
 
699
  return;
700
  }