开放API调用了,通过API实现各类脑洞的时刻


在3月2号,OpenAI公开了ChatGPT相关的API,可以通过API实现对ChatGPT的调用了。

POST https://api.openai.com/v1/chat/completions

curl https://api.openai.com/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -d '{
  "model": "gpt-3.5-turbo",
  "messages": [{"role": "user", "content": "Hello!"}]
}'

import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")

completion = openai.ChatCompletion.create(
  model="gpt-3.5-turbo",
  messages=[
    {
    
    "role": "user", "content": "Hello!"}
  ]
)

print(completion.choices[0].message)

const {
    
     Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
    
    
  apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const completion = await openai.createChatCompletion({
    
    
  model: "gpt-3.5-turbo",
  messages: [{
    
    role: "user", content: "Hello world"}],
});
console.log(completion.data.choices[0].message);

猜你喜欢

转载自blog.csdn.net/wwlsm_zql/article/details/129298757
今日推荐