Skip to content

Commit

Permalink
LLM selection available
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-lperezra committed Dec 24, 2024
1 parent 3daee81 commit e29c74a
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 17 deletions.
4 changes: 3 additions & 1 deletion encoder-ui/src/app/analyzer/analyzer.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<form class="p-4" (ngSubmit)="onSubmit()" [formGroup]="textForm">
<div class="form-group">
<label for="textToAnalyze" class="font-weight-bold">{{'TEXT-ANALYZE' | transloco}}:</label>
<textarea class="form-control" formControlName="TextToAnalyze" rows="8"></textarea>
<textarea class="form-control" formControlName="TextToAnalyze" rows="8" name="textToAnalyze"></textarea>
<label for="useLLM" class="font-weight-bold form-check-label">{{'USE-LLM' | transloco}}: </label>
<input type="checkbox" class="btn btn-primary" class="form-check-input checkbox-form" name="useLLM" formControlName="UseLLM" value="true">
</div>
<div class="form-group pt-4 text-center">
<button type="submit" class="btn btn-primary" [ngClass]="{'disabled': loading}">
Expand Down
4 changes: 4 additions & 0 deletions encoder-ui/src/app/analyzer/analyzer.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@
max-height: 40vh;
overflow-y: auto;
border-radius: 8px;
}

.checkbox-form {
margin-left: .5em;
}
28 changes: 21 additions & 7 deletions encoder-ui/src/app/analyzer/analyzer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,43 @@ export class AnalyzerComponent {
}

public textForm = new UntypedFormGroup({
TextToAnalyze: new UntypedFormControl('', {nonNullable: true, validators: [Validators.required]})
TextToAnalyze: new UntypedFormControl('', {nonNullable: true, validators: [Validators.required]}),
UseLLM: new UntypedFormControl('', {nonNullable: false, validators: [Validators.required]})
})

get textToAnalyze() {
return this.textForm.get('TextToAnalyze');
}

get useLLM() {
return this.textForm.get('UseLLM');
}

