-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathllamacppclient.go
53 lines (44 loc) · 1.28 KB
/
llamacppclient.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package llamacpp
import (
"fmt"
"github.com/spandigitial/codeassistant/client"
"github.com/spandigitial/codeassistant/model"
"os/exec"
)
type Client struct {
binaryPath string
modelPath string
promptContextSize int
extraArguments []string
}
type Option func(client *Client)
func New(binaryPath string, modelPath string, promptContextSize int, options ...Option) *Client {
c := &Client{
binaryPath: binaryPath,
modelPath: modelPath,
promptContextSize: promptContextSize,
}
for _, option := range options {
option(c)
}
return c
}
func WithExtraArguments(arguments ...string) Option {
return func(client *Client) {
client.extraArguments = arguments
}
}
func (c *Client) Models(models chan<- client.LanguageModel) error {
close(models)
return nil
}
func (c *Client) Completion(ci *model.CommandInstance, messageParts chan<- client.MessagePart) error {
args := append([]string{"-m", c.modelPath, "-n", fmt.Sprintf("%d", c.promptContextSize)}, c.extraArguments...)
out, err := exec.Command(c.binaryPath, args...).Output()
if err != nil {
return err
}
messageParts <- client.MessagePart{Delta: "", Type: "Start"}
messageParts <- client.MessagePart{Delta: string(out), Type: "Part"}
messageParts <- client.MessagePart{Delta: "", Type: "Done"}
}