Skip to content

Commit

Permalink
fix abort
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jul 16, 2024
1 parent 0cb01b1 commit d014e23
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
6 changes: 5 additions & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ import {
errorMessage,
isRequestError,
RequestError,
serializeError,
} from "../../core/src/error"
import { CORE_VERSION, GITHUB_REPO } from "../../core/src/version"
import { grep } from "./grep"
import { logVerbose } from "../../core/src/util"

export async function cli() {
process.on("uncaughtException", (err) => {
error(isQuiet ? err : errorMessage(err))
const se = serializeError(err)
error(errorMessage(se))
if (!isQuiet && se?.stack) logVerbose(se?.stack)
if (isRequestError(err)) {
const exitCode = (err as RequestError).status
process.exit(exitCode)
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
runtimeHost,
} from "../../core/src/host"
import { MarkdownTrace, TraceChunkEvent } from "../../core/src/trace"
import { logVerbose, logError } from "../../core/src/util"
import { logVerbose, logError, assert } from "../../core/src/util"
import { CORE_VERSION } from "../../core/src/version"
import { YAMLStringify } from "../../core/src/yaml"
import {
Expand Down Expand Up @@ -216,6 +216,11 @@ export async function startServer(options: { port: string }) {
delete runs[runId]
run.canceller.abort(reason)
}
response = <ResponseStatus>{
ok: true,
status: 0,
runId,
}
break
}
case "shell.exec": {
Expand All @@ -240,6 +245,7 @@ export async function startServer(options: { port: string }) {
} catch (e) {
response = { ok: false, error: serializeError(e) }
} finally {
assert(!!response)
if (response.error) logError(response.error)
ws.send(JSON.stringify({ id, response }))
}
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export async function parseTokenFromEnv(
throw new Error(
"AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_BASE or AZURE_API_BASE missing"
)
base = base.replace(/\/openai\/deployments.*$/g, "") + `/openai/deployments`
if (!URL.canParse(base))
throw new Error("AZURE_OPENAI_ENDPOINT must be a valid URL")
const version =
Expand All @@ -116,8 +117,6 @@ export async function parseTokenFromEnv(
throw new Error(
`AZURE_OPENAI_API_VERSION must be '${AZURE_OPENAI_API_VERSION}'`
)
if (!base.endsWith("/openai/deployments"))
base += "/openai/deployments"
return {
provider,
model,
Expand Down
11 changes: 2 additions & 9 deletions packages/sample/genaisrc/azure.genai.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
script({
title: "azure summarize",
system: [],
model: "azure:gpt-4"
model: "azure:gpt-3.5-turbo"
})

def("FILE", env.files)

$`
Summarize each file with one paragraph.
Be concise.
Answer in plain text.
`
$`write a poem.`

0 comments on commit d014e23

Please sign in to comment.