Skip to content

Commit

Permalink
feat: search scripts can be aborted by ctrl+C to avoid stuck
Browse files Browse the repository at this point in the history
  • Loading branch information
snowyu committed Aug 14, 2024
1 parent 5e02208 commit 55548f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ $ npm install -g @offline-ai/cli
$ ai COMMAND
running command...
$ ai (--version)
@offline-ai/cli/0.1.1 linux-x64 node-v20.14.0
@offline-ai/cli/0.1.2 linux-x64 node-v20.14.0
$ ai --help [COMMAND]
USAGE
$ ai COMMAND
Expand Down Expand Up @@ -318,7 +318,7 @@ EXAMPLES
$ ai agent publish <agent-name>
```

_See code: [src/commands/agent/index.ts](https://github.com/offline-ai/cli/blob/v0.1.1/src/commands/agent/index.ts)_
_See code: [src/commands/agent/index.ts](https://github.com/offline-ai/cli/blob/v0.1.2/src/commands/agent/index.ts)_

## `ai autocomplete [SHELL]`

Expand Down Expand Up @@ -393,7 +393,7 @@ EXAMPLES
$ ai brain download <brain-name>
```

_See code: [src/commands/brain/index.ts](https://github.com/offline-ai/cli/blob/v0.1.1/src/commands/brain/index.ts)_
_See code: [src/commands/brain/index.ts](https://github.com/offline-ai/cli/blob/v0.1.2/src/commands/brain/index.ts)_

## `ai brain dn [NAME]`

Expand Down Expand Up @@ -524,7 +524,7 @@ EXAMPLES
$ ai brain download <brain-name> [-q <QUANT>]
```

_See code: [src/commands/brain/download.ts](https://github.com/offline-ai/cli/blob/v0.1.1/src/commands/brain/download.ts)_
_See code: [src/commands/brain/download.ts](https://github.com/offline-ai/cli/blob/v0.1.2/src/commands/brain/download.ts)_

## `ai brain list [NAME]`

Expand Down Expand Up @@ -557,7 +557,7 @@ ALIASES
$ ai brain search
```

_See code: [src/commands/brain/list.ts](https://github.com/offline-ai/cli/blob/v0.1.1/src/commands/brain/list.ts)_
_See code: [src/commands/brain/list.ts](https://github.com/offline-ai/cli/blob/v0.1.2/src/commands/brain/list.ts)_

## `ai brain refresh`

Expand All @@ -581,7 +581,7 @@ DESCRIPTION
refresh brain index from huggingface.co
```

_See code: [src/commands/brain/refresh.ts](https://github.com/offline-ai/cli/blob/v0.1.1/src/commands/brain/refresh.ts)_
_See code: [src/commands/brain/refresh.ts](https://github.com/offline-ai/cli/blob/v0.1.2/src/commands/brain/refresh.ts)_

## `ai brain search [NAME]`

Expand Down Expand Up @@ -649,7 +649,7 @@ EXAMPLES
}
```

_See code: [src/commands/config/index.ts](https://github.com/offline-ai/cli/blob/v0.1.1/src/commands/config/index.ts)_
_See code: [src/commands/config/index.ts](https://github.com/offline-ai/cli/blob/v0.1.2/src/commands/config/index.ts)_

## `ai config save [DATA]`

Expand Down Expand Up @@ -690,7 +690,7 @@ GLOBAL FLAGS
--json Format output as json.
```

_See code: [src/commands/config/save.ts](https://github.com/offline-ai/cli/blob/v0.1.1/src/commands/config/save.ts)_
_See code: [src/commands/config/save.ts](https://github.com/offline-ai/cli/blob/v0.1.2/src/commands/config/save.ts)_

## `ai help [COMMAND]`

Expand Down Expand Up @@ -1052,7 +1052,7 @@ EXAMPLES
│[info]:Start Script: ...
```

_See code: [src/commands/run/index.ts](https://github.com/offline-ai/cli/blob/v0.1.1/src/commands/run/index.ts)_
_See code: [src/commands/run/index.ts](https://github.com/offline-ai/cli/blob/v0.1.2/src/commands/run/index.ts)_

## `ai test`

Expand Down Expand Up @@ -1100,7 +1100,7 @@ EXAMPLES
$ ai test -f ./fixture.yaml -l info
```

_See code: [src/commands/test/index.ts](https://github.com/offline-ai/cli/blob/v0.1.1/src/commands/test/index.ts)_
_See code: [src/commands/test/index.ts](https://github.com/offline-ai/cli/blob/v0.1.2/src/commands/test/index.ts)_

## `ai version`

Expand Down
8 changes: 6 additions & 2 deletions src/lib/run-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { AIScriptServer, LogLevel, LogLevelMap } from '@isdk/ai-tool-agent'
import { detectTextLanguage as detectLang } from '@isdk/detect-text-language'
import { prompt, setHistoryStore, HistoryStore } from './prompt.js'
// import { initTools } from './init-tools.js'
import { expandPath } from './load-config.js'

class AIScriptEx extends AIScriptServer {
$detectLang(text: string) {
Expand Down Expand Up @@ -97,8 +96,13 @@ export async function runScript(filename: string, options: IRunScriptOptions) {
}

let script
const aborter = new AbortController()
process.on('SIGINT', () => {
aborter.abort()}
)

try {
script = await AIScriptEx.loadFile(filename, {chatsDir: options.chatsDir})
script = await AIScriptEx.loadFile(filename, {chatsDir: options.chatsDir}, {ABORT_SEARCH_SCRIPTS_SIGNAL: aborter.signal})
} catch(err) {
console.error('Load script error:',err)
process.exit(1)
Expand Down

0 comments on commit 55548f5

Please sign in to comment.