onSubmit() {
this.diagnostics = [];
var textHTML = this.textToAnalyze?.value;
var textOriginal = textHTML;
var textToProcess = this.textToAnalyze?.value.split(".").filter(Boolean);
var llmEnabled = this.useLLM?.value;
var textToProcess = [];
var piecedTextToProcess: any[] = [];
for (var index in textToProcess){
piecedTextToProcess = piecedTextToProcess.concat(textToProcess[index].split(","))

if (llmEnabled) {
piecedTextToProcess = [textOriginal]
}
else {
textToProcess = this.textToAnalyze?.value.split(".").filter(Boolean);
for (var index in textToProcess){
piecedTextToProcess = piecedTextToProcess.concat(textToProcess[index].split(","))
}
}

var forReading = 100/(piecedTextToProcess.length);
this.totalReceived = 0;
this.error = false;
this.loading = true;
this.textAndDiagnosticList = [];
const rawText = {
"Text": textOriginal
"Text": textOriginal,
};
this.irisService.saveRawText(rawText).subscribe({next: raw => {
this.totalReceived = 0;
Expand All @@ -74,7 +87,8 @@ export class AnalyzerComponent {
const textData = {
"ID": raw.id,
"Text": piecedTextToProcess[index],
"Language": this.translocoService.getActiveLang()
"Language": this.translocoService.getActiveLang(),
"UseLLM": llmEnabled
};
this.irisService.analyzeText(textData).subscribe({next: resp =>{
this.totalReceived += forReading;
Expand Down
3 changes: 2 additions & 1 deletion encoder-ui/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
"IMPORTED-RECORDS": "Imported records",
"VECTORIZED-RECORDS": "Vectorized records",
"SIMILARITIES": "Similarities found for",
"MATCHES": "Matches"
"MATCHES": "Matches",
"USE-LLM": "Use LLM for diagnosis recognition"
}
3 changes: 2 additions & 1 deletion encoder-ui/src/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
"IMPORTED-RECORDS": "Registros importados",
"VECTORIZED-RECORDS": "Registros vectorizados",
"SIMILARITIES": "Similitudes encontradas para",
"MATCHES": "Coincidencias"
"MATCHES": "Coincidencias",
"USE-LLM": "Usar LLM para el reconocimiento de diagnósticos"
}
13 changes: 6 additions & 7 deletions src/ENCODER/BP/AnalyzeTextProcess.cls
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ Method OnRequest(pInput As ENCODER.Message.AnalysisRequest, Output pOutput As EN
{

set pOutput = ##class(ENCODER.Message.AnalysisResponse).%New()
set result = ..AnalyzeTextSimplified(pInput.TextToAnalyze, pInput.AnalysisId, pInput.LanguageSelected)
if (pInput.UseLLM) {
set result = ..AnalyzeText(pInput.TextToAnalyze, pInput.AnalysisId, pInput.LanguageSelected)
}
else {
set result = ..AnalyzeTextSimplified(pInput.TextToAnalyze, pInput.AnalysisId, pInput.LanguageSelected)
}
set pOutput.AnalysisRequestId = pInput.AnalysisId
return $$$OK
}
Expand Down Expand Up @@ -50,21 +55,15 @@ Method AnalyzeTextSimplified(text As %String, analysisId As %String, language As
import requests

try:
iris.cls("Ens.Util.Log").LogInfo("ENCODER.BP.AnalyzeTextProcess", "AnalyzeText", "Bottle neck 1")
model = sentence_transformers.SentenceTransformer('/iris-shared/model/')
iris.cls("Ens.Util.Log").LogInfo("ENCODER.BP.AnalyzeTextProcess", "AnalyzeText", "Bottle neck 2")
phrases = text.split(".")
sqlsentence = ""
# iris.cls("Ens.Util.Log").LogInfo("ENCODER.BP.AnalyzeTextProcess", "AnalyzeText", "Starting process")
for phraseToAnalyze in phrases :
iris.cls("Ens.Util.Log").LogInfo("ENCODER.BP.AnalyzeTextProcess", "AnalyzeText", "Bottle neck 3")
if phraseToAnalyze != "":
embedding = model.encode(phraseToAnalyze, normalize_embeddings=True).tolist()
iris.cls("Ens.Util.Log").LogInfo("ENCODER.BP.AnalyzeTextProcess", "AnalyzeText", "Bottle neck 4")
stmt = iris.sql.prepare("INSERT INTO ENCODER_Object.TextMatches (CodeId, Description, Similarity, AnalysisId, RawText) SELECT TOP 50 * FROM (SELECT CodeId, Description, VECTOR_DOT_PRODUCT(VectorDescription, TO_VECTOR(?, DECIMAL)) AS Similarity, ?, ? FROM ENCODER_Object.Codes) WHERE Similarity > 0.65 ORDER BY Similarity DESC")
iris.cls("Ens.Util.Log").LogInfo("ENCODER.BP.AnalyzeTextProcess", "AnalyzeText", "Bottle neck 5")
rs = stmt.execute(str(embedding), analysisId, phraseToAnalyze)
iris.cls("Ens.Util.Log").LogInfo("ENCODER.BP.AnalyzeTextProcess", "AnalyzeText", "Bottle neck 6")
except Exception as err:
iris.cls("Ens.Util.Log").LogInfo("ENCODER.BP.AnalyzeTextProcess", "AnalyzeText", repr(err))
return repr(err)
Expand Down
5 changes: 5 additions & 0 deletions src/ENCODER/Message/AnalysisRequest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Property AnalysisId As %String;

Property LanguageSelected As %String;

Property UseLLM As %Boolean;

Storage Default
{
<Data name="AnalysisRequestDefaultData">
Expand All @@ -20,6 +22,9 @@ Storage Default
<Value name="3">
<Value>LanguageSelected</Value>
</Value>
<Value name="4">
<Value>UseLLM</Value>
</Value>
</Data>
<DefaultData>AnalysisRequestDefaultData</DefaultData>
<Type>%Storage.Persistent</Type>
Expand Down
1 change: 1 addition & 0 deletions src/ENCODER/WS/Service.cls
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ ClassMethod AnalyzeText() As %Status
set analysisRequest.TextToAnalyze = dynamicBody.%Get("Text")
set analysisRequest.AnalysisId = dynamicBody.%Get("ID")
set analysisRequest.LanguageSelected = dynamicBody.%Get("Language")
set analysisRequest.UseLLM = dynamicBody.%Get("UseLLM")

// Creation of BS instance
set status = ##class(Ens.Director).CreateBusinessService("ENCODER.BS.AnalyzeTextService", .instance)
Expand Down

0 comments on commit e29c74a

Please sign in to comment.