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>
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/mudler/cogito/examples/internal/search"
|
|
|
|
"github.com/mudler/cogito"
|
|
)
|
|
|
|
func main() {
|
|
|
|
model := os.Getenv("MODEL")
|
|
apiKey := os.Getenv("API_KEY")
|
|
baseURL := os.Getenv("BASE_URL")
|
|
|
|
defaultLLM := cogito.NewOpenAILLM(model, apiKey, baseURL)
|
|
|
|
f := cogito.NewEmptyFragment()
|
|
for {
|
|
reader := bufio.NewReader(os.Stdin)
|
|
fmt.Print("> ")
|
|
text, _ := reader.ReadString('\n')
|
|
fmt.Println(strings.TrimSpace(text))
|
|
|
|
f = f.AddMessage("user", strings.TrimSpace(text))
|
|
var err error
|
|
f, err = cogito.ExecuteTools(
|
|
defaultLLM, f,
|
|
cogito.WithStatusCallback(func(s string) {
|
|
fmt.Println("___________________ START STATUS _________________")
|
|
fmt.Println(s)
|
|
fmt.Println("___________________ END STATUS _________________")
|
|
}),
|
|
cogito.WithTools(
|
|
&search.SearchTool{},
|
|
),
|
|
)
|
|
if err != nil && !errors.Is(err, cogito.ErrNoToolSelected) {
|
|
panic(err)
|
|
}
|
|
|
|
f, err = defaultLLM.Ask(context.Background(), f)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
fmt.Println(f.LastMessage().Content)
|
|
|
|
}
|
|
}
|