mirror of
https://github.com/ParisNeo/lollms.git
synced 2025-04-13 22:02:56 +00:00
enhanced
This commit is contained in:
parent
e769ffc145
commit
27538a5f3e
@ -1399,7 +1399,7 @@ Answer directly with the reformulation of the last prompt.
|
||||
|
||||
# Extract default values from fc_dict's static_parameters
|
||||
for param in fc_dict['static_parameters']:
|
||||
static_parameters[param['name']] = param['default']
|
||||
static_parameters[param['name']] = param.get('default',"")
|
||||
|
||||
# Create parent directories if they don't exist
|
||||
config_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
@ -1431,6 +1431,7 @@ Answer directly with the reformulation of the last prompt.
|
||||
fc_dict["class"] = class_(self, client, static_parameters)
|
||||
function_calls.append(fc_dict)
|
||||
except Exception as ex:
|
||||
self.error("Couldn't add function call to context")
|
||||
trace_exception(ex)
|
||||
# Calculate the total number of tokens between conditionning, documentation, and knowledge
|
||||
total_tokens = n_cond_tk + n_isearch_tk + n_doc_tk + n_user_description_tk + n_positive_boost + n_negative_boost + n_fun_mode + n_think_first_mode
|
||||
|
@ -16,24 +16,19 @@ class FunctionCall:
|
||||
self.client = client
|
||||
self.static_parameters = static_parameters
|
||||
|
||||
def execute(self, *args, **kwargs):
|
||||
def execute(self, context, *args, **kwargs):
|
||||
"""
|
||||
Execute the function based on its type.
|
||||
This method should be overridden by subclasses.
|
||||
"""
|
||||
raise NotImplementedError("Subclasses must implement the execute method.")
|
||||
|
||||
def update_context(self, context, contructed_context:str):
|
||||
def update_context(self, context, constructed_context:List[str]):
|
||||
"""
|
||||
Update the context if needed.
|
||||
This method should be overridden by subclasses.
|
||||
"""
|
||||
if self.function_type == FunctionType.CONTEXT_UPDATE:
|
||||
raise NotImplementedError("Subclasses must implement the update_context method for CONTEXT_UPDATE functions.")
|
||||
elif self.function_type == FunctionType.AI_FIRST_CALL:
|
||||
raise NotImplementedError("Subclasses must implement the update_context method for AI_FIRST_CALL functions.")
|
||||
elif self.function_type == FunctionType.POST_GENERATION:
|
||||
raise NotImplementedError("Subclasses must implement the update_context method for POST_GENERATION functions.")
|
||||
return constructed_context
|
||||
|
||||
def process_output(self, context, llm_output:str):
|
||||
if self.function_type == FunctionType.CONTEXT_UPDATE:
|
||||
|
@ -92,6 +92,7 @@ class LollmsContextDetails:
|
||||
self.ctx_size = ctx_size
|
||||
self.max_n_predict = max_n_predict
|
||||
self.model = model
|
||||
self.ai_output = ""
|
||||
|
||||
|
||||
def transform_function_to_text(self, template, func):
|
||||
@ -111,7 +112,7 @@ class LollmsContextDetails:
|
||||
function_texts.append(function_text.strip())
|
||||
return "\n\n".join(function_texts)
|
||||
|
||||
def build_prompt(self, template: LollmsLLMTemplate, custom_entries: str = "", suppress: List[str] = []) -> str:
|
||||
def build_prompt(self, template: LollmsLLMTemplate, custom_entries: str = "", suppress: List[str] = [], ignore_function_calls:bool=False) -> str:
|
||||
"""
|
||||
Builds a prompt from the context details using the integrated template system.
|
||||
|
||||
@ -147,7 +148,7 @@ class LollmsContextDetails:
|
||||
append_context("conditionning")
|
||||
append_context("documentation", template.system_custom_header("documentation"))
|
||||
append_context("internet_search_results", template.system_custom_header("Internet search results"))
|
||||
append_context("user_description", template.system_custom_header("user_description"))
|
||||
append_context("user_description")
|
||||
append_context("positive_boost", template.system_custom_header("positive_boost"))
|
||||
append_context("negative_boost", template.system_custom_header("negative_boost"))
|
||||
append_context("current_language", template.system_custom_header("current_language"))
|
||||
@ -156,35 +157,36 @@ class LollmsContextDetails:
|
||||
|
||||
append_context("extra")
|
||||
found_classic_function = False
|
||||
|
||||
for function_call in self.function_calls:
|
||||
fc:FunctionCall = function_call["class"]
|
||||
if fc.function_type == FunctionType.CONTEXT_UPDATE:
|
||||
full_context = fc.update_context(self, full_context)
|
||||
elif fc.function_type == FunctionType.CLASSIC:
|
||||
if not found_classic_function:
|
||||
found_classic_function = True
|
||||
full_context.append(self.transform_function_to_text(template,function_call))
|
||||
|
||||
if found_classic_function:
|
||||
full_context.append(
|
||||
template.system_custom_header("Function Calls")+"\n" + "\n".join([
|
||||
"You have access to functions presented to you in the available functions listed above.",
|
||||
"If you need to call a function, use this exact syntax:",
|
||||
"```function",
|
||||
"{",
|
||||
' "function_name": "name_of_the_function_to_call",',
|
||||
' "function_parameters": {',
|
||||
' "parameter1": value1,',
|
||||
' "parameter2": value2',
|
||||
" }",
|
||||
"}",
|
||||
"```",
|
||||
"Important Notes:",
|
||||
"- **Always** enclose the function call in a `function` markdown code block.",
|
||||
"- Make sure the content of the function markdown code block is a valid json.",
|
||||
])
|
||||
)
|
||||
if not ignore_function_calls:
|
||||
for function_call in self.function_calls:
|
||||
fc:FunctionCall = function_call["class"]
|
||||
if fc.function_type == FunctionType.CONTEXT_UPDATE:
|
||||
full_context = fc.update_context(self, full_context)
|
||||
elif fc.function_type == FunctionType.CLASSIC:
|
||||
if not found_classic_function:
|
||||
found_classic_function = True
|
||||
full_context.append(self.transform_function_to_text(template,function_call))
|
||||
full_context = fc.update_context(self, full_context)
|
||||
|
||||
if found_classic_function:
|
||||
full_context.append(
|
||||
template.system_custom_header("Function Calls")+"\n" + "\n".join([
|
||||
"You have access to functions presented to you in the available functions listed above.",
|
||||
"If you need to call a function, use this exact syntax:",
|
||||
"```function",
|
||||
"{",
|
||||
' "function_name": "name_of_the_function_to_call",',
|
||||
' "function_parameters": {',
|
||||
' "parameter1": value1,',
|
||||
' "parameter2": value2',
|
||||
" }",
|
||||
"}",
|
||||
"```",
|
||||
"Important Notes:",
|
||||
"- **Always** enclose the function call in a `function` markdown code block.",
|
||||
"- Make sure the content of the function markdown code block is a valid json.",
|
||||
])
|
||||
)
|
||||
|
||||
append_context("discussion_messages", template.system_custom_header("Discussion")+"\n")
|
||||
# Add custom entries if provided
|
||||
|
Loading…
x
Reference in New Issue
Block a user