Comparing version 2.2.10 to 2.2.11
@@ -336,3 +336,5 @@ "use strict"; | ||
} | ||
var __internal__OpenAIFnMessagesSymbol = Symbol("internal_openai_fn_messages"); | ||
var __internal__OpenAIFnMessagesSymbol = Symbol( | ||
"internal_openai_fn_messages" | ||
); | ||
function isChatCompletionChunk(data) { | ||
@@ -339,0 +341,0 @@ return "choices" in data && data.choices && data.choices[0] && "delta" in data.choices[0]; |
@@ -336,3 +336,5 @@ "use strict"; | ||
} | ||
var __internal__OpenAIFnMessagesSymbol = Symbol("internal_openai_fn_messages"); | ||
var __internal__OpenAIFnMessagesSymbol = Symbol( | ||
"internal_openai_fn_messages" | ||
); | ||
function isChatCompletionChunk(data) { | ||
@@ -339,0 +341,0 @@ return "choices" in data && data.choices && data.choices[0] && "delta" in data.choices[0]; |
{ | ||
"name": "ai", | ||
"version": "2.2.10", | ||
"version": "2.2.11", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -209,3 +209,3 @@ import { ChatCompletionMessage, CompletionCreateParams, CreateChatCompletionRequestMessage } from 'openai/resources/chat'; | ||
}; | ||
declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, experimental_onFunctionCall, onResponse, onFinish, onError, credentials, headers, body }?: UseChatOptions): UseChatHelpers; | ||
declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, experimental_onFunctionCall, onResponse, onFinish, onError, credentials, headers, body, }?: UseChatOptions): UseChatHelpers; | ||
@@ -254,3 +254,3 @@ type UseCompletionHelpers = { | ||
}; | ||
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, onResponse, onFinish, onError }?: UseCompletionOptions): UseCompletionHelpers; | ||
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers; | ||
@@ -257,0 +257,0 @@ export { CreateMessage, Message, UseChatHelpers, UseChatOptions, UseCompletionHelpers, useChat, useCompletion }; |
@@ -149,9 +149,27 @@ 'use client' | ||
const prefixMap = {}; | ||
const NEWLINE = "\n".charCodeAt(0); | ||
let chunks = []; | ||
let totalLength = 0; | ||
if (isComplexMode) { | ||
while (true) { | ||
const { done, value } = await reader.read(); | ||
if (done) { | ||
const { value } = await reader.read(); | ||
if (value) { | ||
chunks.push(value); | ||
totalLength += value.length; | ||
if (value[value.length - 1] !== NEWLINE) { | ||
continue; | ||
} | ||
} | ||
if (chunks.length === 0) { | ||
break; | ||
} | ||
const lines = decode(value); | ||
let concatenatedChunks = new Uint8Array(totalLength); | ||
let offset = 0; | ||
for (const chunk of chunks) { | ||
concatenatedChunks.set(chunk, offset); | ||
offset += chunk.length; | ||
} | ||
chunks.length = 0; | ||
totalLength = 0; | ||
const lines = decode(concatenatedChunks); | ||
if (typeof lines === "string") { | ||
@@ -158,0 +176,0 @@ throw new Error( |
@@ -26,20 +26,20 @@ # Vercel AI SDK | ||
// ./app/api/chat/route.js | ||
import OpenAI from 'openai' | ||
import { OpenAIStream, StreamingTextResponse } from 'ai' | ||
import OpenAI from 'openai'; | ||
import { OpenAIStream, StreamingTextResponse } from 'ai'; | ||
const openai = new OpenAI({ | ||
apiKey: process.env.OPENAI_API_KEY | ||
}) | ||
apiKey: process.env.OPENAI_API_KEY, | ||
}); | ||
export const runtime = 'edge' | ||
export const runtime = 'edge'; | ||
export async function POST(req) { | ||
const { messages } = await req.json() | ||
const { messages } = await req.json(); | ||
const response = await openai.chat.completions.create({ | ||
model: 'gpt-4', | ||
stream: true, | ||
messages | ||
}) | ||
const stream = OpenAIStream(response) | ||
return new StreamingTextResponse(stream) | ||
messages, | ||
}); | ||
const stream = OpenAIStream(response); | ||
return new StreamingTextResponse(stream); | ||
} | ||
@@ -50,8 +50,8 @@ ``` | ||
// ./app/page.js | ||
'use client' | ||
'use client'; | ||
import { useChat } from 'ai/react' | ||
import { useChat } from 'ai/react'; | ||
export default function Chat() { | ||
const { messages, input, handleInputChange, handleSubmit } = useChat() | ||
const { messages, input, handleInputChange, handleSubmit } = useChat(); | ||
@@ -74,3 +74,3 @@ return ( | ||
</div> | ||
) | ||
); | ||
} | ||
@@ -77,0 +77,0 @@ ``` |
@@ -200,3 +200,3 @@ import { Resource, Accessor, Setter } from 'solid-js'; | ||
}; | ||
declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, onResponse, onFinish, onError, credentials, headers, body }?: UseChatOptions): UseChatHelpers; | ||
declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, onResponse, onFinish, onError, credentials, headers, body, }?: UseChatOptions): UseChatHelpers; | ||
@@ -237,4 +237,4 @@ type UseCompletionHelpers = { | ||
}; | ||
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, onResponse, onFinish, onError }?: UseCompletionOptions): UseCompletionHelpers; | ||
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers; | ||
export { CreateMessage, Message, UseChatHelpers, UseChatOptions, UseCompletionHelpers, useChat, useCompletion }; |
@@ -204,3 +204,3 @@ import { Readable, Writable } from 'svelte/store'; | ||
}; | ||
declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, experimental_onFunctionCall, onResponse, onFinish, onError, credentials, headers, body }?: UseChatOptions): UseChatHelpers; | ||
declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, experimental_onFunctionCall, onResponse, onFinish, onError, credentials, headers, body, }?: UseChatOptions): UseChatHelpers; | ||
@@ -239,4 +239,4 @@ type UseCompletionHelpers = { | ||
}; | ||
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, onResponse, onFinish, onError }?: UseCompletionOptions): UseCompletionHelpers; | ||
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers; | ||
export { CreateMessage, Message, UseChatHelpers, UseChatOptions, UseCompletionHelpers, useChat, useCompletion }; |
@@ -196,3 +196,3 @@ import { Ref } from 'vue'; | ||
}; | ||
declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, onResponse, onFinish, onError, credentials, headers, body }?: UseChatOptions): UseChatHelpers; | ||
declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, onResponse, onFinish, onError, credentials, headers, body, }?: UseChatOptions): UseChatHelpers; | ||
@@ -231,4 +231,4 @@ type UseCompletionHelpers = { | ||
}; | ||
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, onResponse, onFinish, onError }?: UseCompletionOptions): UseCompletionHelpers; | ||
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers; | ||
export { CreateMessage, Message, UseChatHelpers, UseChatOptions, UseCompletionHelpers, useChat, useCompletion }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
271550
8689