0.6.3 • Published 7 months ago

@zhengxs/ernie-api v0.6.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

banner


一个 文心一言 封装,提供快速接入的能力。

安装

# With NPM
$ npm i -S @zhengxs/ernie-api

# With Yarn
$ yarn add @zhengxs/ernie-api

# With PNPM
$ pnpm add @zhengxs/ernie-api

示例

CLI 聊天

设置 ERNIE_BOT_COOKIE 环境变量可以不用传递 cookie。

# 开始聊天
$ erniebot

# or
$ erniebot --cookie xxxxxxx

提示: 输入 /new 可以开启新对话,输入 /exit 退出聊天

教程

简单对话

import { ErnieAPI } from '@zhengxs/ernie-api'

const api = new ErnieAPI({
  // 文心一言的 Cookie
  cookie: 'BDUSS=xxxxxxxxxxxxxxxxxx;',
})

const res = await api.createChatConversation({
  text: '你好',
})

console.log('Ernie BOT:', res.text)

连续对话

传递 sessionIdparentChatId 参数,可以保持聊天上下文,激活连续对话的能力。

const res = await api.createChatConversation({
  text: '你好',
})

console.log('Ernie BOT:', res.text)

const res2 = await api.createChatConversation({
  sessionId: res.sessionId,
  parentChatId: res.id,
  text: '我刚刚说了什么?',
})

console.log('Ernie BOT:', res2.text)

画图

图片的地址可以通过 content 获取。

const res = await api.createChatConversation({
  text: '画一只鸟',
})

// 图片链接
console.log(res.content)

插件

参考 插件列表

使用插件

import { ErnieAPI } from '@zhengxs/ernie-api'

const res = await api.createChatConversation({
  text: '北京智者天下科技有限公司的股东是谁?',
  plugins: [ErnieAPI.plugins.aiQiCha],
})

插件列表

ID名称描述
aiQiCha商业信息查询爱企查提供商业信息检索能力,可用于查企业工商/上市等信息、查老板任职/投资情况
chatFile览卷文档原ChatFile,可基于文档完成摘要、问答、创作等任务,仅支持10MB以内文档,不支持扫描件
eChartE言易图基于 Apache ECharts 为您提供数据洞察和图表制作,目前支持柱状图、折线图、饼图、雷达图、散点图、漏斗图、思维导图(树图)
imageAI说图解画基于图片进行文字创作、回答问题,帮你写文案、想故事。暂仅支持10MB以内的图片
treeMindTreeMind树图思维导图软件,支持脑图、逻辑图、树形图、鱼骨图、组织架构图、时间轴、时间线等多种专业格式

License

MIT

0.6.3

7 months ago

0.6.2

7 months ago

0.6.1

7 months ago

0.6.0

7 months ago

0.5.6

7 months ago

0.5.5

7 months ago

0.5.4

7 months ago

0.5.3

7 months ago

0.5.2

7 months ago

0.5.1

7 months ago

0.5.0

7 months ago

0.4.0

7 months ago

0.3.1

7 months ago

0.3.0

7 months ago

0.2.0

7 months ago

0.1.0

7 months ago