Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<AIConversation> React component only renders the the last word of the response. #6334

Closed
4 tasks done
alexhddev opened this issue Feb 6, 2025 · 4 comments
Closed
4 tasks done
Labels
AI An issue or a feature-request for an AI UI Component question General question

Comments

@alexhddev
Copy link

Before creating a new issue, please confirm:

On which framework/platform are you having an issue?

React

Which UI component?

Other

How is your app built?

Vite

What browsers are you seeing the problem on?

No response

Which region are you seeing the problem in?

eu-west-1

Please describe your bug.

I'm following the basic Amplify AI tutorial from aws:
https://aws.amazon.com/blogs/mobile/create-a-customized-ai-based-chat-interface-with-your-application-data/

I can't make the dialog to work inside a Vite react app.
No matter what I try, the AIConversation Component will only render the last entry in the bot response, as seen in the attached screenshot.
Tried with all Claude models, the behavior is the same.
Kindly please assist.

Image

What's the expected behaviour?

See the full AI response.

Help us reproduce the bug!

Please observe the code snippet and screenshot

Code Snippet

import { Authenticator } from '@aws-amplify/ui-react'
import { AIConversation, createAIHooks } from '@aws-amplify/ui-react-ai'
import { generateClient } from "aws-amplify/api";
import { Schema } from "../amplify/data/resource";
import '@aws-amplify/ui-react/styles.css';

function App() {
  const client = generateClient<Schema>({ authMode: "userPool" }); 
  const { useAIConversation } = createAIHooks(client);

  const [
    {
      data: { messages },
    },
    sendMessage,
  ] = useAIConversation('chat');

  return (
    <>
      <Authenticator>
        <AIConversation
          messages={messages}
          handleSendMessage={sendMessage}
        ></AIConversation>
      </Authenticator>
    </>
  )
}

export default App

Console log output

No response

Additional information and screenshots

No response

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify UI maintainer labels Feb 6, 2025
@alexhddev
Copy link
Author

Requests to Claude 3.5 Sonnet only show the last few words:

Image

@cwomack
Copy link
Member

cwomack commented Feb 6, 2025

Hello, @alexhddev 👋 and sorry you're running into this. We're working on reproducing the issue on our side and will follow up as soon as we have more questions or context on this. Thanks for opening the issue.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify UI maintainer label Feb 6, 2025
@cwomack cwomack added question General question AI An issue or a feature-request for an AI UI Component and removed pending-triage Issue is pending triage labels Feb 6, 2025
@alexhddev
Copy link
Author

The problem doesn't appear if I instantiate the ai clients in a separate Client.ts file:
Can't say why.

import { generateClient } from "aws-amplify/api";
import { Schema } from "../amplify/data/resource";
import { createAIHooks } from "@aws-amplify/ui-react-ai";

export const client = generateClient<Schema>({ authMode: "userPool" });
export const { useAIConversation, useAIGeneration } = createAIHooks(client);

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify UI maintainer label Feb 7, 2025
@alexhddev
Copy link
Author

Problem solved:
For anyone reading:
The issue was that I was instantiating the ai client INSIDE the react component. It should be instantiated outside:

// Chat.tsx

import { generateClient } from "aws-amplify/data";
import { createAIHooks, AIConversation } from '@aws-amplify/ui-react-ai';
import type { Schema } from "../amplify/data/resource";

const client = generateClient<Schema>({ authMode: 'userPool' }); // outside Chat function
const { useAIConversation } = createAIHooks(client);  // outside Chat function

export default function Chat() {

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify UI maintainer label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AI An issue or a feature-request for an AI UI Component question General question
Projects
None yet
Development

No branches or pull requests

2 participants