# spark-desk

> 使用WebSocket调用 讯飞星火认知大模型 的js库

Latest version **2.0.1** (published 2024-12-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install spark-desk
pnpm add spark-desk
yarn add spark-desk
bun add spark-desk
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2024-12-26 |
| First published | 2023-08-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 51.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | 自由如风 |
| Maintainers | ting-xing |
| Keywords | 星火大模型, SparkDesk, 人工智能, AI |

## Links

- npm: https://www.npmjs.com/package/spark-desk
- Repository: https://github.com/ting-xing/spark-desk
- Homepage: https://github.com/ting-xing/spark-desk#readme
- Issues: https://github.com/ting-xing/spark-desk/issues
- npm.io page: https://npm.io/package/spark-desk

## Dependencies (3)

- [ws](https://npm.io/package/ws.md) ^8.13.0
- [axios](https://npm.io/package/axios.md) ^1.7.9
- [crypto-js](https://npm.io/package/crypto-js.md) ^4.1.1

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2024-12-26
- 2.0.0 — 2024-12-26
- 1.4.1 — 2024-05-07
- 1.4.0 — 2024-05-07
- 1.3.1 — 2024-05-06
- 1.2.0 — 2023-10-25
- 1.1.0 — 2023-09-07
- 1.0.5 — 2023-09-05
- 1.0.4 — 2023-08-28
- 1.0.3 — 2023-08-28
- 1.0.2 — 2023-08-28
- 1.0.1 — 2023-08-28

## README

## spark-desk

这是一个使用HTTP/WebSocket调用 [讯飞星火认知大模型](https://xinghuo.xfyun.cn/sparkapi)
的js库。

1. 使用 typescript
2. 支持 cjs 和 esm
3. 面向对象
4. 支持所有版本接口
5. 支持在浏览器、nodejs里运行
6. 支持 Http 和 Websocket 方式使用

### 简单尝试

前往 [在线样例](https://ting-xing.github.io/spark-desk-example/)

### 在您的项目里使用

#### 使用 Websocket

```ts
import {Version, WebsocketSparkDesk} from 'spark-desk'

const sparkDesk = new WebsocketSparkDesk({
    APPID: "a5fxxxxxx",
    APISecret: "MGIxNTcwNDI4MGY1YjUxM2Mxxxxxxx",
    APIKey: "aa5fbf57f7818bd1cec61dexxxxxxxx",
    version: Version.Ultra
});

const user = sparkDesk.createUser("张三");

user.speak("你好!很高兴认识你。").then(answer => console.log(answer.content))
```

#### 使用 HTTP

```ts
import {Version, HttpSparkDesk} from 'spark-desk'

const sparkDesk = new HttpSparkDesk({
    APIPassword: "qNuVTubjjhxxxxxxx:lPktJLLhrxxxxxxxx",
    version: Version.Ultra
});

const user = sparkDesk.createUser("张三");

user.speak("你好!很高兴认识你。").then(answer => console.log(answer.content))
```

### 更多参数

```ts
import {WebsocketSparkDesk} from "./WebsocketSparkDesk";
import {HttpSparkDesk} from "./HttpSparkDesk";

const websocketSparkDesk = new WebsocketSparkDesk(/*配置*/);

websocketSparkDesk.request({
    // websocket 参数 
    // https://www.xfyun.cn/doc/spark/Web.html#_1-%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E
}) // 返回 WebsocketResponseImpl 对象

const httpSparkDesk = new HttpSparkDesk(/*配置*/);

httpSparkDesk.request({
    // http 参数
    // https://www.xfyun.cn/doc/spark/HTTP%E8%B0%83%E7%94%A8%E6%96%87%E6%A1%A3.html#_3-%E8%AF%B7%E6%B1%82%E8%AF%B4%E6%98%8E
}) // 返回 AxiosResponse

```

### 底层实现

| 环境      | HTTP模式 | websocket模式 |
 |---------|--------|-------------|
| node    | axios  | ws库         |
| browser | axios  | 原生Websocket |

#### 本项目开发环境

| 名称       | 版本              |
|----------|-----------------|
| nodejs   | v18.19.1        |
| npm      | 10.2.4          |
| OS       | Windows 11 专业版  |
| webstorm | WebStorm 2023.2 |

---
_Source: https://npm.io/package/spark-desk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
