mirror of
https://github.com/open-webui/open-webui
synced 2025-02-22 13:18:25 +00:00
refac: tool calls
This commit is contained in:
parent
28cf616147
commit
642a093d02
@ -1283,7 +1283,28 @@ TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE = PersistentConfig(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE = """Available Tools: {{TOOLS}}\nReturn an empty string if no tools match the query. If a function tool matches, construct and return a JSON object in the format {\"name\": \"functionName\", \"parameters\": {\"requiredFunctionParamKey\": \"requiredFunctionParamValue\"}} using the appropriate tool and its parameters. Only return the object and limit the response to the JSON object without additional text."""
|
DEFAULT_TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE = """Available Tools: {{TOOLS}}
|
||||||
|
|
||||||
|
Your task is to choose and return the correct tool(s) from the list of available tools based on the query. Follow these guidelines:
|
||||||
|
|
||||||
|
- Return only the JSON object, without any additional text or explanation.
|
||||||
|
|
||||||
|
- If no tools match the query, return an empty array:
|
||||||
|
{
|
||||||
|
"tool_calls": []
|
||||||
|
}
|
||||||
|
|
||||||
|
- If one or more tools match the query, construct a JSON response containing a "tool_calls" array with objects that include:
|
||||||
|
- "name": The tool's name.
|
||||||
|
- "parameters": A dictionary of required parameters and their corresponding values.
|
||||||
|
|
||||||
|
The format for the JSON response is strictly:
|
||||||
|
{
|
||||||
|
"tool_calls": [
|
||||||
|
{"name": "toolName1", "parameters": {"key1": "value1"}},
|
||||||
|
{"name": "toolName2", "parameters": {"key2": "value2"}}
|
||||||
|
]
|
||||||
|
}"""
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_EMOJI_GENERATION_PROMPT_TEMPLATE = """Your task is to reflect the speaker's likely facial expression through a fitting emoji. Interpret emotions from the message and reflect their facial expression using fitting, diverse emojis (e.g., 😊, 😢, 😡, 😱).
|
DEFAULT_EMOJI_GENERATION_PROMPT_TEMPLATE = """Your task is to reflect the speaker's likely facial expression through a fitting emoji. Interpret emotions from the message and reflect their facial expression using fitting, diverse emojis (e.g., 😊, 😢, 😡, 😱).
|
||||||
|
@ -270,11 +270,14 @@ async def chat_completion_tools_handler(
|
|||||||
|
|
||||||
result = json.loads(content)
|
result = json.loads(content)
|
||||||
|
|
||||||
tool_function_name = result.get("name", None)
|
async def tool_call_handler(tool_call):
|
||||||
|
log.debug(f"{tool_call=}")
|
||||||
|
|
||||||
|
tool_function_name = tool_call.get("name", None)
|
||||||
if tool_function_name not in tools:
|
if tool_function_name not in tools:
|
||||||
return body, {}
|
return body, {}
|
||||||
|
|
||||||
tool_function_params = result.get("parameters", {})
|
tool_function_params = tool_call.get("parameters", {})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
required_params = (
|
required_params = (
|
||||||
@ -325,6 +328,13 @@ async def chat_completion_tools_handler(
|
|||||||
if tools[tool_function_name]["file_handler"]:
|
if tools[tool_function_name]["file_handler"]:
|
||||||
skip_files = True
|
skip_files = True
|
||||||
|
|
||||||
|
# check if "tool_calls" in result
|
||||||
|
if result.get("tool_calls"):
|
||||||
|
for tool_call in result.get("tool_calls"):
|
||||||
|
await tool_call_handler(tool_call)
|
||||||
|
else:
|
||||||
|
await tool_call_handler(result)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(f"Error: {e}")
|
log.exception(f"Error: {e}")
|
||||||
content = None
|
content = None
|
||||||
|
@ -31,7 +31,8 @@
|
|||||||
ENABLE_TAGS_GENERATION: true,
|
ENABLE_TAGS_GENERATION: true,
|
||||||
ENABLE_SEARCH_QUERY_GENERATION: true,
|
ENABLE_SEARCH_QUERY_GENERATION: true,
|
||||||
ENABLE_RETRIEVAL_QUERY_GENERATION: true,
|
ENABLE_RETRIEVAL_QUERY_GENERATION: true,
|
||||||
QUERY_GENERATION_PROMPT_TEMPLATE: ''
|
QUERY_GENERATION_PROMPT_TEMPLATE: '',
|
||||||
|
TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
let promptSuggestions = [];
|
let promptSuggestions = [];
|
||||||
@ -251,6 +252,20 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-3">
|
||||||
|
<div class=" mb-2.5 text-xs font-medium">{$i18n.t('Tools Function Calling Prompt')}</div>
|
||||||
|
|
||||||
|
<Tooltip
|
||||||
|
content={$i18n.t('Leave empty to use the default prompt, or enter a custom prompt')}
|
||||||
|
placement="top-start"
|
||||||
|
>
|
||||||
|
<Textarea
|
||||||
|
bind:value={taskConfig.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE}
|
||||||
|
placeholder={$i18n.t('Leave empty to use the default prompt, or enter a custom prompt')}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
|
||||||
<hr class=" border-gray-50 dark:border-gray-850 my-3" />
|
<hr class=" border-gray-50 dark:border-gray-850 my-3" />
|
||||||
|
|
||||||
<div class=" space-y-3 {banners.length > 0 ? ' mb-3' : ''}">
|
<div class=" space-y-3 {banners.length > 0 ? ' mb-3' : ''}">
|
||||||
|
@ -17,12 +17,12 @@ const config = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
vitePlugin: {
|
vitePlugin: {
|
||||||
inspector: {
|
// inspector: {
|
||||||
toggleKeyCombo: 'meta-shift', // Key combination to open the inspector
|
// toggleKeyCombo: 'meta-shift', // Key combination to open the inspector
|
||||||
holdMode: false, // Enable or disable hold mode
|
// holdMode: false, // Enable or disable hold mode
|
||||||
showToggleButton: 'always', // Show toggle button ('always', 'active', 'never')
|
// showToggleButton: 'always', // Show toggle button ('always', 'active', 'never')
|
||||||
toggleButtonPos: 'bottom-right' // Position of the toggle button
|
// toggleButtonPos: 'bottom-right' // Position of the toggle button
|
||||||
}
|
// }
|
||||||
},
|
},
|
||||||
onwarn: (warning, handler) => {
|
onwarn: (warning, handler) => {
|
||||||
const { code } = warning;
|
const { code } = warning;
|
||||||
|
Loading…
Reference in New Issue
Block a user