Skip to content

Commit ebdec80

Browse files
committed
fix: change new Client API
Signed-off-by: Donnie Adams <[email protected]>
1 parent ee2b368 commit ebdec80

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

client.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,31 @@ import (
1212

1313
const relativeToBinaryPath = "<me>"
1414

15-
type Client struct {
15+
type ClientOpts struct {
1616
GPTScriptURL string
1717
GPTScriptBin string
1818
}
1919

20-
func (c *Client) Complete() {
21-
if c.GPTScriptBin == "" {
22-
c.GPTScriptBin = getCommand()
20+
type Client struct {
21+
opts ClientOpts
22+
}
23+
24+
func NewClient(opts ClientOpts) *Client {
25+
c := &Client{opts: opts}
26+
c.complete()
27+
return c
28+
}
29+
30+
func (c *Client) complete() {
31+
if c.opts.GPTScriptBin == "" {
32+
c.opts.GPTScriptBin = getCommand()
2333
}
2434
}
2535

2636
func (c *Client) Evaluate(ctx context.Context, opts Opts, tools ...fmt.Stringer) (*Run, error) {
2737
return (&Run{
28-
url: c.GPTScriptURL,
29-
binPath: c.GPTScriptBin,
38+
url: c.opts.GPTScriptURL,
39+
binPath: c.opts.GPTScriptBin,
3040
requestPath: "evaluate",
3141
state: Creating,
3242
opts: opts,
@@ -37,8 +47,8 @@ func (c *Client) Evaluate(ctx context.Context, opts Opts, tools ...fmt.Stringer)
3747

3848
func (c *Client) Run(ctx context.Context, toolPath string, opts Opts) (*Run, error) {
3949
return (&Run{
40-
url: c.GPTScriptURL,
41-
binPath: c.GPTScriptBin,
50+
url: c.opts.GPTScriptURL,
51+
binPath: c.opts.GPTScriptBin,
4252
requestPath: "run",
4353
state: Creating,
4454
opts: opts,
@@ -86,8 +96,8 @@ func (c *Client) Fmt(ctx context.Context, nodes []Node) (string, error) {
8696

8797
run := &runSubCommand{
8898
Run: Run{
89-
url: c.GPTScriptURL,
90-
binPath: c.GPTScriptBin,
99+
url: c.opts.GPTScriptURL,
100+
binPath: c.opts.GPTScriptBin,
91101
requestPath: "fmt",
92102
state: Creating,
93103
toolPath: "",
@@ -148,8 +158,8 @@ func (c *Client) ListModels(ctx context.Context) ([]string, error) {
148158
func (c *Client) runBasicCommand(ctx context.Context, command, requestPath, toolPath, content string) (string, error) {
149159
run := &runSubCommand{
150160
Run: Run{
151-
url: c.GPTScriptURL,
152-
binPath: c.GPTScriptBin,
161+
url: c.opts.GPTScriptURL,
162+
binPath: c.opts.GPTScriptBin,
153163
requestPath: requestPath,
154164
state: Creating,
155165
toolPath: toolPath,

client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestMain(m *testing.M) {
2020
panic("OPENAI_API_KEY or GPTSCRIPT_URL environment variable must be set")
2121
}
2222

23-
client = &Client{GPTScriptURL: os.Getenv("GPTSCRIPT_URL"), GPTScriptBin: os.Getenv("GPTSCRIPT_BIN")}
23+
client = NewClient(ClientOpts{GPTScriptURL: os.Getenv("GPTSCRIPT_URL"), GPTScriptBin: os.Getenv("GPTSCRIPT_BIN")})
2424
os.Exit(m.Run())
2525
}
2626

0 commit comments

Comments
 (0)