Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(cli)/add knowledgebase usecase #18

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
21 changes: 18 additions & 3 deletions cmd/cli/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import (

"github.com/nullswan/nomi/internal/chat"
"github.com/nullswan/nomi/internal/cli"
"github.com/nullswan/nomi/internal/config"
"github.com/nullswan/nomi/internal/logger"
"github.com/nullswan/nomi/internal/providers"
"github.com/nullswan/nomi/internal/tools"
"github.com/nullswan/nomi/usecases/browser"
"github.com/nullswan/nomi/usecases/commit"
"github.com/nullswan/nomi/usecases/copywriter"
"github.com/nullswan/nomi/usecases/interpreter"
"github.com/nullswan/nomi/usecases/knowledgebase"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -87,18 +89,18 @@ var usecaseCmd = &cobra.Command{
)
}

textToJSONBackend, err := cli.InitJSONProviders(
ttjProvider, err := cli.InitJSONProviders(
logger,
targetModel,
)
if err != nil {
fmt.Printf("Error initializing providers: %v\n", err)
return
}
defer textToJSONBackend.Close()
defer ttjProvider.Close()

ttjBackend := tools.NewTextToJSONBackend(
textToJSONBackend,
ttjProvider,
logger,
)

Expand All @@ -119,6 +121,10 @@ var usecaseCmd = &cobra.Command{
defer ttsProvider.Close()
}

knownledgeBase := tools.NewFileKnowledgeBase(
config.GetKnowledgeDirectory(),
)

switch usecaseID {
case "commit":
err = commit.OnStart(
Expand Down Expand Up @@ -158,6 +164,14 @@ var usecaseCmd = &cobra.Command{
inputHandler,
conversation,
)
case "knowledgebase":
err = knowledgebase.OnStart(
ctx,
selector,
toolsLogger,
logger,
knownledgeBase,
)
default:
fmt.Println("usecase " + usecaseID + " not found")
return
Expand All @@ -178,5 +192,6 @@ var usecaseListCmd = &cobra.Command{
fmt.Println("copywriter - Generate copywriting documents")
fmt.Println("browser - Browse the web with LLM")
fmt.Println("console - Interact with the console")
fmt.Println("knowledgebase - Use the knowledgebase")
},
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/google/uuid v1.6.0
github.com/gopxl/beep/v2 v2.1.0
github.com/gordonklaus/portaudio v0.0.0-20230709114228-aafa478834f5
github.com/gorilla/websocket v1.5.3
github.com/jedib0t/go-pretty/v6 v6.6.1
github.com/manifoldco/promptui v0.9.0
github.com/mattn/go-runewidth v0.0.16
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ github.com/gordonklaus/portaudio v0.0.0-20230709114228-aafa478834f5 h1:5AlozfqaV
github.com/gordonklaus/portaudio v0.0.0-20230709114228-aafa478834f5/go.mod h1:WY8R6YKlI2ZI3UyzFk7P6yGSuS+hFwNtEzrexRyD7Es=
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hajimehoshi/go-mp3 v0.3.4 h1:NUP7pBYH8OguP4diaTZ9wJbUbk3tC0KlfzsEpWmYj68=
github.com/hajimehoshi/go-mp3 v0.3.4/go.mod h1:fRtZraRFcWb0pu7ok0LqyFhCUrPeMsGRSVop0eemFmo=
github.com/hajimehoshi/oto/v2 v2.3.1/go.mod h1:seWLbgHH7AyUMYKfKYT9pg7PhUu9/SisyJvNTT+ASQo=
Expand Down
11 changes: 11 additions & 0 deletions internal/audio/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
type StreamHandler struct {
stream *portaudio.Stream
logger *slog.Logger
params *StreamParameters
}

type StreamParameters struct {
Expand Down Expand Up @@ -111,6 +112,7 @@ func NewInputStream(
With("device_name", device.Name)

logger.
With("channels", opts.Channels).
With("sample_rate", opts.SampleRate).
With("frames_per_buffer", opts.FramesPerBuffer).
With("latency", opts.Latency).
Expand Down Expand Up @@ -139,6 +141,7 @@ func NewInputStream(
return &StreamHandler{
stream: stream,
logger: logger,
params: opts,
}, nil
}

Expand Down Expand Up @@ -175,6 +178,14 @@ func (a *StreamHandler) Close() error {
return nil
}

func (a *StreamHandler) GetSampleRate() float64 {
return a.params.SampleRate
}

func (a *StreamHandler) GetChannels() int {
return a.params.Channels
}

func GetDevices() ([]*portaudio.DeviceInfo, error) {
devices, err := portaudio.Devices()
if err != nil {
Expand Down
43 changes: 27 additions & 16 deletions internal/tools/audiostream.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,15 @@ import (
type AudioStream interface {
Start() error
Close() error

GetSampleRate() float64
GetChannels() int
}

type audioStream struct {
stream *audio.StreamHandler
}

func (a *audioStream) Close() error {
err := a.stream.Stop()
if err != nil {
return fmt.Errorf("failed to stop audio stream: %w", err)
}
return nil
}

func (a *audioStream) Start() error {
err := a.stream.Start()
if err != nil {
return fmt.Errorf("failed to start audio stream: %w", err)
}
return nil
}

func NewAudioStream(
logger *slog.Logger,
device *portaudio.DeviceInfo,
Expand All @@ -52,3 +39,27 @@ func NewAudioStream(
stream: stream,
}, nil
}

func (a *audioStream) Close() error {
err := a.stream.Stop()
if err != nil {
return fmt.Errorf("failed to stop audio stream: %w", err)
}
return nil
}

func (a *audioStream) Start() error {
err := a.stream.Start()
if err != nil {
return fmt.Errorf("failed to start audio stream: %w", err)
}
return nil
}

func (a *audioStream) GetSampleRate() float64 {
return a.stream.GetSampleRate()
}

func (a *audioStream) GetChannels() int {
return a.stream.GetChannels()
}
3 changes: 2 additions & 1 deletion internal/tools/knowldege.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ type FileKnowledgeBase struct {

func NewFileKnowledgeBase(repositoryPath string) *FileKnowledgeBase {
return &FileKnowledgeBase{
repositoryPath: repositoryPath,
// TODO(nullswan): Select your knowledge basepath
repositoryPath: repositoryPath + "/nomi",
}
}

Expand Down
Loading
Loading