From 35b4ea6e5236fb4a7480d7da49ba4c4d29f6162d Mon Sep 17 00:00:00 2001 From: Simone Vellei Date: Mon, 5 Feb 2024 09:08:57 +0100 Subject: [PATCH] docs: add assistant and linglet --- docs/content/reference/assistant.md | 28 +++++++++++++ docs/content/reference/examples.md | 10 +++++ docs/content/reference/linglet.md | 62 +++++++++++++++++++++++++++++ examples/linglet/sql/main.go | 5 ++- 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 docs/content/reference/examples.md diff --git a/docs/content/reference/assistant.md b/docs/content/reference/assistant.md index 54d2d24c..a7f95357 100644 --- a/docs/content/reference/assistant.md +++ b/docs/content/reference/assistant.md @@ -4,3 +4,31 @@ description: linkTitle: "Assistant" menu: { main: { parent: 'reference', weight: -90 } } --- + +An AI Assistant is a conversational component that can understand and respond to natural language. It can be used to automate tasks, answer questions, and provide information. LinGoose offers an AI Assistant that is built on top of the `Thread`, `LLM` and `RAG` components. It uses the RAG model to retrieve relevant documents and then uses a language model to generate responses based on the retrieved documents. + +## Using AI Assistant + +LinGoose assistant can optionally be configured with a RAG model and a language model. + +```go +myAssistant := assistant.New( + openai.New().WithTemperature(0), +).WithRAG(myRAG).WithThread( + thread.New().AddMessages( + thread.NewUserMessage().AddContent( + thread.NewTextContent("what is the purpose of NATO?"), + ), + ), +) + + +err = myAssistant.Run(context.Background()) +if err != nil { + panic(err) +} + +fmt.Println(myAssistant.Thread()) +``` + +We can define the LinGoose `Assistant` as a `Thread` runner with an optional `RAG` component that will help to produce the response. \ No newline at end of file diff --git a/docs/content/reference/examples.md b/docs/content/reference/examples.md new file mode 100644 index 00000000..7a48602c --- /dev/null +++ b/docs/content/reference/examples.md @@ -0,0 +1,10 @@ +--- +title: "LinGoose Examples" +description: +linkTitle: "Examples" +menu: { main: { parent: 'reference', weight: -88 } } +--- + +LinGoose provides a number of examples to help you get started with building your own AI app. You can use these examples as a reference to understand how to build your own assistant. + +[LinGoose examples](https://github.com/henomis/lingoose/tree/main/examples) \ No newline at end of file diff --git a/docs/content/reference/linglet.md b/docs/content/reference/linglet.md index 95c580cb..649fbe7e 100644 --- a/docs/content/reference/linglet.md +++ b/docs/content/reference/linglet.md @@ -4,3 +4,65 @@ description: linkTitle: "Linglets" menu: { main: { parent: 'reference', weight: -89 } } --- + +Linglets are pre-built LinGoose Assistants with a specific purpose. They are designed to be used as a starting point for building your own AI app. You can use them as a reference to understand how to build your own assistant. + +There are two Linglets available: + +- `sql` - A Linglet that can understand and respond to SQL queries. +- `summarize` - A Linglet that can summarize text. + +## Using SQL Linglet + +The sql Linglet helps to build SQL queries. It can be used to automate tasks, defining a comlex SQL query, and provide information. + +```go +db, err := sql.Open("sqlite3", "Chinook_Sqlite.sqlite") +if err != nil { + panic(err) +} + +lingletSQL := lingletsql.New( + openai.New().WithMaxTokens(2000).WithTemperature(0).WithModel(openai.GPT3Dot5Turbo16K0613), + db, +) + +result, err := lingletSQL.Run( + context.Background(), + "list the top 3 albums that are most frequently present in playlists.", +) +if err != nil { + panic(err) +} + +fmt.Printf("SQL Query\n-----\n%s\n\n", result.SQLQuery) +fmt.Printf("Answer\n-------\n%s\n", result.Answer) +``` + +## Using Summarize Linglet + +The summarize Linglet helps to summarize text. + +```go + +textLoader := loader.NewTextLoader("state_of_the_union.txt", nil). + WithTextSplitter(textsplitter.NewRecursiveCharacterTextSplitter(4000, 0)) + +summarize := summarize.New( + openai.New().WithMaxTokens(2000).WithTemperature(0).WithModel(openai.GPT3Dot5Turbo16K0613), + textLoader, +).WithCallback( + func(t *thread.Thread, i, n int) { + fmt.Printf("Progress : %.0f%%\n", float64(i)/float64(n)*100) + }, +) + +summary, err := summarize.Run(context.Background()) +if err != nil { + panic(err) +} + +fmt.Println(*summary) +``` + +The summarize linglet chunks the input text into smaller pieces and then iterate over each chunk to summarize the result. It also provides a callback function to track the progress of the summarization process. \ No newline at end of file diff --git a/examples/linglet/sql/main.go b/examples/linglet/sql/main.go index d5551a37..6bcb0820 100644 --- a/examples/linglet/sql/main.go +++ b/examples/linglet/sql/main.go @@ -24,7 +24,10 @@ func main() { db, ) - result, err := lingletSQL.Run(context.Background(), "list the top 3 albums most present in playlists.") + result, err := lingletSQL.Run( + context.Background(), + "list the top 3 albums that are most frequently present in playlists.", + ) if err != nil { panic(err) }