Skip to content

Commit 07a979b

Browse files
committed
address pr feedback
1 parent 6ce2cf8 commit 07a979b

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/directory/directory.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,9 @@ export const directory = {
756756
{
757757
path: 'src/pages/[platform]/ai/conversation/ai-conversation/index.mdx'
758758
},
759+
{
760+
path: 'src/pages/[platform]/ai/conversation/connect-your-frontend/index.mdx'
761+
},
759762
{
760763
path: 'src/pages/[platform]/ai/conversation/history/index.mdx'
761764
},

src/pages/[platform]/ai/conversation/connect-your-frontend/index.mdx

+11-13
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ There are two main types within the conversation flow, `Conversation` and `Messa
3939

4040
A `Conversation` is an instance of a chat session between an application user and an LLM. It contains data and methods for interacting with the conversation. A conversation has a one-to-many relationship with its messages.
4141

42-
The `Conversation` type is accessible via `Schema['myChat']['type']` type definition, where `'myChat'` is the name of the conversation route in your data schema.
42+
The `Conversation` type is accessible via `Schema['myChat']['type']` type definition, where `'myChat'` is the name of the conversation route in your data schema.
4343

4444
| Property/Method | Type | Description |
4545
|------------------|:-------|:-------------|
@@ -56,7 +56,7 @@ The `Conversation` type is accessible via `Schema['myChat']['type']` type defini
5656

5757
A `Message` is a single chat message between an application user and an LLM. Each message has a `role` property that indicates whether the message is from the user or the assistant. User and assistant messages have a one-to-one relationship. Assistant messages contain an `associatedUserMessageId` property that points to the `id` of the user message that triggered the assistant response.
5858

59-
The `Message` type is accessible via `Schema['myChat']['messageType']`.
59+
The `Message` type is accessible via `Schema['myChat']['messageType']`, where `'myChat'` is the name of the conversation route in your data schema.
6060

6161
| Property | Type | Description |
6262
|-----------|:-------|:-------------|
@@ -67,22 +67,29 @@ The `Message` type is accessible via `Schema['myChat']['messageType']`.
6767
| `role` | `'user' \| 'assistant'` | Whether the message is from the user or assistant |
6868
| `createdAt` | `string` | The date and time when the message was created |
6969

70-
## Data flow
70+
## Request response flow
7171

7272
1. Create a new conversation with `.create()` or get an existing one with `.get()`.
7373
2. Subscribe to assistant responses for a conversation with `.onStreamEvent()`.
7474
3. Send messages to the conversation with `.sendMessage()`.
7575

7676
```ts
77+
import { generateClient } from 'aws-amplify/data';
78+
import { type Schema } from '../amplify/data/resource'
79+
80+
const client = generateClient<Schema>();
81+
7782
// 1. Create a conversation
7883
const { data: chat, errors } = await client.conversations.chat.create();
7984

8085
// 2. Subscribe to assistant responses
8186
const subscription = chat.onStreamEvent({
8287
next: (event) => {
88+
// handle assistant response stream events
8389
console.log(event);
8490
},
8591
error: (error) => {
92+
// handle errors
8693
console.error(error);
8794
},
8895
});
@@ -95,16 +102,7 @@ const { data: message, errors } = await chat.sendMessage('Hello, world!');
95102

96103
### Create a conversation
97104

98-
Conversation routes defined in your schema are accessible via the `.conversations` namespace. First create a client instance with the `generateClient()` function.
99-
100-
```ts
101-
import { generateClient } from 'aws-amplify/data';
102-
import { type Schema } from '../amplify/data/resource'
103-
104-
const client = generateClient<Schema>();
105-
```
106-
107-
Then create a new conversation by calling the `.create()` method on your conversation route. In the examples below, we're using a conversation route named `chat`.
105+
Create a new conversation by calling the `.create()` method on your conversation route. In the examples below, we're using a conversation route named `chat`.
108106

109107
```ts
110108
const { data: chat, errors } = await client.conversations.chat.create();

0 commit comments

Comments
 (0)