mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 10:35:01 +00:00
feat(functions): allow parallel calls with mixed/no grammars (#2432)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
2bbc52fcc8
commit
669cd06dd9
3 changed files with 134 additions and 55 deletions
|
@ -215,5 +215,48 @@ Some text after the JSON
|
|||
Expect(results[0].Name).To(Equal("\"add\""))
|
||||
Expect(results[0].Arguments).To(Equal(`{"x":5,"y":"v\"value\"","z":"\"v\""}`))
|
||||
})
|
||||
|
||||
It("should detect multiple functions call where the JSONRegexMatch is repeated", func() {
|
||||
input := `
|
||||
Some text before the JSON
|
||||
<tool_call>{"function": "add", "arguments": {"x": 5, "y": 3}}</tool_call>
|
||||
<tool_call>{"function": "subtract", "arguments": {"x": 10, "y": 7}}</tool_call>
|
||||
Some text after the JSON
|
||||
`
|
||||
functionConfig.JSONRegexMatch = []string{`(?s)<tool_call>(.*?)</tool_call>`}
|
||||
|
||||
results := ParseFunctionCall(input, functionConfig)
|
||||
Expect(results).To(HaveLen(2))
|
||||
Expect(results[0].Name).To(Equal("add"))
|
||||
Expect(results[0].Arguments).To(Equal(`{"x":5,"y":3}`))
|
||||
Expect(results[1].Name).To(Equal("subtract"))
|
||||
Expect(results[1].Arguments).To(Equal(`{"x":10,"y":7}`))
|
||||
})
|
||||
})
|
||||
Context("ParseTextContent", func() {
|
||||
It("Can extract notes from the LLM result", func() {
|
||||
input := `
|
||||
Some text before the JSON
|
||||
<sketchpad>
|
||||
roses are red
|
||||
</sketchpad>
|
||||
<tool_call>{"function": "subtract", "arguments": {"x": 10, "y": 7}}</tool_call>
|
||||
Some text after the JSON
|
||||
`
|
||||
functionConfig.CaptureLLMResult = []string{`(?s)<sketchpad>(.*?)</sketchpad>`}
|
||||
results := ParseTextContent(input, functionConfig)
|
||||
Expect(results).To(Equal("roses are red"))
|
||||
})
|
||||
|
||||
It("Defaults to empty if doesn't catch any", func() {
|
||||
input := `
|
||||
Some text before the JSON
|
||||
<tool_call>{"function": "subtract", "arguments": {"x": 10, "y": 7}}</tool_call>
|
||||
Some text after the JSON
|
||||
`
|
||||
functionConfig.CaptureLLMResult = []string{`(?s)<sketchpad>(.*?)</sketchpad>`}
|
||||
results := ParseTextContent(input, functionConfig)
|
||||
Expect(results).To(Equal(""))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue