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 llm error handling for data extract #119

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
27 changes: 21 additions & 6 deletions src/services/data-extraction/data-extraction.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {first, GenAiModel, GenerativeResponse} from "../../utils";
import pQueue from '../../utils/p-queue'
import PQueue from "../../utils/p-queue";

const queue = new PQueue({concurrency: 4});
const queue = new PQueue({concurrency: 2});

export interface DataExtractionBackendConfig {
identityUrl: string;
Expand Down Expand Up @@ -219,11 +219,26 @@ export class DataExtractionImpl extends DataExtractionCsv<WatsonBackends, Contex
const input = prompt + '\n\n' + text;

const modelId = config.model || this.backendConfig.modelId;
const result: GenerativeResponse = await backends.wml.generate({
input,
modelId,
parameters,
});
const result: GenerativeResponse = await backends.wml
.generate({
input,
modelId,
parameters,
})
.then(result => {
if (result?.generatedText?.trim()) {
return result
}

const fallbackModelId: string = 'meta-llama/llama-2-70b-chat'
console.log(`*** No information returned from generate. Trying again with ${fallbackModelId} model`)

return backends.wml.generate({
input,
modelId: fallbackModelId,
parameters,
})
});

console.log('2. Text generated from watsonx.ai:', {prompt, modelId, max_new_tokens, generatedText: result.generatedText, input})

Expand Down
2 changes: 1 addition & 1 deletion src/utils/gen-ai-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class GenAiModel {
}

console.log('Error generating text: ', err);
throw err;
return {generatedText: '[Error]'}
})
}
}