-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,093 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/henomis/lingoose/llm/openai" | ||
"github.com/henomis/lingoose/thread" | ||
"github.com/henomis/lingoose/tools/python" | ||
) | ||
|
||
func main() { | ||
newStr := func(str string) *string { | ||
return &str | ||
} | ||
llm := openai.New().WithModel(openai.GPT3Dot5Turbo0613).WithToolChoice(newStr("auto")).WithTools( | ||
python.New(), | ||
) | ||
|
||
t := thread.New().AddMessage( | ||
thread.NewUserMessage().AddContent( | ||
thread.NewTextContent("calculate reverse string of 'ailatiditalia', don't try to guess, let's use appropriate tool"), | ||
), | ||
) | ||
|
||
llm.Generate(context.Background(), t) | ||
if t.LastMessage().Role == thread.RoleTool { | ||
llm.Generate(context.Background(), t) | ||
} | ||
|
||
fmt.Println(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
openaiembedder "github.com/henomis/lingoose/embedder/openai" | ||
"github.com/henomis/lingoose/index" | ||
"github.com/henomis/lingoose/index/vectordb/jsondb" | ||
"github.com/henomis/lingoose/llm/openai" | ||
"github.com/henomis/lingoose/rag" | ||
"github.com/henomis/lingoose/thread" | ||
ragtool "github.com/henomis/lingoose/tools/rag" | ||
"github.com/henomis/lingoose/tools/serpapi" | ||
"github.com/henomis/lingoose/tools/shell" | ||
) | ||
|
||
func main() { | ||
|
||
rag := rag.New( | ||
index.New( | ||
jsondb.New().WithPersist("index.json"), | ||
openaiembedder.New(openaiembedder.AdaEmbeddingV2), | ||
), | ||
).WithChunkSize(1000).WithChunkOverlap(0) | ||
|
||
_, err := os.Stat("index.json") | ||
if os.IsNotExist(err) { | ||
err = rag.AddSources(context.Background(), "state_of_the_union.txt") | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
newStr := func(str string) *string { | ||
return &str | ||
} | ||
llm := openai.New().WithModel(openai.GPT4o).WithToolChoice(newStr("auto")).WithTools( | ||
ragtool.New(rag, "US covid vaccines"), | ||
serpapi.New(), | ||
shell.New(), | ||
) | ||
|
||
topics := []string{ | ||
"how many covid vaccine doses US has donated to other countries.", | ||
"who's the author of LinGoose github project.", | ||
"which process is consuming the most memory.", | ||
} | ||
|
||
for _, topic := range topics { | ||
t := thread.New().AddMessage( | ||
thread.NewUserMessage().AddContent( | ||
thread.NewTextContent("Please tell me " + topic), | ||
), | ||
) | ||
|
||
llm.Generate(context.Background(), t) | ||
if t.LastMessage().Role == thread.RoleTool { | ||
llm.Generate(context.Background(), t) | ||
} | ||
|
||
fmt.Println(t) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/henomis/lingoose/tools/duckduckgo" | ||
) | ||
|
||
func main() { | ||
|
||
t := duckduckgo.New().WithMaxResults(5) | ||
f := t.Fn().(duckduckgo.FnPrototype) | ||
|
||
fmt.Println(f(duckduckgo.Input{Query: "Simone Vellei"})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/henomis/lingoose/tools/python" | ||
) | ||
|
||
func main() { | ||
t := python.New().WithPythonPath("python3") | ||
|
||
pythonScript := `print("Hello from Python!")` | ||
f := t.Fn().(python.FnPrototype) | ||
|
||
fmt.Println(f(python.Input{PythonCode: pythonScript})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/henomis/lingoose/tools/serpapi" | ||
) | ||
|
||
func main() { | ||
|
||
t := serpapi.New() | ||
f := t.Fn().(serpapi.FnPrototype) | ||
|
||
fmt.Println(f(serpapi.Input{Query: "Simone Vellei"})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/henomis/lingoose/tools/shell" | ||
) | ||
|
||
func main() { | ||
t := shell.New() | ||
|
||
bashScript := `echo "Hello from $SHELL!"` | ||
f := t.Fn().(shell.FnPrototype) | ||
|
||
fmt.Println(f(shell.Input{BashScript: bashScript})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package dalle | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/henomis/lingoose/transformer" | ||
) | ||
|
||
const ( | ||
defaultTimeoutInSeconds = 60 | ||
) | ||
|
||
type Tool struct { | ||
} | ||
|
||
type Input struct { | ||
Description string `json:"description" jsonschema:"description=the description of the image that should be created"` | ||
} | ||
|
||
type Output struct { | ||
Error string `json:"error,omitempty"` | ||
ImageURL string `json:"imageURL,omitempty"` | ||
} | ||
|
||
type FnPrototype func(Input) Output | ||
|
||
func New() *Tool { | ||
return &Tool{} | ||
} | ||
|
||
func (t *Tool) Name() string { | ||
return "dalle" | ||
} | ||
|
||
func (t *Tool) Description() string { | ||
return "A tool that creates an image from a description." | ||
} | ||
|
||
func (t *Tool) Fn() any { | ||
return t.fn | ||
} | ||
|
||
func (t *Tool) fn(i Input) Output { | ||
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeoutInSeconds*time.Second) | ||
defer cancel() | ||
|
||
d := transformer.NewDallE().WithImageSize(transformer.DallEImageSize512x512) | ||
imageURL, err := d.Transform(ctx, i.Description) | ||
if err != nil { | ||
return Output{Error: fmt.Sprintf("error creating image: %v", err)} | ||
} | ||
|
||
return Output{ImageURL: imageURL.(string)} | ||
} |
Oops, something went wrong.