开发者快速入门

5分钟即可将GPT-5.6的强大能力集成到您的应用中。

准备工作

在开始之前,请确保您已具备以下条件:

  • ChatGPT Work账号(立即注册
  • API Key(在开发者设置中生成)
  • Python 3.8+ 或 Node.js 16+

步骤一:安装SDK

Python

pip install chatgpt-work

JavaScript

npm install @chatgpt-work/sdk

步骤二:发起第一次请求

Python

from chatgpt_work import ChatGPTWork

client = ChatGPTWork(api_key="your-api-key")

response = client.chat.completions.create(
    model="gpt-5.6-pro",
    messages=[
        {"role": "user", "content": "你好,请介绍一下GPT-5.6"}
    ]
)

print(response.choices[0].message.content)

JavaScript

import { ChatGPTWork } from '@chatgpt-work/sdk';

const client = new ChatGPTWork({ apiKey: 'your-api-key' });

const response = await client.chat.completions.create({
  model: 'gpt-5.6-pro',
  messages: [
    { role: 'user', content: '你好,请介绍一下GPT-5.6' }
  ]
});

console.log(response.choices[0].message.content);

步骤三:使用流式输出

流式输出可以提供更好的用户体验,文字会逐字显示:

import { ChatGPTWork } from '@chatgpt-work/sdk';

const client = new ChatGPTWork({ apiKey: 'your-api-key' });

const stream = await client.chat.completions.create({
  model: 'gpt-5.6-pro',
  messages: [{ role: 'user', content: '写一个Python快速排序' }],
  stream: true
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '');
}

步骤四:使用Function Calling

让AI调用您的自定义函数:

const tools = [{
  type: 'function',
  function: {
    name: 'get_weather',
    description: '获取指定城市的天气',
    parameters: {
      type: 'object',
      properties: {
        city: { type: 'string', description: '城市名称' }
      },
      required: ['city']
    }
  }
}];

const response = await client.chat.completions.create({
  model: 'gpt-5.6-pro',
  messages: [{ role: 'user', content: '北京今天天气怎么样?' }],
  tools
});

// AI会返回需要调用的函数和参数
const toolCall = response.choices[0].message.tool_calls[0];
console.log(toolCall.function.name); // "get_weather"
console.log(toolCall.function.arguments); // {"city": "北京"}

下一步

恭喜!您已成功接入ChatGPT Work API。接下来可以探索: