Skip to content

Commit

Permalink
(chore: examples) make next-openai-pages elements locatable by playwr…
Browse files Browse the repository at this point in the history
…ight (vercel#2119)
  • Loading branch information
jeremyphilemon authored Jun 27, 2024
1 parent b33d61a commit 31bffdf
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ export default function Page() {

<form onSubmit={submitMessage} className="fixed bottom-0 p-2 w-full">
<input
disabled={status !== 'awaiting_message'}
className="bg-zinc-100 w-full p-2"
placeholder="Send message..."
value={input}
onChange={handleInputChange}
className="bg-zinc-100 w-full p-2"
disabled={status !== 'awaiting_message'}
/>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ export default function Page() {

<form onSubmit={submitMessage} className="fixed bottom-0 p-2 w-full">
<input
disabled={status !== 'awaiting_message'}
className="bg-zinc-100 w-full p-2"
placeholder="Send message..."
value={input}
onChange={handleInputChange}
className="bg-zinc-100 w-full p-2"
disabled={status !== 'awaiting_message'}
/>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export default function Page() {
{isLoading ? (
'Loading...'
) : (
<pre className="text-sm w-full whitespace-pre-wrap">{generation}</pre>
<pre
className="text-sm w-full whitespace-pre-wrap"
data-testid="generation"
>
{generation}
</pre>
)}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export default function Page() {
Generate
</div>

{isLoading ? 'Loading...' : generation}
{isLoading ? (
'Loading...'
) : (
<div data-testid="generation">generation</div>
)}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function Page() {
Generate
</div>

{completion}
<div data-testid="generation">{completion}</div>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function Page() {
<div className="fixed bottom-0 p-2 w-full">
<input
value={input}
placeholder="Send message..."
onChange={event => {
setInput(event.target.value);
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useChat } from 'ai/react';

export default function Chat() {
const { messages, input, handleInputChange, handleSubmit } = useChat({
api: '/api/chat-api-route',
});
const { messages, input, handleInputChange, handleSubmit, isLoading } =
useChat({
api: '/api/chat-api-route',
});

return (
<div className="flex flex-col gap-2">
Expand All @@ -19,8 +20,10 @@ export default function Chat() {
<form onSubmit={handleSubmit} className="fixed bottom-0 p-2 w-full">
<input
value={input}
placeholder="Send message..."
onChange={handleInputChange}
className="bg-zinc-100 w-full p-2"
disabled={isLoading}
/>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useChat } from 'ai/react';

export default function Chat() {
const { messages, input, handleInputChange, handleSubmit } = useChat({
api: '/api/chat-edge',
});
const { messages, input, handleInputChange, handleSubmit, isLoading } =
useChat({
api: '/api/chat-edge',
});

return (
<div className="flex flex-col gap-2">
Expand All @@ -19,8 +20,10 @@ export default function Chat() {
<form onSubmit={handleSubmit} className="fixed bottom-0 p-2 w-full">
<input
value={input}
placeholder="Send message..."
onChange={handleInputChange}
className="bg-zinc-100 w-full p-2"
disabled={isLoading}
/>
</form>
</div>
Expand Down
9 changes: 6 additions & 3 deletions examples/next-openai-pages/pages/chat/stream-chat/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useChat } from 'ai/react';

export default function Page() {
const { messages, input, handleSubmit, handleInputChange } = useChat({
api: '/api/stream-chat',
});
const { messages, input, handleSubmit, handleInputChange, isLoading } =
useChat({
api: '/api/stream-chat',
});

return (
<div className="flex flex-col gap-2">
Expand All @@ -19,8 +20,10 @@ export default function Page() {
<form onSubmit={handleSubmit} className="fixed bottom-0 p-2 w-full">
<input
value={input}
placeholder="Send message..."
onChange={handleInputChange}
className="bg-zinc-100 w-full p-2"
disabled={isLoading}
/>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default function Page() {
<form onSubmit={handleSubmit} className="fixed bottom-0 p-2 w-full">
<input
value={input}
placeholder="Send message..."
onChange={handleInputChange}
className="bg-zinc-100 w-full p-2"
/>
Expand Down
1 change: 1 addition & 0 deletions examples/next-openai-pages/pages/tools/call-tool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function Page() {
<form onSubmit={handleSubmit} className="fixed bottom-0 p-2 w-full">
<input
value={input}
placeholder="Send message..."
onChange={handleInputChange}
className="bg-zinc-100 w-full p-2"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function Page() {
<form onSubmit={handleSubmit} className="fixed bottom-0 p-2 w-full">
<input
value={input}
placeholder="Send message..."
onChange={handleInputChange}
className="bg-zinc-100 w-full p-2"
/>
Expand Down

0 comments on commit 31bffdf

Please sign in to comment.