# DuckAGI接入文档（中文版）

接入方式和OpenAI的一致。[点击前往OpenAI开发者平台](https://platform.openai.com/docs/guides/text-generation/chat-completions-api)

##

## 在官方OpenAI库中使用（python）

```
openai.api_base = 'https://api.duckagi.com/v1'
openai.api_key = 'sk-xxxxxxxxxxx'

messages = [
    {"role": "user", "content": "你好"}
]

res = openai.ChatCompletion.create(
    model="gpt-4",
    messages=messages,
    stream=False,
)

print(res['choices'][0]['message']['content'])
```

## DALL-E

```
openai.api_base = 'https://api.duckagi.com/v1'
openai.api_key = 'sk-xxxxxxxxxxx'

res = openai.Image.create(
    prompt='Cat'
)
print(res)
```

1、生成令牌

<figure><img src="https://910671140-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLG4bCkCR3yAI7oAAjGlx%2Fuploads%2FqD7avATU9OsfAcsOPcTh%2Fimage.png?alt=media&#x26;token=9f42b80a-71be-4562-9d96-c47f8a872daa" alt=""><figcaption></figcaption></figure>

2.在聊天栏目的设置中填入信息进行测试

<figure><img src="https://910671140-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLG4bCkCR3yAI7oAAjGlx%2Fuploads%2FAKKFiq0sVyncW6KoTVeE%2Fimage.png?alt=media&#x26;token=2f26dd70-8fec-4840-be0b-f9eb1db580a9" alt=""><figcaption></figcaption></figure>

3.成功

<figure><img src="https://910671140-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLG4bCkCR3yAI7oAAjGlx%2Fuploads%2FREcnT9YP5xa891qeNrTL%2Fimage.png?alt=media&#x26;token=091bca14-68c7-49e2-bfc4-34868531731b" alt=""><figcaption></figcaption></figure>
