Skip to content

informat.aiagent 相关

概述

使用informat.aiagent执行ai助手相关操作


informat.aiagent.chatCompletions

允许向人工智能模型提供部分输入并获取自然、连贯的完成文本的技术。接口可以用于各种应用,包括文本生成、语言翻译、问题回答等等

javascript
let result=informat.aiagent.chatCompletions(setting);
参数类型描述
settingOpenAIChatSettingopenAiChat配置信息

返回值 类型为InformatAIChatResp

示例1 普通文字对话

javascript

let result=informat.aiagent.chatCompletions({
    'url':'https://api.openai.com/v1/chat/completions',
    'model':'gpt-4o',
    'apiKey':'sk-xxxxxxxx',
    'messages':[{"role":"user","content":"地球有多大?"}]
});

返回值如下

json
{
  "choices":[
    {
      "finish_reason":"stop",
      "index":0,
      "message":{
        "content":"地球的大小可以通过其直径、周长和表面积来描述。1.**赤道直径**:大约12,742千米(7,918英里)。2.**极地直径**:大约12,714千米(7,900英里),由于地球是一个扁球体,所以赤道直径稍大于极地直径。3.**赤道周长**:大约40,075千米(24,901英里)。4.**表面积**:大约5.1亿平方千米(1.97亿平方英里)。这些数据表明,地球是一个中等大小的行星,与我们太阳系中的其他行星相比,地球的大小适中。",
        "role":"assistant"
      }
    }
  ],
  "created":1743407834,
  "id":"chatcmpl-BH4J8JNKpbj01hfpFNuohZOtvH5XF",
  "model":"gpt-4o-2024-08-06",
  "object":"chat.completion",
  "usage":{
    "completion_tokens":167,
    "prompt_tokens":13,
    "total_tokens":180
  }
}

示例2 识别发票内容(文字和图片对话)

javascript
let data=automatic.getVar('data');//监听发票附件变更事件
let filePath=data.content.formRecord.attachment.path;//发票图片附件存储路径
let base64Image=informat.storage.getBase64Content(filePath);//获取发票图片base64编码
let content=[
    {"text":"分析这张发票内容,返回包含以下字段的JSON数据:发票代码、发票号码、开票日期、销售方名称、购买方名称、购买方纳税人识别号、金额、税率。注意:返回值不包含```json,必须是一个完整的json字符串","type":"text"},
    {"image_url":{"url":"data:image/jpeg;base64,"+base64Image},"type":"image_url"}
]
let message={}
message.role='user';
message.content=content;
let result=informat.aiagent.chatCompletions({
    'url':'https://api.openai.com/v1/chat/completions',
    'model':'gpt-4o',
    'apiKey':'sk-xxxxxxxxxx',
    'messages':[message]
});
let json=result.choices[0].message.content;
let invoice=JSON.parse(json);
console.log('开票日期',invoice['开票日期'])
invoice['开票日期']=informat.date.parseDate(invoice['开票日期'])
console.log('invoice',invoice)

返回值如下

json
{
  "发票代码": "033001700211",
  "发票号码": "56894556",
  "开票日期": "2019年01月08日",
  "销售方名称": "深圳市XXX服务有限公司",
  "购买方名称": "深圳市基石协作科技有限公司",
  "购买方纳税人识别号": "913101X5768225450X",
  "金额": "66.97",
  "税率": "***"
}

informat.aiagent.completions

允许向人工智能模型提供部分输入并获取自然、连贯的完成文本的技术。接口可以用于各种应用,包括文本生成、语言翻译、问题回答等等

javascript
let result=informat.aiagent.completions(
	'aiagent',
	[{type:"text",text:"centos 怎么安装pgsql"}]
);
参数类型描述
moduleIdStringAI助手标识符
messageListArray<InformatAiagentContentMessage>提示词或图片列表

返回值 类型为InformatAIChatResp

示例

javascript
let result=informat.aiagent.completions('aiagent',[{"type":"text","text":"centos7 怎么安装pgsql"}]);

返回值如下

json
{
  "choices":[
    {
      "finish_reason":"stop",
      "index":0,
      "message":{
        "content":"在CentOS7上安装PostgreSQL可以通过以下步骤完成:\n\n1.更新系统和安装必要的软件包:\n```\nsudoyumupdate\nsudoyuminstallepel-release\nsudoyuminstallpostgresql-serverpostgresql-contrib\n```\n\n2.初始化PostgreSQL数据库:\n```\nsudopostgresql-setupinitdb\n```\n\n3.启动PostgreSQL服务并设置开机自动启动:\n```\nsudosystemctlstartpostgresql\nsudosystemctlenablepostgresql\n```\n\n4.设置PostgreSQL用户密码:\n```\nsudo-i-upostgres\npsql\n\\passwordpostgres\n```\n\n5.修改PostgreSQL配置文件以允许远程连接(如果需要):\n```\nsudonano/var/lib/pgsql/data/pg_hba.conf\n```\n在文件末尾添加以下行:\n```\nhostallall0.0.0.0/0md5\n```\n保存并退出文件,然后重新启动PostgreSQL服务:\n```\nsudosystemctlrestartpostgresql\n```\n\n现在你已经成功在CentOS7上安装并配置了PostgreSQL。你可以使用psql命令连接到数据库,并开始使用它了。",
        "role":"assistant"
      }
    }
  ],
  "created":1715674313,
  "id":"chatcmpl-9OhYH4Wu4kdrhtGIHbnwt2Xf971LZ",
  "model":"gpt-3.5-turbo-0125",
  "object":"chat.completion",
  "usage":{
    "completion_tokens":265,
    "prompt_tokens":16,
    "total_tokens":281
  }
}

queryThreadList

查询会话列表

javascript
informat.aiagent.queryThreadList(query)
参数类型描述
queryQuery查询条件

返回值

类型为Array<AiAgentThread> 返回会话列表

queryThreadListCount

查询会话列表总数

javascript
informat.aiagent.queryThreadListCount(filter)
参数类型描述
filterFilter过滤器

返回值

类型为int 返回会话列表总数

queryThreadMessageList

查询会话消息列表

javascript
informat.aiagent.queryThreadMessageList(query)
参数类型描述
queryQuery查询条件

返回值

类型为Array<AiAgentThreadMessage> 返回会话消息列表

queryThreadMessageListCount

查询会话消息列表总数

javascript
informat.aiagent.queryThreadMessageListCount(filter)
参数类型描述
filterFilter过滤器

返回值

类型为int 返回会话列表总数