mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 10:35:01 +00:00
feat(functions): allow to set JSON matcher (#2319)
Signed-off-by: mudler <mudler@localai.io>
This commit is contained in:
parent
c4186f13c3
commit
84e2407afa
3 changed files with 105 additions and 33 deletions
|
@ -87,7 +87,7 @@ var _ = Describe("LocalAI function parse tests", func() {
|
|||
It("should parse the function name and arguments correctly with the name key", func() {
|
||||
input := `{"name": "add", "arguments": {"x": 5, "y": 3}}`
|
||||
functionConfig.ParallelCalls = false
|
||||
functionConfig.NoGrammar = false
|
||||
functionConfig.NoGrammar = true
|
||||
functionConfig.ResponseRegex = ""
|
||||
functionConfig.FunctionName = true
|
||||
|
||||
|
@ -100,7 +100,40 @@ var _ = Describe("LocalAI function parse tests", func() {
|
|||
It("should parse the function name and arguments correctly with the function key", func() {
|
||||
input := `{"function": "add", "arguments": {"x": 5, "y": 3}}`
|
||||
functionConfig.ParallelCalls = false
|
||||
functionConfig.NoGrammar = false
|
||||
functionConfig.NoGrammar = true
|
||||
functionConfig.ResponseRegex = ""
|
||||
functionConfig.FunctionName = false
|
||||
|
||||
results := ParseFunctionCall(input, functionConfig)
|
||||
Expect(results).To(HaveLen(1))
|
||||
Expect(results[0].Name).To(Equal("add"))
|
||||
Expect(results[0].Arguments).To(Equal(`{"x":5,"y":3}`))
|
||||
})
|
||||
|
||||
It("Should parse the result by matching the JSONRegexMatch", func() {
|
||||
input := `
|
||||
<tool_call>
|
||||
{"function": "add", "arguments": {"x": 5, "y": 3}}
|
||||
</tool_call>`
|
||||
functionConfig.ParallelCalls = false
|
||||
functionConfig.NoGrammar = true
|
||||
functionConfig.JSONRegexMatch = `(?s)<tool_call>(.*?)</tool_call>`
|
||||
functionConfig.ResponseRegex = ""
|
||||
functionConfig.FunctionName = false
|
||||
|
||||
results := ParseFunctionCall(input, functionConfig)
|
||||
Expect(results).To(HaveLen(1))
|
||||
Expect(results[0].Name).To(Equal("add"))
|
||||
Expect(results[0].Arguments).To(Equal(`{"x":5,"y":3}`))
|
||||
})
|
||||
|
||||
It("Should parse the result by matching the JSONRegexMatch", func() {
|
||||
input := `
|
||||
{"function": "add", "arguments": {"x": 5, "y": 3}}
|
||||
</tool_call>`
|
||||
functionConfig.ParallelCalls = false
|
||||
functionConfig.NoGrammar = true
|
||||
functionConfig.JSONRegexMatch = `(?s)(.*?)</tool_call>`
|
||||
functionConfig.ResponseRegex = ""
|
||||
functionConfig.FunctionName = false
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue