项目地址

项目截图

优质回答的标准是什么_优质回答的经验和感受_优质回答经验感受与收获

优质回答的标准是什么_优质回答的经验和感受_优质回答经验感受与收获

优质回答的经验和感受_优质回答的标准是什么_优质回答经验感受与收获

优质回答的经验和感受_优质回答经验感受与收获_优质回答的标准是什么

优质回答的经验和感受_优质回答经验感受与收获_优质回答的标准是什么

使用技术栈

node+SQLite+redis+nginx+log4js+express+jenkins+cdn+react+antd+react-scrollbars-custom+iconfont+webpack+postman+axios+redux+immutable+npm+yarn+openai等等

官网

优质回答的经验和感受_优质回答的标准是什么_优质回答经验感受与收获

官方聊天应用

优质回答的标准是什么_优质回答的经验和感受_优质回答经验感受与收获

官方Javascript沙盒应用

优质回答经验感受与收获_优质回答的经验和感受_优质回答的标准是什么

官方技术文档

优质回答的标准是什么_优质回答经验感受与收获_优质回答的经验和感受

node调用ChatGPT的API

装包:

yarn add openai

获取API Keys:

优质回答的标准是什么_优质回答经验感受与收获_优质回答的经验和感受

优质回答的标准是什么_优质回答经验感受与收获_优质回答的经验和感受

获取Organization ID:

优质回答的经验和感受_优质回答经验感受与收获_优质回答的标准是什么

优质回答的标准是什么_优质回答经验感受与收获_优质回答的经验和感受

node代码:

const { Configuration, OpenAIApi } = require('openai')
const configuration = new Configuration({
  organization: 'xxx',
  apiKey: 'xxx',
})
const openai = new OpenAIApi(configuration)
//增加
const chatAdd = async (req, res) => {
  const {
    talkId = '',
    name = '',
    messageType = '1',
    message = '',
    modelType = '1',
    promptType = '1',
  } = req.body
  const uid = uuidv4()
  const now = Date.now()
  const talkRedis = await redisClient.get('talk')
  let talkList = JSON.parse(talkRedis)
  const resultIndex = talkList.findIndex((item) => item.uid === talkId)
  if (resultIndex >= 0) {
    if (message && message.trim() !== '') {
      const chatRedis = await redisClient.get('chat')
      let chatList = JSON.parse(chatRedis)
      chatList = Array.isArray(chatList) ? chatList : []
      let currentChatList = chatList
        .filter((item) => item.talkId === talkId)
        .sort((a, b) => a.createTime - b.createTime)
      let prompt = ''
      if (promptType === '1') {
        if (currentChatList.length > 0) {
          let shotChatList = currentChatList
          if (currentChatList.length > 10) {
            shotChatList = currentChatList.slice(currentChatList.length - 10)
          }
          shotChatList.forEach((item) => {
            let { messageType, message } = item
            if (messageType === '1') {
              prompt += `YOU:${message}\n`
            } else if (messageType === '2') {
              //message = encodeURIComponent(message)
              prompt += `${message}\n`
            }
          })
        }
        prompt += `YOU:${message}\n`
      } else if (promptType === '2') {
        if (currentChatList.length > 0) {
          let shotChatList = currentChatList
          if (currentChatList.length > 10) {
            shotChatList = currentChatList.slice(currentChatList.length - 10)
          }          
          shotChatList.forEach((item) => {
            const { messageType, message } = item
            if (messageType === '1') {
              prompt += `\n/* Command: ${message} */\n`
            } else if (messageType === '2') {
              //message = encodeURIComponent(message)
              prompt += `${message}\n`
            }
          })
        }
        prompt += `<|endoftext|>/* I start with a blank HTML page, and incrementally modif it via