Skip to content

Commit 1f83238

Browse files
committed
chore: update prompt types for more granular configuration
Signed-off-by: Donnie Adams <[email protected]>
1 parent 3248d6e commit 1f83238

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

src/gptscript.ts

+20-10
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,11 @@ export class GPTScript {
398398
return JSON.parse(result) as Array<DatasetMeta>
399399
}
400400

401-
async addDatasetElements(elements: Array<DatasetElement>, opts: {name?: string, description?: string, datasetID?: string}): Promise<string> {
401+
async addDatasetElements(elements: Array<DatasetElement>, opts: {
402+
name?: string,
403+
description?: string,
404+
datasetID?: string
405+
}): Promise<string> {
402406
const serializableElements = elements.map(e => {
403407
return {
404408
name: e.name,
@@ -1136,11 +1140,17 @@ export interface PromptFrame {
11361140
type: RunEventType.Prompt
11371141
time: string
11381142
message: string
1139-
fields: string[]
1143+
fields: Field[]
11401144
sensitive: boolean
11411145
metadata: Record<string, string>
11421146
}
11431147

1148+
export interface Field {
1149+
name: string
1150+
description?: string
1151+
sensitive?: boolean
1152+
}
1153+
11441154
export type Frame = RunFrame | CallFrame | PromptFrame
11451155

11461156
export interface AuthResponse {
@@ -1322,19 +1332,19 @@ export function createServer(listener: http.RequestListener<typeof http.Incoming
13221332
const gptscriptCertB64 = process.env.GPTSCRIPT_CERT
13231333

13241334
if (!certB64) {
1325-
console.log('Missing CERT env var')
1335+
console.log("Missing CERT env var")
13261336
process.exit(1)
13271337
} else if (!privateKeyB64) {
1328-
console.log('Missing PRIVATE_KEY env var')
1338+
console.log("Missing PRIVATE_KEY env var")
13291339
process.exit(1)
13301340
} else if (!gptscriptCertB64) {
1331-
console.log('Missing GPTSCRIPT_CERT env var')
1341+
console.log("Missing GPTSCRIPT_CERT env var")
13321342
process.exit(1)
13331343
}
13341344

1335-
const cert = Buffer.from(certB64, 'base64').toString('utf-8')
1336-
const privateKey = Buffer.from(privateKeyB64, 'base64').toString('utf-8')
1337-
const gptscriptCert = Buffer.from(gptscriptCertB64, 'base64').toString('utf-8')
1345+
const cert = Buffer.from(certB64, "base64").toString("utf-8")
1346+
const privateKey = Buffer.from(privateKeyB64, "base64").toString("utf-8")
1347+
const gptscriptCert = Buffer.from(gptscriptCertB64, "base64").toString("utf-8")
13381348

13391349
const options = {
13401350
key: privateKey,
@@ -1350,11 +1360,11 @@ export function createServer(listener: http.RequestListener<typeof http.Incoming
13501360
export function startServer(server: https.Server) {
13511361
const port = process.env.PORT
13521362
if (!port) {
1353-
console.log('Missing PORT env var')
1363+
console.log("Missing PORT env var")
13541364
process.exit(1)
13551365
}
13561366

1357-
server.listen(parseInt(port, 10), '127.0.0.1', () => {
1367+
server.listen(parseInt(port, 10), "127.0.0.1", () => {
13581368
console.log(`Server listening on port ${port}`)
13591369
})
13601370
}

tests/gptscript.test.ts

+17-16
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe("gptscript module", () => {
116116

117117
expect(run).toBeDefined()
118118
expect(await run.text()).toContain("Understood.")
119-
})
119+
}, 10000)
120120

121121
test("evaluate executes and streams a prompt correctly", async () => {
122122
let out = ""
@@ -129,7 +129,7 @@ describe("gptscript module", () => {
129129
}
130130

131131
const run = await g.evaluate(t, opts)
132-
run.on(gptscript.RunEventType.CallProgress, (data: gptscript.CallFrame) => {
132+
run.on(gptscript.RunEventType.CallFinish, data => {
133133
for (let output of data.output) out += `system: ${output.content}`
134134
})
135135

@@ -210,10 +210,11 @@ describe("gptscript module", () => {
210210
}
211211

212212
const run = await g.run(testGptPath, opts)
213-
run.on(gptscript.RunEventType.CallProgress, data => {
213+
run.on(gptscript.RunEventType.CallFinish, data => {
214214
for (let output of data.output) out += `system: ${output.content}`
215215
})
216-
await run.text()
216+
217+
expect(await run.text()).toContain("Calvin Coolidge")
217218
err = run.err
218219

219220
for (let c in run.calls) {
@@ -231,23 +232,21 @@ describe("gptscript module", () => {
231232

232233
test("run executes and streams a file with global tools correctly", async () => {
233234
let out = ""
234-
let err = undefined
235235
const testGptPath = path.join(__dirname, "fixtures", "global-tools.gpt")
236236
const opts = {
237237
disableCache: true,
238238
credentialOverrides: ["github.com/gptscript-ai/gateway:OPENAI_API_KEY"]
239239
}
240240

241241
const run = await g.run(testGptPath, opts)
242-
run.on(gptscript.RunEventType.CallProgress, data => {
242+
run.on(gptscript.RunEventType.CallFinish, data => {
243243
for (let output of data.output) out += `system: ${output.content}`
244244
})
245-
await run.text()
246-
err = run.err
247245

246+
expect(await run.text()).toContain("Hello!")
247+
expect(run.err).toEqual("")
248248
expect(out).toContain("Hello!")
249-
expect(err).toEqual("")
250-
}, 30000)
249+
}, 60000)
251250

252251
test("aborting a run is reported correctly", async () => {
253252
let errMessage = ""
@@ -627,7 +626,7 @@ describe("gptscript module", () => {
627626
expect(await run.text()).toContain("Lake Huron")
628627
expect(run.err).toEqual("")
629628
expect(run.state).toEqual(gptscript.RunState.Continue)
630-
}, 10000)
629+
}, 15000)
631630

632631
test("nextChat on tool providing chat state", async () => {
633632
const t = {
@@ -651,7 +650,7 @@ describe("gptscript module", () => {
651650
expect(await run.text()).toContain("Austin")
652651
expect(run.err).toEqual("")
653652
expect(run.state).toEqual(gptscript.RunState.Continue)
654-
}, 10000)
653+
}, 15000)
655654

656655
test("confirm", async () => {
657656
const t = {
@@ -702,11 +701,11 @@ describe("gptscript module", () => {
702701
run.on(gptscript.RunEventType.Prompt, async (data: gptscript.PromptFrame) => {
703702
expect(data.message).toContain("first name")
704703
expect(data.fields.length).toEqual(1)
705-
expect(data.fields[0]).toEqual("first name")
704+
expect(data.fields[0].name).toEqual("first name")
706705
expect(data.sensitive).toBeFalsy()
707706

708707
promptFound = true
709-
await g.promptResponse({id: data.id, responses: {[data.fields[0]]: "Clicky"}})
708+
await g.promptResponse({id: data.id, responses: {[data.fields[0].name]: "Clicky"}})
710709
})
711710

712711
expect(await run.text()).toContain("Clicky")
@@ -722,12 +721,12 @@ describe("gptscript module", () => {
722721
})
723722
run.on(gptscript.RunEventType.Prompt, async (data: gptscript.PromptFrame) => {
724723
expect(data.fields.length).toEqual(1)
725-
expect(data.fields[0]).toEqual("first name")
724+
expect(data.fields[0].name).toEqual("first name")
726725
expect(data.metadata).toEqual({key: "value"})
727726
expect(data.sensitive).toBeFalsy()
728727

729728
promptFound = true
730-
await g.promptResponse({id: data.id, responses: {[data.fields[0]]: "Clicky"}})
729+
await g.promptResponse({id: data.id, responses: {[data.fields[0].name]: "Clicky"}})
731730
})
732731

733732
expect(await run.text()).toContain("Clicky")
@@ -968,6 +967,8 @@ describe("gptscript module", () => {
968967
} catch (e) {
969968
throw new Error("failed to list datasets: " + e)
970969
}
970+
971+
client.close()
971972
}, 60000)
972973

973974
test("create and delete workspace", async () => {

0 commit comments

Comments
 (0)