mirror of
https://github.com/mudler/cogito.git
synced 2026-07-24 10:55:21 -04:00
2f20fcce01
* Split e2e and unit tests Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Abstract away LLM to an interface Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Update README Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Fixups Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Enhance content improve generation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Add unit test for reviewer Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Better handling of result status of tool calls Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Fixups Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Add tools test file Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
package mock
|
|
|
|
import (
|
|
. "github.com/mudler/cogito"
|
|
"github.com/sashabaranov/go-openai"
|
|
)
|
|
|
|
// MockTool implements the Tool interface for testing
|
|
type MockTool struct {
|
|
name string
|
|
description string
|
|
runResults []string
|
|
runError error
|
|
runIndex int
|
|
status *ToolStatus
|
|
}
|
|
|
|
func NewMockTool(name, description string) *MockTool {
|
|
return &MockTool{
|
|
name: name,
|
|
description: description,
|
|
status: &ToolStatus{},
|
|
}
|
|
}
|
|
|
|
func (m *MockTool) Tool() openai.Tool {
|
|
return openai.Tool{
|
|
Type: openai.ToolTypeFunction,
|
|
Function: &openai.FunctionDefinition{
|
|
Name: m.name,
|
|
Description: m.description,
|
|
// We don't need parameters in this mock
|
|
// Will show up as null
|
|
},
|
|
}
|
|
}
|
|
|
|
func (m *MockTool) Status() *ToolStatus {
|
|
return m.status
|
|
}
|
|
|
|
func (m *MockTool) Run(args map[string]any) (string, error) {
|
|
if m.runError != nil {
|
|
return "", m.runError
|
|
}
|
|
defer func() {
|
|
m.runIndex++
|
|
}()
|
|
return m.runResults[m.runIndex], nil
|
|
}
|
|
|
|
func (m *MockTool) SetRunResult(result string) {
|
|
m.runResults = append(m.runResults, result)
|
|
}
|
|
|
|
func (m *MockTool) SetRunError(err error) {
|
|
m.runError = err
|
|
}
|