alanhe421 / coding-note

note
3 stars 1 forks source link

AI服务API对比 #474

Open alanhe421 opened 1 year ago

alanhe421 commented 1 year ago

百度文心一言

虽然垃圾,但也有一定市场

https://cloud.baidu.com/doc/WENXINWORKSHOP/s/flfmc9do2

image

curl https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=【API Key】&client_secret=【Secret Key】

https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant

curl -XPOST https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions?access_token={access_token} -d '{
   "messages": [
    {"role":"user","content":"介绍一下你自己"}
   ]
}'
alanhe421 commented 1 year ago

星火

WebSocket通信

https://www.xfyun.cn/doc/spark/Web.html#_1-%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E

alanhe421 commented 1 year ago

OpenAI

curl https://api.openai.com/v1/engines/davinci-codex/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_OPENAI_API_KEY" \
-d '{
  "prompt": "Translate the following English text to French: '{}'",
  "max_tokens": 60
}'
alanhe421 commented 1 year ago

ChatGLM

https://github.com/THUDM/ChatGLM-6B/tree/main#api%E9%83%A8%E7%BD%B2

curl -X POST "http://127.0.0.1:8000" \
     -H 'Content-Type: application/json' \
     -d '{"prompt": "你好", "history": []}'
alanhe421 commented 11 months ago

通义千问

https://help.aliyun.com/zh/dashscope/developer-reference/api-details?spm=a2c4g.11186623.0.i0#341800c0f8w0r

import fetch from 'node-fetch';

fetch('https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer xxxxx',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    model: 'qwen-turbo',
    input: {
      messages: [
        {
          "role": "system",
          "content": "你是WebShell AI助手."
        },
        {
          "role": "user",
          "content": "如何安装szrz?"
        }
      ]
    },
    parameters: {
      result_format: 'message'
    }
  })
})
  .then(res=>res.json()).then(res => {
    return res.output.choices[0].message;
  }).then(console.log)
  .catch(console.error);