Spaces:
Running
Running
File size: 1,255 Bytes
372d102 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import re
from function_support import _function
def extract_links(text):
url_pattern = r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
urls = re.findall(url_pattern, text)
return urls
def allocate(messages,model,functs):
if "gemini" not in model:
for msg in messages:
if isinstance(msg["content"],list):
msg["content"]=msg["content"][0]["text"]
for msg in messages:
if "tool" in msg["role"]:
msg["role"]="user"
msg["content"]=f"Tool {msg['name']} returned response: {msg['content']}. Now you must output the next tool Call or respond to user in natural language after the task has been completed. "
del msg['name']
del msg["tool_call_id"]
if "tool_calls" in msg:
add=""
for tools in msg["tool_calls"]:
add=f"""
```json
[
{{
"tool":"{tools["function"]["name"]}",
"tool_input":{tools["function"]["arguments"]}
}}
]
```"""
msg["content"]=add
del msg["tool_calls"]
if functs !=None:
function_call=_function(tools=functs)
messages.insert(1,{"role": "system", "content": function_call})
|