diff --git a/examples/assistant/agent/main.go b/examples/assistant/agent/main.go index 5c0e723b..96441d56 100644 --- a/examples/assistant/agent/main.go +++ b/examples/assistant/agent/main.go @@ -10,6 +10,7 @@ import ( "github.com/henomis/lingoose/observer/langfuse" "github.com/henomis/lingoose/thread" + humantool "github.com/henomis/lingoose/tool/human" pythontool "github.com/henomis/lingoose/tool/python" serpapitool "github.com/henomis/lingoose/tool/serpapi" ) @@ -18,7 +19,7 @@ func main() { ctx := context.Background() langfuseObserver := langfuse.New(ctx) - trace, err := langfuseObserver.Trace(&observer.Trace{Name: "Average Temperature calculator"}) + trace, err := langfuseObserver.Trace(&observer.Trace{Name: "Italian guests calculator"}) if err != nil { panic(err) } @@ -31,6 +32,7 @@ func main() { openai.New().WithModel(openai.GPT4o).WithToolChoice(&auto).WithTools( pythontool.New(), serpapitool.New(), + humantool.New(), ), ).WithParameters( assistant.Parameters{ @@ -41,7 +43,7 @@ func main() { ).WithThread( thread.New().AddMessages( thread.NewUserMessage().AddContent( - thread.NewTextContent("Search the current temperature of New York, Rome, and Tokyo, then calculate the average temperature in Celsius."), + thread.NewTextContent("search the top 3 italian dishes and then their costs, then ask the user's budget in euros and calculate how many guests can be invited for each dish"), ), ), ).WithMaxIterations(10) diff --git a/tool/human/human.go b/tool/human/human.go new file mode 100644 index 00000000..9e6f6e55 --- /dev/null +++ b/tool/human/human.go @@ -0,0 +1,44 @@ +package human + +import ( + "fmt" +) + +type Tool struct { +} + +func New() *Tool { + return &Tool{} +} + +type Input struct { + Question string `json:"question" jsonschema:"description=the question to ask the human"` +} + +type Output struct { + Error string `json:"error,omitempty"` + Result string `json:"result,omitempty"` +} + +type FnPrototype = func(Input) Output + +func (t *Tool) Name() string { + return "human" +} + +func (t *Tool) Description() string { + return "A tool that asks a question to a human and returns the answer. Use it to interact with a human." +} + +func (t *Tool) Fn() any { + return t.fn +} + +func (t *Tool) fn(i Input) Output { + var answer string + + fmt.Printf("\n\n%s > ", i.Question) + fmt.Scanln(&answer) + + return Output{Result: answer} +} diff --git a/tool/python/python.go b/tool/python/python.go index 261e2080..3fd6b7ad 100644 --- a/tool/python/python.go +++ b/tool/python/python.go @@ -22,7 +22,7 @@ func (t *Tool) WithPythonPath(pythonPath string) *Tool { } type Input struct { - PythonCode string `json:"python_code" jsonschema:"description=python code that prints the final result to stdout."` + PythonCode string `json:"python_code" jsonschema:"description=python code that uses print() to print the final result to stdout."` } type Output struct { @@ -38,7 +38,7 @@ func (t *Tool) Name() string { //nolint:lll func (t *Tool) Description() string { - return "A tool that runs Python code using the Python interpreter. Use this tool to solve calculations, manipulate data, or perform any other Python-related tasks. The code should print the final result to stdout." + return "Use this tool to solve calculations, manipulate data, or perform any other Python-related tasks. The code should use print() to print the final result to stdout." } func (t *Tool) Fn() any { diff --git a/tool/serpapi/api.go b/tool/serpapi/api.go index 15491ec3..aa3f4c6f 100644 --- a/tool/serpapi/api.go +++ b/tool/serpapi/api.go @@ -94,48 +94,6 @@ func (r *response) Decode(body io.Reader) error { return err } - if r.apiResponse.AnswerBox != nil { - answerBox, errMarshall := json.Marshal(r.apiResponse.AnswerBox) - if errMarshall != nil { - return errMarshall - } - - r.Results = append(r.Results, result{ - Title: "Answer Box", - Info: string(answerBox), - }) - - return nil - } - - if r.apiResponse.SportsResults != nil { - sportsResults, errMarshall := json.Marshal(r.apiResponse.SportsResults) - if errMarshall != nil { - return errMarshall - } - - r.Results = append(r.Results, result{ - Title: "Sports Results", - Info: string(sportsResults), - }) - - return nil - } - - if r.apiResponse.KnowledgeGraph != nil { - knowledgeGraph, errMarshall := json.Marshal(r.apiResponse.KnowledgeGraph) - if errMarshall != nil { - return errMarshall - } - - r.Results = append(r.Results, result{ - Title: "Knowledge Graph", - Info: string(knowledgeGraph), - }) - - return nil - } - for _, res := range r.apiResponse.OrganicResults { r.Results = append(r.Results, result{ Title: res.Title,