From b6fd8d043405af2d85fb28cafee924522f62d42e Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Fri, 31 May 2024 02:18:37 +0200 Subject: [PATCH] upgraded function calls --- lollms/functions/bibliography.py | 4 +-- lollms/functions/summary.py | 56 ++++++++++++++++++++++++++++++++ lollms/personality.py | 10 ++++-- 3 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 lollms/functions/summary.py diff --git a/lollms/functions/bibliography.py b/lollms/functions/bibliography.py index 20d32a4..c7a4137 100644 --- a/lollms/functions/bibliography.py +++ b/lollms/functions/bibliography.py @@ -343,8 +343,8 @@ Local PDF: {local_url} # Metadata function def search_and_rank_function(llm, score_threshold:float, client: Optional[Any] = None): return { - "function_name": "arxiv_pdf_search", # The function name in string - "function": partial(arxiv_pdf_search, llm=llm, client=client, score_threshold= score_threshold), # The function to be called with partial to preset client + "function_name": "search_and_rank", # The function name in string + "function": partial(search_and_rank, llm=llm, client=client, score_threshold= score_threshold), # The function to be called with partial to preset client "function_description": "Searches for PDFs on arXiv based on a query, downloads them to a specified directory, rates them, sort them by rating and returns a HTML string containing article details and links, along with a dictionary containing detailed information about each PDF.", # Description of the function "function_parameters": [ # The set of parameters {"name": "search_subject", "type": "str", "description": "The search subject."}, diff --git a/lollms/functions/summary.py b/lollms/functions/summary.py new file mode 100644 index 0000000..a534a5d --- /dev/null +++ b/lollms/functions/summary.py @@ -0,0 +1,56 @@ +# Lollms function call definition file + +# Import necessary libraries +import requests +from pathlib import Path + +# Partial is useful if we need to preset some parameters +from functools import partial + +# It is advised to import typing elements +from typing import List, Optional, Any, Tuple, Dict + +# Import PackageManager if there are potential libraries that need to be installed +from lollms.utilities import PackageManager, find_first_available_file_index, discussion_path_to_url + +# ascii_colors offers advanced console coloring and bug tracing +from ascii_colors import trace_exception + +# Import Client from lollms.client_session +from lollms.client_session import Client + +# Here is an example of how we install a non-installed library using PackageManager +if not PackageManager.check_package_installed("bs4"): + PackageManager.install_package("beautifulsoup4") + +# Now we can import the library +from bs4 import BeautifulSoup + + +from lollms.databases.discussions_database import Discussion + +# Core function to search for PDFs on arXiv and download them to a specified directory +def summerize_discussion(summary_request:str,llm, discussion:Discussion) -> str: + messages = discussion.get_messages() + text = "" + for message in messages: + text += message.content + + + summary = llm.summerize_text( + text, + summary_request, + doc_name="discussion" + ) + return summary + +# Metadata function +def summerize_discussion_function(llm, discussion:Discussion): + return { + "function_name": "summerize_discussion", # The function name in string + "function": partial(summerize_discussion, llm=llm, discussion=discussion), # The function to be called with partial to preset client + "function_description": "Summerizes the discussion while keeping some key information as requested by the summary_request parameter", # Description of the function + "function_parameters": [ # The set of parameters + {"name": "summary_request", "type": "str", "description": "The desired information to recover while summerizing."}, + ] + } \ No newline at end of file diff --git a/lollms/personality.py b/lollms/personality.py index 086c423..4e537a4 100644 --- a/lollms/personality.py +++ b/lollms/personality.py @@ -3313,12 +3313,16 @@ The AI should respond in this format using data from actions_list: Returns: List[Dict[str, Any]]: A list of dictionaries with the function names and parameters to execute. """ + # Upgrade the prompt with information about the function calls. upgraded_prompt = self._upgrade_prompt_with_function_info(prompt, functions) # Generate the initial text based on the upgraded prompt. generated_text = self.fast_gen(upgraded_prompt, max_answer_length, callback=callback) + if self.config.debug: + self.print_prompt("Generrated", generated_text) + # Extract the function calls from the generated text. function_calls = self.extract_function_calls_as_json(generated_text) @@ -3411,9 +3415,9 @@ The AI should respond in this format using data from actions_list: "}", "```", "Only use available functions.", - "You can call multiple functions in one generation.", - "Each function call needs to be in a separate function markdown tag.", - f"Do not add status of the execution as it will be added automatically by the system.{separator_template}" + "If you choose to use a function call, do not write anything else. Just the function call.", + f"Do not add status of the execution as it will be added automatically by the system.", + f"A function call must not be followed by any text{separator_template}" f"{start_header_id_template}Available functions{end_header_id_template}\n"] for function in functions: