Skip to content

Commit 3e094a7

Browse files
Add temperature and non-modified env vars
1 parent 102ea13 commit 3e094a7

File tree

10 files changed

+47
-17
lines changed

10 files changed

+47
-17
lines changed

examples/search.gpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ Look for the first 5 search results. Download each search result and look for co
1414
that would best answer the query ${query}.
1515

1616
With all that information try your best to provide an answer or useful context to ${query}.
17+
18+
If you can not retrieve a referenced URL then just skip that item and make a reference that
19+
that URL was skipped.

go.mod

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module github.com/acorn-io/gptscript
22

33
go 1.21.5
44

5+
replace github.com/sashabaranov/go-openai => github.com/gptscript-ai/go-openai v0.0.0-20240206232711-45b6e096246a
6+
57
require (
68
github.com/acorn-io/broadcaster v0.0.0-20240105011354-bfadd4a7b45d
79
github.com/acorn-io/cmd v0.0.0-20240203032901-e9e631185ddb
@@ -20,12 +22,6 @@ require (
2022

2123
require (
2224
github.com/acorn-io/baaah v0.0.0-20240119160309-2a58ee757bbd // indirect
23-
github.com/kr/pretty v0.3.1 // indirect
24-
github.com/onsi/ginkgo/v2 v2.13.0 // indirect
25-
github.com/onsi/gomega v1.29.0 // indirect
26-
)
27-
28-
require (
2925
github.com/bombsimon/logrusr/v4 v4.0.0 // indirect
3026
github.com/davecgh/go-spew v1.1.1 // indirect
3127
github.com/fatih/color v1.15.0 // indirect
@@ -36,11 +32,14 @@ require (
3632
github.com/hexops/gotextdiff v1.0.3 // indirect
3733
github.com/hexops/valast v1.4.3 // indirect
3834
github.com/inconshreveable/mousetrap v1.1.0 // indirect
35+
github.com/kr/pretty v0.3.1 // indirect
3936
github.com/mattn/go-colorable v0.1.13 // indirect
4037
github.com/mattn/go-isatty v0.0.17 // indirect
4138
github.com/mattn/go-runewidth v0.0.9 // indirect
4239
github.com/nightlyone/lockfile v1.0.0 // indirect
4340
github.com/olekukonko/tablewriter v0.0.5 // indirect
41+
github.com/onsi/ginkgo/v2 v2.13.0 // indirect
42+
github.com/onsi/gomega v1.29.0 // indirect
4443
github.com/pmezard/go-difflib v1.0.0 // indirect
4544
github.com/rogpeppe/go-internal v1.11.0 // indirect
4645
github.com/samber/lo v1.38.1 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaU
3737
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
3838
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
3939
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
40+
github.com/gptscript-ai/go-openai v0.0.0-20240206232711-45b6e096246a h1:AdBbQ1ODOYK5AwCey4VFEmKeu9gG4PCzuO80pQmgupE=
41+
github.com/gptscript-ai/go-openai v0.0.0-20240206232711-45b6e096246a/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
4042
github.com/hexops/autogold v0.8.1/go.mod h1:97HLDXyG23akzAoRYJh/2OBs3kd80eHyKPvZw0S5ZBY=
4143
github.com/hexops/autogold v1.3.1 h1:YgxF9OHWbEIUjhDbpnLhgVsjUDsiHDTyDfy2lrfdlzo=
4244
github.com/hexops/autogold v1.3.1/go.mod h1:sQO+mQUCVfxOKPht+ipDSkJ2SCJ7BNJVHZexsXqWMx4=
@@ -90,8 +92,6 @@ github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
9092
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
9193
github.com/samber/slog-logrus v1.0.0 h1:SsrN0p9akjCEaYd42Q5GtisMdHm0q11UD4fp4XCZi04=
9294
github.com/samber/slog-logrus v1.0.0/go.mod h1:ZTdPCmVWljwlfjz6XflKNvW4TcmYlexz4HMUOO/42bI=
93-
github.com/sashabaranov/go-openai v1.18.3 h1:dspFGkmZbhjg1059KhqLYSV2GaCiRIn+bOu50TlXUq8=
94-
github.com/sashabaranov/go-openai v1.18.3/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
9595
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
9696
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
9797
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=

pkg/engine/engine.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,25 @@ func (e *Engine) runCommand(ctx context.Context, tool types.Tool, input string)
182182
case string:
183183
envMap[envName] = val
184184
env = append(env, envName+"="+val)
185+
envMap[k] = val
186+
env = append(env, k+"="+val)
185187
case json.Number:
186188
envMap[envName] = string(val)
187189
env = append(env, envName+"="+string(val))
190+
envMap[k] = string(val)
191+
env = append(env, k+"="+string(val))
188192
case bool:
189193
envMap[envName] = fmt.Sprint(val)
190194
env = append(env, envName+"="+fmt.Sprint(val))
195+
envMap[k] = fmt.Sprint(val)
196+
env = append(env, k+"="+fmt.Sprint(val))
191197
default:
192198
data, err := json.Marshal(val)
193199
if err == nil {
194200
envMap[envName] = string(data)
195201
env = append(env, envName+"="+string(data))
202+
envMap[k] = string(data)
203+
env = append(env, k+"="+string(data))
196204
}
197205
}
198206
}

pkg/openai/client.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,10 @@ func (c *Client) Call(ctx context.Context, messageRequest types.CompletionReques
258258
}
259259

260260
request := openai.ChatCompletionRequest{
261-
Model: messageRequest.Model,
262-
Messages: msgs,
263-
MaxTokens: messageRequest.MaxToken,
261+
Model: messageRequest.Model,
262+
Messages: msgs,
263+
MaxTokens: messageRequest.MaxToken,
264+
Temperature: messageRequest.Temperature,
264265
}
265266

266267
if messageRequest.JSONResponse {

pkg/parser/parser.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ func toBool(line string) (bool, error) {
2323
return false, nil
2424
}
2525

26+
func toFloatPtr(line string) (*float32, error) {
27+
f, err := strconv.ParseFloat(line, 32)
28+
if err != nil {
29+
return nil, err
30+
}
31+
f32 := float32(f)
32+
return &f32, nil
33+
}
34+
2635
func csv(line string) (result []string) {
2736
for _, part := range strings.Split(line, ",") {
2837
result = append(result, strings.TrimSpace(part))
@@ -101,6 +110,11 @@ func isParam(line string, tool *types.Tool) (_ bool, err error) {
101110
if err != nil {
102111
return false, err
103112
}
113+
case "temperature":
114+
tool.Temperature, err = toFloatPtr(value)
115+
if err != nil {
116+
return false, err
117+
}
104118
default:
105119
return false, nil
106120
}

pkg/test/examples_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestExamples(t *testing.T) {
2020
RequireOpenAPIKey(t)
2121

2222
tests := []string{
23-
"fib.gpt",
23+
"fac.gpt",
2424
"helloworld.gpt",
2525
}
2626
for _, entry := range tests {

pkg/types/completion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type CompletionRequest struct {
1717
Tools []CompletionTool
1818
Messages []CompletionMessage
1919
MaxToken int
20+
Temperature *float32
2021
JSONResponse bool
2122
Cache *bool
2223
}

pkg/types/tool.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ type Tool struct {
2626
ToolMapping map[string]string `json:"toolMapping,omitempty"`
2727
BuiltinFunc BuiltinFunc `json:"-"`
2828

29-
Vision bool `json:"vision,omitempty"`
30-
MaxTokens int `json:"maxTokens,omitempty"`
31-
ModelName string `json:"modelName,omitempty"`
32-
JSONResponse bool `json:"jsonResponse,omitempty"`
33-
Cache *bool `json:"cache,omitempty"`
29+
Vision bool `json:"vision,omitempty"`
30+
MaxTokens int `json:"maxTokens,omitempty"`
31+
ModelName string `json:"modelName,omitempty"`
32+
JSONResponse bool `json:"jsonResponse,omitempty"`
33+
Temperature *float32 `json:"temperature,omitempty"`
34+
Cache *bool `json:"cache,omitempty"`
3435

3536
Source ToolSource `json:"source,omitempty"`
3637
}
@@ -61,6 +62,9 @@ func (t Tool) String() string {
6162
if t.Cache != nil && !*t.Cache {
6263
_, _ = fmt.Fprintln(buf, "Cache: false")
6364
}
65+
if t.Temperature != nil {
66+
_, _ = fmt.Fprintf(buf, "Temperature: %f", *t.Temperature)
67+
}
6468
if t.Arguments != nil {
6569
var keys []string
6670
for k := range t.Arguments.Properties {

0 commit comments

Comments
 (0)