Skip to content

Commit

Permalink
Update type definition to include updated openai v4 types. (#458)
Browse files Browse the repository at this point in the history
Co-authored-by: Max Leiter <max.leiter@vercel.com>
  • Loading branch information
mosnicholas and MaxLeiter committed Aug 16, 2023
1 parent 799e385 commit 04084a8
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 440 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-carpets-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ai': patch
---

openai-stream: fix experimental_onFunctionCall types for OpenAI SDK v4
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/action-setup@v2.2.2
with:
version: 8.6.3
version: 8.6.9

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 8.6.3
version: 8.6.9

- name: Use Node.js 18
uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup pnpm 8
uses: pnpm/action-setup@v2
with:
version: 8.6.3
version: 8.6.9

- name: Setup Node.js 18.x
uses: actions/setup-node@v2
Expand Down
2 changes: 1 addition & 1 deletion examples/next-openai-rate-limits/app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Ratelimit } from '@upstash/ratelimit'

// Create an OpenAI API client (that's edge friendly!)
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY
apiKey: process.env.OPENAI_API_KEY || ''
})

// IMPORTANT! Set the runtime to edge
Expand Down
2 changes: 1 addition & 1 deletion examples/next-openai/app/api/chat-with-functions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import OpenAI from 'openai'
import { CompletionCreateParams } from 'openai/resources/chat'
// Create an OpenAI API client (that's edge friendly!)
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY
apiKey: process.env.OPENAI_API_KEY || ''
})

// IMPORTANT! Set the runtime to edge
Expand Down
2 changes: 1 addition & 1 deletion examples/next-openai/app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { OpenAIStream, StreamingTextResponse } from 'ai'

// Create an OpenAI API client (that's edge friendly!)
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY
apiKey: process.env.OPENAI_API_KEY || ''
})

// IMPORTANT! Set the runtime to edge
Expand Down
3 changes: 2 additions & 1 deletion examples/nuxt-openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
"@vue/shared": "^3.3.4",
"ai": "2.2.0",
"nuxt": "^3.6.5",
"openai": "4.0.0",
"tailwindcss": "^3.3.3",
"ufo": "^1.2.0",
"unctx": "^2.3.1",
"openai": "4.0.0",
"vue": "^3.3.4"
}
}
2 changes: 1 addition & 1 deletion examples/solidstart-openai/src/routes/api/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { APIEvent } from 'solid-start/api'

// Create an OpenAI API client
const openai = new OpenAI({
apiKey: process.env['OPENAI_API_KEY']
apiKey: process.env['OPENAI_API_KEY'] || ''
})

export const POST = async (event: APIEvent) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/sveltekit-openai/src/routes/api/chat/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { RequestHandler } from './$types'

// Create an OpenAI API client
const openai = new OpenAI({
apiKey: env.OPENAI_API_KEY
apiKey: env.OPENAI_API_KEY || ''
})

export const POST = (async ({ request }) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"keywords": [
"ai"
],
"packageManager": "pnpm@8.6.3",
"packageManager": "pnpm@8.6.9",
"prettier": {
"tabWidth": 2,
"semi": false,
Expand Down
4 changes: 3 additions & 1 deletion packages/core/streams/openai-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export type OpenAIStreamCallbacks = AIStreamCallbacks & {
createFunctionCallMessages: (
functionCallResult: JSONValue
) => CreateMessage[]
) => Promise<Response | undefined | void | string>
) => Promise<
Response | undefined | void | string | AsyncIterable<ChatCompletionChunk>
>
}

// https://github.com/openai/openai-node/blob/07b3504e1c40fd929f4aae1651b83afc19e3baf8/src/resources/chat/completions.ts#L28-L40
Expand Down

0 comments on commit 04084a8

Please sign in to comment.