mirror of
https://github.com/mudler/LocalAI.git
synced 2024-06-07 19:40:48 +00:00
491e1d752b
* feat(functions): relax mixedgrammars Extend even more the functionalities and when mixed mode is enabled, tolerate also both strings and JSON in the result - in this case we make sure that the JSON can be correctly parsed. This also updates the examples and the gallery model to configure the grammar. The changeset also breaks current function/grammar configuration as it reserves now a stanza in the YAML config. For example: ```yaml function: grammar: # This allows the grammar to also return messages mixed_mode: true # Suffix to add to the grammar # prefix: '<tool_call>\n' # Force parallel calls in the grammar # parallel_calls: true ``` Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactor, add a way to disable mixed json and freestring Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Fix linting issues Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
95 lines
2.8 KiB
YAML
95 lines
2.8 KiB
YAML
---
|
|
name: "hermes-2-pro-mistral"
|
|
|
|
config_file: |
|
|
mmap: true
|
|
stopwords:
|
|
- "<|im_end|>"
|
|
- "<dummy32000>"
|
|
- "</tool_call>"
|
|
- "<|eot_id|>"
|
|
- "<|end_of_text|>"
|
|
function:
|
|
# disable injecting the "answer" tool
|
|
disable_no_action: true
|
|
|
|
grammar:
|
|
# This allows the grammar to also return messages
|
|
mixed_mode: true
|
|
|
|
return_name_in_function_response: true
|
|
# Without grammar uncomment the lines below
|
|
# Warning: this is relying only on the capability of the
|
|
# LLM model to generate the correct function call.
|
|
json_regex_match:
|
|
- "(?s)<tool_call>(.*?)</tool_call>"
|
|
- "(?s)<tool_call>(.*?)"
|
|
replace_llm_results:
|
|
# Drop the scratchpad content from responses
|
|
- key: "(?s)<scratchpad>.*</scratchpad>"
|
|
value: ""
|
|
replace_function_results:
|
|
# Replace everything that is not JSON array or object
|
|
- key: '(?s)^[^{\[]*'
|
|
value: ""
|
|
- key: '(?s)[^}\]]*$'
|
|
value: ""
|
|
- key: "'([^']*?)'"
|
|
value: "_DQUOTE_${1}_DQUOTE_"
|
|
- key: '\\"'
|
|
value: "__TEMP_QUOTE__"
|
|
- key: "\'"
|
|
value: "'"
|
|
- key: "_DQUOTE_"
|
|
value: '"'
|
|
- key: "__TEMP_QUOTE__"
|
|
value: '"'
|
|
# Drop the scratchpad content from responses
|
|
- key: "(?s)<scratchpad>.*</scratchpad>"
|
|
value: ""
|
|
|
|
template:
|
|
chat: |
|
|
{{.Input -}}
|
|
<|im_start|>assistant
|
|
chat_message: |
|
|
<|im_start|>{{if eq .RoleName "assistant"}}assistant{{else if eq .RoleName "system"}}system{{else if eq .RoleName "tool"}}tool{{else if eq .RoleName "user"}}user{{end}}
|
|
{{- if .FunctionCall }}
|
|
<tool_call>
|
|
{{- else if eq .RoleName "tool" }}
|
|
<tool_response>
|
|
{{- end }}
|
|
{{- if .Content}}
|
|
{{.Content }}
|
|
{{- end }}
|
|
{{- if .FunctionCall}}
|
|
{{toJson .FunctionCall}}
|
|
{{- end }}
|
|
{{- if .FunctionCall }}
|
|
</tool_call>
|
|
{{- else if eq .RoleName "tool" }}
|
|
</tool_response>
|
|
{{- end }}<|im_end|>
|
|
completion: |
|
|
{{.Input}}
|
|
function: |-
|
|
<|im_start|>system
|
|
You are a function calling AI model.
|
|
Here are the available tools:
|
|
<tools>
|
|
{{range .Functions}}
|
|
{'type': 'function', 'function': {'name': '{{.Name}}', 'description': '{{.Description}}', 'parameters': {{toJson .Parameters}} }}
|
|
{{end}}
|
|
</tools>
|
|
You should call the tools provided to you sequentially
|
|
Please use <scratchpad> XML tags to record your reasoning and planning before you call the functions as follows:
|
|
<scratchpad>
|
|
{step-by-step reasoning and plan in bullet points}
|
|
</scratchpad>
|
|
For each function call return a json object with function name and arguments within <tool_call> XML tags as follows:
|
|
<tool_call>
|
|
{"arguments": <args-dict>, "name": <function-name>}
|
|
</tool_call><|im_end|>
|
|
{{.Input -}}
|
|
<|im_start|>assistant
|