Skip to content

Commit 48608f3

Browse files
committed
AI Search refinements
1 parent 7c43e3e commit 48608f3

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/qualcoder/ai_llm.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,9 @@ def generate_code_descriptions(self, code_name, code_memo='') -> list:
497497
HumanMessage(
498498
content=(f'We are searching for empirical data that fits a code named "{code_name}" '
499499
f'with the following code memo: "{extract_ai_memo(code_memo)}". \n'
500-
'Your task: Give back a list of 10 reformulated variants of the code name, using '
501-
'synonyms or directly related concepts. Try to give a variety of diverse reformulations. '
502-
'Use simple language.'
500+
'Your task: Give back a list of up to 10 reformulated variants of the code, using '
501+
'synonyms or directly related concepts. Also consider the memo, if available. '
502+
'Try to give a variety of diverse reformulations. Use simple language.'
503503
f'Always answer in the following language: "{self.get_curr_language()}". Do not use numbers or bullet points. '
504504
'Do not explain anything or repeat the code name, just give back the list of variants. '
505505
'Return the list as a valid JSON object in the following form:\n'
@@ -517,7 +517,8 @@ def generate_code_descriptions(self, code_name, code_memo='') -> list:
517517

518518
res = self.large_llm.invoke(code_descriptions_prompt, response_format={"type": "json_object"}, config=config)
519519
logger.debug(str(res.content))
520-
code_descriptions = json_repair.loads(str(res.content))['descriptions']
520+
code_descriptions = list(json_repair.loads(str(res.content))['descriptions'])
521+
code_descriptions.insert(0, code_name) # insert the original as well
521522
return code_descriptions
522523

523524
def retrieve_similar_data(self, result_callback, code_name, code_memo='', doc_ids=None):
@@ -637,13 +638,13 @@ def _search_analyze_chunk(self, chunk, code_name, code_memo, search_prompt: Prom
637638
'Summarize your reasoning briefly in the field "interpretation" of the result. '
638639
f'In this particular field, always answer in the language "{self.get_curr_language()}".\n'
639640
'If you came to the conclusion that the chunk of data '
640-
'is not related to the code, give back \'false\' in the field "related", otherwise \'true\'.\n'
641-
'If the previous step resulted in \'true\', identify a quote from the chunk of empirical data that contains the part which is '
641+
'is not related to the code, give back \'False\' in the field "related", otherwise \'True\'.\n'
642+
'If the previous step resulted in \'True\', identify a quote from the chunk of empirical data that contains the part which is '
642643
'relevant for the analysis of the given code. Include enough context so that the quote is comprehensable. '
643644
'Give back this quote in the field "quote" exactly like in the original, '
644645
'including errors. Do not leave anything out, do not translate the text or change it in any other way. '
645646
'If you cannot identify a particular quote, return the whole chunk of empirical data in the field "quote".\n'
646-
'If the previous step resulted in \'false\', return an empty quote ("") in the field "quote".\n'
647+
'If the previous step resulted in \'False\', return an empty quote ("") in the field "quote".\n'
647648
f'Make sure to return nothing else but a valid JSON object in the following form: \n{json_result}.'
648649
f'\n\nThe chunk of empirical data for you to analyze: \n"{chunk.page_content}"')
649650
)
@@ -659,10 +660,9 @@ def _search_analyze_chunk(self, chunk, code_name, code_memo, search_prompt: Prom
659660
res_json = json_repair.loads(str(res.content))
660661

661662
# analyse and format the answer
662-
if 'related' in res_json and res_json['related'] is True and \
663+
if 'related' in res_json and res_json['related'] in [True, 'True', 'true'] and \
663664
'quote' in res_json and res_json['quote'] != '': # found something
664665
# Adjust quote_start
665-
i = 0 # TODO i not used
666666
doc = {}
667667
doc['metadata'] = chunk.metadata
668668

0 commit comments

Comments
 (0)