Skip to content

Commit

Permalink
📝 docs: 更新ChatGPT 的错误demo示例 (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
ONLY-yours authored Feb 4, 2024
1 parent d0f0e82 commit f6ee50c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion demos/chatgpt-nextjs/src/app/api/openai/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ export async function POST(request: Request) {
baseURL: 'base url', // if u dont need change baseUrl,you can delete this line
});

const PickMessages = messages.map((message) => {
return {
role: message.role,
content: message.content,
};
});

const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: [...messages],
messages: [...PickMessages],
stream: true,
});

Expand Down
9 changes: 9 additions & 0 deletions docs/guide/chatgpt.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ bun add openai

我们借助 Vercel 的库来解析 数据流,不需要自己手动配置 Reader

> 这里我们需要将 role 和 content 组合一下,因为 messages 包含的内容会更多一些,但是对于 ChatGPT 来说只需要这两个内容
```ts
import OpenAI from 'openai';
import { OpenAIStream, StreamingTextResponse } from 'ai';
Expand All @@ -45,6 +47,13 @@ export const POST = async (request: Request) => {
baseURL: 'base url',
});

const PickMessages = messages.map((message) => {
return {
role: message.role,
content: message.content,
};
});

const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: [...messages],
Expand Down

0 comments on commit f6ee50c

Please sign in to comment.