Skip to content

Commit

Permalink
docs: add assistant and linglet
Browse files Browse the repository at this point in the history
  • Loading branch information
henomis committed Feb 5, 2024
1 parent 8523b16 commit 35b4ea6
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 1 deletion.
28 changes: 28 additions & 0 deletions docs/content/reference/assistant.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 10 additions & 0 deletions docs/content/reference/examples.md
Original file line number Diff line number Diff line change
@@ -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)
62 changes: 62 additions & 0 deletions docs/content/reference/linglet.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 4 additions & 1 deletion examples/linglet/sql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 35b4ea6

Please sign in to comment.