Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import (

// LLMs toolkit
"github.com/kshard/chatter"
"github.com/kshard/chatter/llm/autoconfig"
"github.com/kshard/chatter/provider/autoconfig"

// Agents toolkit
"github.com/kshard/thinker/agent"
Expand Down
2 changes: 1 addition & 1 deletion command/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (r *Registry) Invoke(reply *chatter.Reply) (thinker.Phase, chatter.Message,
return thinker.AGENT_RETURN, nil, nil
}

return thinker.AGENT_ASK, answer, nil
return thinker.AGENT_ASK, &answer, nil
}

func convert(cmd thinker.Cmd) (chatter.Cmd, error) {
Expand Down
45 changes: 34 additions & 11 deletions doc/HOWTO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [HowTos](#howtos)
- [Setup environment](#setup-environment)
- [Example configurations](#example-configurations)


## Setup environment
Expand All @@ -11,41 +12,63 @@ The library uses [`chatter`](github.com/kshard/chatter) as an adapter to access
* [OpenAI](https://platform.openai.com/docs/api-reference/introduction)
* [LM Studio](https://lmstudio.ai)

Once the provider and LLMs access is configures, your application can start using it. The [`autoconfig`](github.com/kshard/chatter/llm/autoconfig) is recommended approach to begin with. It does not require any specification within Golang code.
Once the provider and LLMs access is configures, your application can start using it. The [`autoconfig`](github.com/kshard/chatter/provider/autoconfig) is recommended approach to begin with. It does not require any specification within Golang code.

```go
import "github.com/kshard/chatter/llm/autoconfig"
import "github.com/kshard/chatter/provider/autoconfig"

llm, err := autoconfig.New("thinker")
llm, err := autoconfig.FromNetRC("thinker")
if err != nil {
panic(err)
}
```

The `autoconfig` reads the desired configuration from `~/.netrc` and creates appropriate instance of LLM API.
The `autoconfig` reads the desired configuration from `~/.netrc` and creates appropriate instance of LLM API. Your `~/.netrc` file must include at least the `provider` and `model` fields under a named service entry. For example:

```
machine thinker
provider provider:bedrock/foundation/converse
model us.anthropic.claude-3-7-sonnet-20250219-v1:0
```

* `provider` specifies the full path to the provider's capability (e.g., `provider:bedrock/foundation/converse`). The path ressembles import path of providers implemented by this library
* `model` specifies the exact model name as recognized by the provider

Each provider and model family may support additional options. These can also be added under the same `machine` entry and will be passed into the corresponding provider implementation.

```
region // used by Bedrock providers
host // used by OpenAI providers
secret // used by OpenAI providers
timeout // used by OpenAI providers
dimensions // used by embedding families
```

### Example configurations


**For AWS Bedrock**, `~/.netrc` config is
```
machine thinker
provider bedrock
provider provider:bedrock/foundation/converse
model us.anthropic.claude-3-7-sonnet-20250219-v1:0
region us-west-2
family llama3
model meta.llama3-1-70b-instruct-v1:0
```

**For OpenAI**, `~/.netrc` config is
```
machine chatter1
provider openai
host https://api.openai.com
provider provider:openai/foundation/gpt
model gpt-4o
host https://api.openai.com
secret sk-...IA
```

**For LM Studio**, `~/.netrc` config is
```
machine chatter1
provider openai
host http://localhost:1234
provider provider:openai/foundation/gpt
model gemma-3-27b-it
host http://localhost:1234
timeout 300
```
4 changes: 2 additions & 2 deletions examples/01_helloworld/hw.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"fmt"

"github.com/kshard/chatter"
"github.com/kshard/chatter/llm/autoconfig"
"github.com/kshard/chatter/provider/autoconfig"
"github.com/kshard/thinker/agent"
)

Expand All @@ -38,7 +38,7 @@ func anagram(expr string) (chatter.Message, error) {

func main() {
// create instance of LLM API, see doc/HOWTO.md for details
llm, err := autoconfig.New("thinker")
llm, err := autoconfig.FromNetRC("thinker")
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/02_rainbow/rainbow.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

"github.com/kshard/chatter"
"github.com/kshard/chatter/aio"
"github.com/kshard/chatter/llm/autoconfig"
"github.com/kshard/chatter/provider/autoconfig"
"github.com/kshard/thinker"
"github.com/kshard/thinker/agent/worker"
"github.com/kshard/thinker/codec"
Expand Down Expand Up @@ -49,7 +49,7 @@ func validate(seq []string) error {

func main() {
// create instance of LLM API, see doc/HOWTO.md for details
llm, err := autoconfig.New("thinker")
llm, err := autoconfig.FromNetRC("thinker")
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/03_script/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/kshard/chatter"
"github.com/kshard/chatter/aio"
"github.com/kshard/chatter/llm/autoconfig"
"github.com/kshard/chatter/provider/autoconfig"
"github.com/kshard/thinker"
"github.com/kshard/thinker/agent"
"github.com/kshard/thinker/codec"
Expand Down Expand Up @@ -82,7 +82,7 @@ func main() {
registry.Register(softcmd.Return())

// create instance of LLM API, see doc/HOWTO.md for details
llm, err := autoconfig.New("thinker")
llm, err := autoconfig.FromNetRC("thinker")
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/04_reflex/reflex.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/kshard/chatter"
"github.com/kshard/chatter/aio"
"github.com/kshard/chatter/llm/autoconfig"
"github.com/kshard/chatter/provider/autoconfig"
"github.com/kshard/thinker/agent/worker"
"github.com/kshard/thinker/codec"
"github.com/kshard/thinker/command/softcmd"
Expand All @@ -39,7 +39,7 @@ func main() {
registry.Register(softcmd.Bash("MacOS", "/tmp/script"))

// create instance of LLM API, see doc/HOWTO.md for details
llm, err := autoconfig.New("thinker")
llm, err := autoconfig.FromNetRC("thinker")
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/05_chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"os"

"github.com/kshard/chatter"
"github.com/kshard/chatter/llm/autoconfig"
"github.com/kshard/chatter/provider/autoconfig"
"github.com/kshard/thinker"
"github.com/kshard/thinker/agent"
"github.com/kshard/thinker/agent/worker"
Expand Down Expand Up @@ -72,7 +72,7 @@ func (agt AgentB) Encode(string) (chatter.Message, error) {

func main() {
// create instance of LLM API, see doc/HOWTO.md for details
llm, err := autoconfig.New("thinker")
llm, err := autoconfig.FromNetRC("thinker")
if err != nil {
panic(err)
}
Expand Down
27 changes: 20 additions & 7 deletions examples/06_text_processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ package main
import (
"context"
"fmt"
"io"

"github.com/fogfish/stream/lfs"
"github.com/fogfish/stream/spool"
"github.com/kshard/chatter"
"github.com/kshard/chatter/llm/autoconfig"
"github.com/kshard/chatter/provider/autoconfig"
"github.com/kshard/thinker/agent"
"github.com/kshard/thinker/agent/worker"
"github.com/kshard/thinker/codec"
Expand All @@ -40,7 +41,7 @@ func processor(s string) (chatter.Message, error) {
}

func main() {
llm, err := autoconfig.New("thinker")
llm, err := autoconfig.FromNetRC("thinker")
if err != nil {
panic(err)
}
Expand All @@ -55,7 +56,7 @@ func main() {
if err != nil {
panic(err)
}
q := spool.New(r, w, spool.Mutable)
q := spool.New(r, w, spool.IsMutable)

// We need 10 files, let's use agents to get itls
fmt.Printf("==> creating files ...\n")
Expand All @@ -70,14 +71,26 @@ func main() {
wrk := agent.NewPrompter(llm, processor)

fmt.Printf("==> processing files ...\n")
q.ForEachFile(context.Background(), "/",
func(ctx context.Context, path string, txt []byte) ([]byte, error) {
q.ForEach(context.Background(), "/",
func(ctx context.Context, path string, r io.Reader, w io.Writer) error {
fmt.Printf("==> %v ...\n", path)

txt, err := io.ReadAll(r)
if err != nil {
return err
}

kwd, err := wrk.PromptOnce(ctx, string(txt))
if err != nil {
return nil, err
return err
}
return []byte(kwd.String()), nil

_, err = w.Write([]byte(kwd.String()))
if err != nil {
return err
}

return nil
},
)
}
8 changes: 4 additions & 4 deletions examples/07_aws_sfs/cmd/classify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ package main

import (
"github.com/aws/aws-lambda-go/lambda"
"github.com/kshard/chatter/llm/bedrock"
"github.com/kshard/chatter/provider/bedrock/foundation/converse"
"github.com/kshard/thinker/examples/07_aws_sfs/core"
)

func main() {
llm, err := bedrock.New(
bedrock.WithLLM(bedrock.LLAMA3_1_70B_INSTRUCT),
bedrock.WithRegion("us-west-2"),
llm, err := converse.New(
"us.anthropic.claude-3-7-sonnet-20250219-v1:0",
converse.WithRegion("us-west-2"),
)
if err != nil {
panic(err)
Expand Down
8 changes: 4 additions & 4 deletions examples/07_aws_sfs/cmd/ingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ package main

import (
"github.com/aws/aws-lambda-go/lambda"
"github.com/kshard/chatter/llm/bedrock"
"github.com/kshard/chatter/provider/bedrock/foundation/converse"
"github.com/kshard/thinker/examples/07_aws_sfs/core"
)

func main() {
llm, err := bedrock.New(
bedrock.WithLLM(bedrock.LLAMA3_1_70B_INSTRUCT),
bedrock.WithRegion("us-west-2"),
llm, err := converse.New(
"us.anthropic.claude-3-7-sonnet-20250219-v1:0",
converse.WithRegion("us-west-2"),
)
if err != nil {
panic(err)
Expand Down
8 changes: 4 additions & 4 deletions examples/07_aws_sfs/cmd/insight/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ package main

import (
"github.com/aws/aws-lambda-go/lambda"
"github.com/kshard/chatter/llm/bedrock"
"github.com/kshard/chatter/provider/bedrock/foundation/converse"
"github.com/kshard/thinker/examples/07_aws_sfs/core"
)

func main() {
llm, err := bedrock.New(
bedrock.WithLLM(bedrock.LLAMA3_1_70B_INSTRUCT),
bedrock.WithRegion("us-west-2"),
llm, err := converse.New(
"us.anthropic.claude-3-7-sonnet-20250219-v1:0",
converse.WithRegion("us-west-2"),
)
if err != nil {
panic(err)
Expand Down
13 changes: 6 additions & 7 deletions examples/07_aws_sfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@ package main

import (
"github.com/aws/aws-cdk-go/awscdk/v2"
"github.com/aws/aws-cdk-go/awscdk/v2/awsbedrock"
"github.com/aws/aws-cdk-go/awscdk/v2/awsevents"
"github.com/aws/aws-cdk-go/awscdk/v2/awssqs"
"github.com/aws/jsii-runtime-go"
"github.com/fogfish/scud"
"github.com/fogfish/typestep"
"github.com/kshard/chatter/llm/bedrock"
"github.com/kshard/chatter/provider/bedrock/iam"
"github.com/kshard/thinker/examples/07_aws_sfs/core"
)

func main() {
app := awscdk.NewApp(nil)
stack := awscdk.NewStack(app, jsii.String("example-aws-thinker"), nil)

llm := bedrock.NewFoundationModel(stack, jsii.String("LLM"),
awsbedrock.FoundationModelIdentifier_META_LLAMA_3_1_70_INSTRUCT_V1(),
fm := iam.NewInferenceProfile(stack, jsii.String("InferenceProfile"),
jsii.String("us.anthropic.claude-3-7-sonnet-20250219-v1:0"),
)

input := awsevents.NewEventBus(stack, jsii.String("Input"),
Expand All @@ -46,23 +45,23 @@ func main() {
SourceCodeLambda: "07_aws_sfs/cmd/ingest",
},
)
llm.GrantAccessIn(ingest, jsii.String("us-west-2"))
fm.GrantAccessIn(ingest, jsii.String("us-west-2"))

classify := scud.NewFunctionGo(stack, jsii.String("Classify"),
&scud.FunctionGoProps{
SourceCodeModule: "github.com/kshard/thinker/examples",
SourceCodeLambda: "07_aws_sfs/cmd/classify",
},
)
llm.GrantAccessIn(classify, jsii.String("us-west-2"))
fm.GrantAccessIn(classify, jsii.String("us-west-2"))

insight := scud.NewFunctionGo(stack, jsii.String("Insight"),
&scud.FunctionGoProps{
SourceCodeModule: "github.com/kshard/thinker/examples",
SourceCodeLambda: "07_aws_sfs/cmd/insight",
},
)
llm.GrantAccessIn(insight, jsii.String("us-west-2"))
fm.GrantAccessIn(insight, jsii.String("us-west-2"))

a := typestep.From[core.Document](input)
b := typestep.Join(new(core.Ingestor).Ingest, ingest, a)
Expand Down
4 changes: 2 additions & 2 deletions examples/08_manifold/mainfold.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/kshard/chatter"
"github.com/kshard/chatter/aio"
"github.com/kshard/chatter/llm/autoconfig"
"github.com/kshard/chatter/provider/autoconfig"
"github.com/kshard/thinker/agent"
"github.com/kshard/thinker/codec"
"github.com/kshard/thinker/command"
Expand All @@ -39,7 +39,7 @@ func main() {
registry.Register(command.Bash("MacOS", "/tmp/script"))

// create instance of LLM API, see doc/HOWTO.md for details
llm, err := autoconfig.New("thinker")
llm, err := autoconfig.FromNetRC("thinker")
if err != nil {
panic(err)
}
Expand Down
Loading
Loading