Skip to content

Commit cb739b4

Browse files
Padroniza nome de metodo que obtem tipo de IA (LLAMA ou GEMINI)
1 parent f501379 commit cb739b4

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

markup_doc/labeling_utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414
from .choices import order_labels
1515

1616

17+
MODEL_NAME_GEMINI = 'GEMINI'
18+
MODEL_NAME_LLAMA = 'LLAMA'
1719

18-
def getLLM():
20+
21+
def get_llm_model_name():
22+
# FIXME: This function always fetches the first LlamaModel instance.
1923
model_ai = LlamaModel.objects.first()
2024

2125
if model_ai.api_key_gemini:
22-
return 'GEMINI'
26+
return MODEL_NAME_GEMINI
2327
else:
24-
return 'LLAMA'
28+
return MODEL_NAME_LLAMA
2529

2630

2731
def split_in_three(obj_reference, chunk_size=15):

markup_doc/tasks.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717
extract_keywords,
1818
create_labeled_object2,
1919
get_data_first_block,
20-
getLLM
20+
get_llm_model_name
2121
)
2222
from markup_doc.models import ProcessStatus
23+
from markup_doc.labeling_utils import MODEL_NAME_GEMINI, MODEL_NAME_LLAMA
2324
from markup_doc.sync_api import sync_journals_from_api
2425
from markuplib.function_docx import functionsDocx
2526
from model_ai.llama import LlamaService, LlamaInputSettings
2627
from reference.config_gemini import create_prompt_reference
2728

2829

30+
2931
def clean_labels(text):
3032
# Eliminar etiquetas tipo [kwd] o [sectitle], incluso si tienen espacios como [/ doctitle ]
3133
text = re.sub(r'\[\s*/?\s*\w+(?:\s+[^\]]+)?\s*\]', '', text)
@@ -151,16 +153,16 @@ def get_labels(title, user_id):
151153
continue
152154

153155
if item.get('type') == 'first_block':
154-
first_block = LlamaService(mode='prompt', temperature=0.1)
156+
llm_first_block = LlamaService(mode='prompt', temperature=0.1)
155157

156-
if getLLM() == 'GEMINI':
157-
output = first_block.run(LlamaInputSettings.get_first_metadata(clean_labels(item.get('text'))))
158+
if get_llm_model_name() == MODEL_NAME_GEMINI:
159+
output = llm_first_block.run(LlamaInputSettings.get_first_metadata(clean_labels(item.get('text'))))
158160
match = re.search(r'\{.*\}', output, re.DOTALL)
159161
if match:
160162
output = match.group(0)
161163
output = json.loads(output)
162-
163-
if getLLM() == 'LLAMA':
164+
165+
if get_llm_model_name() == MODEL_NAME_LLAMA:
164166

165167
output_author = get_data_first_block(clean_labels(item.get('text')), 'author', user_id)
166168

@@ -283,7 +285,7 @@ def get_labels(title, user_id):
283285

284286
num_refs = [item["num_ref"] for item in obj_reference]
285287

286-
if getLLM() == 'LLAMA':
288+
if get_llm_model_name() == 'LLAMA':
287289
for obj_ref in obj_reference:
288290
obj = process_reference(obj_ref['num_ref'], obj_ref['obj'], user_id)
289291
stream_data_back.append(obj)
@@ -297,7 +299,7 @@ def get_labels(title, user_id):
297299
text_references = "\n".join([item["text"] for item in chunk]).replace('<italic>', '').replace('</italic>', '')
298300
prompt_reference = create_prompt_reference(text_references)
299301

300-
result = first_block.run(prompt_reference)
302+
result = llm_first_block.run(prompt_reference)
301303

302304
match = re.search(r'\[.*\]', result, re.DOTALL)
303305
if match:

0 commit comments

Comments
 (0)