upgraded function calls

This commit is contained in:
Saifeddine ALOUI 2024-05-31 02:18:37 +02:00
parent 8b833fb615
commit b6fd8d0434
3 changed files with 65 additions and 5 deletions

View File

@ -343,8 +343,8 @@ Local PDF: {local_url}
# Metadata function # Metadata function
def search_and_rank_function(llm, score_threshold:float, client: Optional[Any] = None): def search_and_rank_function(llm, score_threshold:float, client: Optional[Any] = None):
return { return {
"function_name": "arxiv_pdf_search", # The function name in string "function_name": "search_and_rank", # 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": 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_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 "function_parameters": [ # The set of parameters
{"name": "search_subject", "type": "str", "description": "The search subject."}, {"name": "search_subject", "type": "str", "description": "The search subject."},

View File

@ -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."},
]
}

View File

@ -3313,12 +3313,16 @@ The AI should respond in this format using data from actions_list:
Returns: Returns:
List[Dict[str, Any]]: A list of dictionaries with the function names and parameters to execute. 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. # Upgrade the prompt with information about the function calls.
upgraded_prompt = self._upgrade_prompt_with_function_info(prompt, functions) upgraded_prompt = self._upgrade_prompt_with_function_info(prompt, functions)
# Generate the initial text based on the upgraded prompt. # Generate the initial text based on the upgraded prompt.
generated_text = self.fast_gen(upgraded_prompt, max_answer_length, callback=callback) 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. # Extract the function calls from the generated text.
function_calls = self.extract_function_calls_as_json(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.", "Only use available functions.",
"You can call multiple functions in one generation.", "If you choose to use a function call, do not write anything else. Just the function call.",
"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.",
f"Do not add status of the execution as it will be added automatically by the system.{separator_template}" 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"] f"{start_header_id_template}Available functions{end_header_id_template}\n"]
for function in functions: for function in functions: