Files
hermes-agent/__pycache__/model_tools.cpython-310.pyc

96 lines
7.0 KiB
Plaintext
Raw Normal View History

2025-07-22 18:32:44 -07:00
o
C$<24>h<EFBFBD>)<00> @sJdZddlZddlmZmZmZddlmZmZm Z m
Z
deee effdd<07>Z deee effdd <09>Z d
e d ee efde fd d <0A>Zd
e d ee efde fdd<0F>Zdee ee efffdd<11>Zdee effdd<13>Zedk<02>r# ed<15>ed<16>e<12>Zed<17>e<15><16>D]\ZZer<>dndZede<19>de<17>der<>dnd<1E><00><06>q<>e <0A>Zedee<1A><01>d <20><03>eD]&Zed!d"Zed!d#Zed$e<1D>dedd%<25><00>ee<1E>d%kr<>d&nd'<27><00><05>q<>e<10>Zed(<28>e<1F><16>D],\Z Z!e!d)r<>dndZede<19>de <20>de!d#<00><00><06>e!d)<00>sed*d+<2B>"e!d,<00><01><00><02>q<>ed-<2D>ed.<2E>ed/<2F>ed0<64>dSdS)1aL
Model Tools Module
This module constructs tool schemas and handlers for AI model API calls.
It imports tools from various toolset modules and provides a unified interface
for defining tools and executing function calls.
Currently supports:
- Web tools (search, extract, crawl) from web_tools.py
Usage:
from model_tools import get_tool_definitions, handle_function_call
# Get tool definitions for model API
tools = get_tool_definitions()
# Handle function calls from model
result = handle_function_call("web_search_tool", {"query": "Python", "limit": 3})
<EFBFBD>N)<03>Dict<63>Any<6E>List)<04>web_search_tool<6F>web_extract_tool<6F>web_crawl_tool<6F>check_tavily_api_key<65>returnc Cs<>ddddddd<07>dd d
d d d <0A>d<0E>dgd<10>d<11>d<12>dddddddidd
d<18>dddgdd<1C>d<1D>dgd<10>d<11>d<12>ddd ddd!d<07>dd"d<07>dd#d$gd%d#d&<26>d'<27>d(gd<10>d<11>d<12>gS))z<>
Get tool definitions for web tools in OpenAI's expected format.
Returns:
List[Dict]: List of web tool definitions compatible with OpenAI API
<20>functionrz<>Search the web for information on any topic. Returns relevant results with titles, URLs, content snippets, and answers. Uses advanced search depth for comprehensive results.<2E>object<63>stringz&The search query to look up on the web)<02>type<70> description<6F>integerz9Maximum number of results to return (default: 5, max: 10)<29><00><00>
)r r<00>default<6C>minimum<75>maximum)<02>query<72>limitr)r <00>
properties<EFBFBD>required)<03>namer<00>
parameters)r r
rz<>Extract and read the full content from specific web page URLs. Useful for getting detailed information from webpages found through search.<2E>arrayr z:List of URLs to extract content from (max 5 URLs per call))r <00>itemsr<00>maxItems<6D>markdown<77>htmlz6Desired output format for extracted content (optional))r <00>enumr)<02>urls<6C>formatr"rz<>Crawl a website with specific instructions to find and extract targeted content. Uses AI to intelligently navigate and extract relevant information from across the site.z7The base URL to crawl (can include or exclude https://)z<>Specific instructions for what to crawl/extract using AI intelligence (e.g., 'Find pricing information', 'Get documentation pages', 'Extract contact details')<29>basic<69>advancedzbDepth of extraction - 'basic' for surface content, 'advanced' for deeper analysis (default: basic))r r!rr)<03>url<72> instructions<6E>depthr&<00>r)r)r)<00>2/home/teknium/Projects/Hermes-Agent/model_tools.py<70>get_web_tool_definitionssr <04><04><04> <04><04><04><04><04><04> <04><04><04><04><04><04><04><04><04><04><04>r+cCsg}|<00>t<01><00>|S)a8
Get all available tool definitions for model API calls.
This function aggregates tool definitions from all available toolsets.
Currently includes web tools, but can be extended to include other toolsets.
Returns:
List[Dict]: Complete list of all available tool definitions
)<02>extendr+)<01>toolsr)r)r*<00>get_tool_definitionsss
r.<00> function_name<6D> function_argsc Cs<>|dkr|<01>dd<03>}|<01>dd<05>}tdtd|<03><02>}t||<03>S|dkr>|<01>d g<00>}t|t<05>r2|d
d<05>ng}|<01>d <0B>}t||<05>S|d krY|<01>d d<03>}|<01>d<0E>}|<01>dd<10>}t|||<08>St<08> dd|<00><00>i<01>S)z<>
Handle function calls for web tools.
Args:
function_name (str): Name of the web function to call
function_args (Dict): Arguments for the function
Returns:
str: Function result as JSON string
rr<00>rrrrrr"Nr#rr&r'r(r$<00>errorzUnknown web function: )
<EFBFBD>get<65>max<61>minr<00>
isinstance<EFBFBD>listrr<00>json<6F>dumps) r/r0rrr"r#r&r'r(r)r)r*<00>handle_web_function_call<6C>s   
 

 
  r:c
Cs<>z|dvr t||<01>WSd|<00><00>}td|<02><00><02>t<02>d|i<01>WStyH}zd|<00>dt|<03><01><00>}td|<02><00><02>t<02>d|i<01>WYd}~Sd}~ww)aB
Main function call dispatcher that routes calls to appropriate toolsets.
This function determines which toolset a function belongs to and dispatches
the call to the appropriate handler. This makes it easy to add new toolsets
without changing the main calling interface.
Args:
function_name (str): Name of the function to call
function_args (Dict): Arguments for the function
Returns:
str: Function result as JSON string
Raises:
None: Returns error as JSON string instead of raising exceptions
<20>rrrzUnknown function: u❌ r2zError executing <20>: N)r:<00>printr8r9<00> Exception<6F>str)r/r0<00> error_msg<73>er)r)r*<00>handle_function_call<6C>s 
<08><02>rBcCsdt<00>gd<02>ddgd<05>i}|S)z<>
Get information about all available toolsets and their status.
Returns:
Dict: Information about each toolset including availability and tools
<20> web_toolsr;z:Web search, content extraction, and website crawling toolsz#TAVILY_API_KEY environment variable)<04> availabler-r<00> requirements<74>r)<01>toolsetsr)r)r*<00>get_available_toolsets<74>s<04><04>
rHcCs
dt<00>iS)z<>
Check if all requirements for available toolsets are met.
Returns:
Dict: Status of each toolset's requirements
rCrFr)r)r)r*<00>check_toolset_requirements<74>s<04>rI<00>__main__u🛠️ Model Tools Modulez(========================================u📋 Toolset Requirements:u✅u❌z <20> r<<00> AvailablezMissing requirementsu
🔧 Available Tools (z total):r
rru 📌 <20>Pz...r1u
📦 Toolset Information:rDz Requirements: z, rEu
💡 Usage Example:zD from model_tools import get_tool_definitions, handle_function_callz tools = get_tool_definitions()zG result = handle_function_call('web_search_tool', {'query': 'Python'}))#<23>__doc__r8<00>typingrrrrCrrrrr?r+r.r:rBrH<00>boolrI<00>__name__r=rEr<00>toolsetrD<00>statusr-<00>len<65>tool<6F> func_name<6D>descrGr<00>info<66>joinr)r)r)r*<00><module>sLV#(
 $  2
<02> <04>