This commit is contained in:
Saifeddine ALOUI 2024-12-15 17:28:16 +01:00
parent 89eb98ff98
commit ef1286273b
2 changed files with 30 additions and 12 deletions

View File

@ -791,11 +791,13 @@ The generated code must be placed inside the html code tag.
repeat_penalty=None, repeat_penalty=None,
repeat_last_n=None, repeat_last_n=None,
callback=None, callback=None,
debug=False, debug=None,
return_full_generated_code=False, return_full_generated_code=False,
accept_all_if_no_code_tags_is_present=False, accept_all_if_no_code_tags_is_present=False,
max_continues=5 max_continues=5
): ):
if debug is None:
debug = self.config.debug
response_full = "" response_full = ""
full_prompt = f"""{self.system_full_header}Act as a code generation assistant who answers with a single code tag content. full_prompt = f"""{self.system_full_header}Act as a code generation assistant who answers with a single code tag content.
{self.system_custom_header("user")} {self.system_custom_header("user")}
@ -809,13 +811,15 @@ Make sure only a single code tag is generated at each dialogue turn.
```{language} ```{language}
{template} {template}
``` ```
Don't forget to close the markdown code tag {"Make sure you fill all fields and tyo use the exact same keys as the template." if language in ["json","yaml","xml"] else ""}
Don't forget to close the markdown code tag.
""" """
elif code_tag_format=="html": elif code_tag_format=="html":
full_prompt +=f"""You must answer with the code placed inside the html code tag like this: full_prompt +=f"""You must answer with the code placed inside the html code tag like this:
<code language="{language}"> <code language="{language}">
{template} {template}
</code> </code>
{"Make sure you fill all fields and tyo use the exact same keys as the template." if language in ["json","yaml","xml"] else ""}
Don't forget to close the html code tag Don't forget to close the html code tag
""" """
@ -891,23 +895,31 @@ Make sure only a single code tag is generated at each dialogue turn.
```json ```json
{template} {template}
``` ```
Don't forget to close the markdown code tag Make sure you provide exactly the same fields as the template.
Don't forget to close the markdown code tag.
""" """
elif code_tag_format=="html": elif code_tag_format=="html":
full_prompt +=f"""You must answer with the code placed inside the html code tag like this: full_prompt +=f"""You must answer with the code placed inside the html code tag like this:
<code language="json"> <code language="json">
{template} {template}
</code> </code>
Don't forget to close the html code tag Make sure you provide exactly the same fields as the template.
Don't forget to close the html code tag.
""" """
full_prompt += self.ai_custom_header("assistant") full_prompt += self.ai_custom_header("assistant")
if debug:
ASCIIColors.yellow("Full text generation code:")
ASCIIColors.yellow(full_prompt)
if len(self.image_files)>0: if len(self.image_files)>0:
response = self.generate_with_images(full_prompt, self.image_files, max_size, temperature, top_k, top_p, repeat_penalty, repeat_last_n, callback, debug=debug) response = self.generate_with_images(full_prompt, self.image_files, max_size, temperature, top_k, top_p, repeat_penalty, repeat_last_n, callback, debug=debug)
elif len(images)>0: elif len(images)>0:
response = self.generate_with_images(full_prompt, images, max_size, temperature, top_k, top_p, repeat_penalty, repeat_last_n, callback, debug=debug) response = self.generate_with_images(full_prompt, images, max_size, temperature, top_k, top_p, repeat_penalty, repeat_last_n, callback, debug=debug)
else: else:
response = self.generate(full_prompt, max_size, temperature, top_k, top_p, repeat_penalty, repeat_last_n, callback, debug=debug) response = self.generate(full_prompt, max_size, temperature, top_k, top_p, repeat_penalty, repeat_last_n, callback, debug=debug)
if debug:
ASCIIColors.green("Response:")
ASCIIColors.green(response)
response_full += response response_full += response
codes = self.extract_code_blocks(response) codes = self.extract_code_blocks(response)
if len(codes)==0 and accept_all_if_no_code_tags_is_present: if len(codes)==0 and accept_all_if_no_code_tags_is_present:
@ -3146,7 +3158,7 @@ class APScript(StateMachine):
repeat_penalty=None, repeat_penalty=None,
repeat_last_n=None, repeat_last_n=None,
callback=None, callback=None,
debug=False, debug=None,
return_full_generated_code=False, return_full_generated_code=False,
accept_all_if_no_code_tags_is_present=False, accept_all_if_no_code_tags_is_present=False,
max_continues=5 max_continues=5
@ -3262,11 +3274,10 @@ class APScript(StateMachine):
# Generate each field individually # Generate each field individually
for field, field_info in template.items(): for field, field_info in template.items():
if "prompt" in field_info: if "prompt" in field_info:
field_prompt = field_info["prompt"].format(main_prompt=prompt) field_prompt = self.system_custom_header("prompt")+prompt+"\n"+self.system_custom_header("field to generate")+field+"\n"
template = f"""{{ template = f"""{{
"{field}": [The value of {field}] "{field}": [{field_info["prompt"]}]
}} }}"""
"""
code = self.generate_code(field_prompt, self.personality.image_files, template, "json", callback=self.sink, accept_all_if_no_code_tags_is_present=True ) code = self.generate_code(field_prompt, self.personality.image_files, template, "json", callback=self.sink, accept_all_if_no_code_tags_is_present=True )
# Clean up the response # Clean up the response
cleaned_response = json.loads(code)[field] cleaned_response = json.loads(code)[field]

View File

@ -207,11 +207,18 @@ def find_rag_database_by_name(entries: List[str], name: str) -> Optional[str]:
Returns: Returns:
Optional[str]: The entry if found, otherwise None. Optional[str]: The entry if found, otherwise None.
""" """
ASCIIColors.green("find_rag_database_by_name:")
for i, entry in enumerate(entries): for i, entry in enumerate(entries):
ASCIIColors.green(entry)
parts = entry.split('::') parts = entry.split('::')
if len(parts)>1:
entry_name, entry_path = parts[0], parts[1] entry_name, entry_path = parts[0], parts[1]
if entry_name == name: if entry_name == name:
return i, entry_path return i, entry_path
else:
entry_name = entry
if entry_name == name:
return i, entry_path
return None return None
# ----------------------------------- Personal files ----------------------------------------- # ----------------------------------- Personal files -----------------------------------------
class SelectDatabase(BaseModel): class SelectDatabase(BaseModel):