You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/[platform]/build-a-backend/ai/set-up-ai/index.mdx
+157Lines changed: 157 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,3 +32,160 @@ export function getStaticProps(context) {
32
32
Amplify AI sections are under construction
33
33
34
34
</Callout>
35
+
36
+
In this guide, you will learn how to set up Amplify AI. This includes building Conversation and Generation routes, and securing access to these routes with authorization rules.
37
+
38
+
Before you begin, you will need:
39
+
40
+
-[Node.js](https://nodejs.org/) v18.16.0 or later
41
+
-[npm](https://www.npmjs.com/) v6.14.4 or later
42
+
-[git](https://git-scm.com/) v2.14.1 or later
43
+
44
+
You will also need an AWS Account with access to the Bedrock Foundation Model(s) you want to use. You can do that by going in to the [Bedrock console and requesting access](https://console.aws.amazon.com/bedrock/home#/modelaccess).
45
+
46
+
With Amplify AI, you can define Conversation and Generation routes backed by an AWS AppSync API and Amazon Bedrock.
47
+
48
+
## Building your AI backend
49
+
50
+
If you've run `npm create amplify@latest` already, you should see an `amplify/data/resource/ts` file, which is the central location to configure your AI backend. Within the `schema` object, you define Conversation routes (`a.conversation({})`) and Generation routes (`a.generation({})`), and can integrate them seamlessly with existing Amplify Data schema objects.
51
+
52
+
```ts title="amplify/data/resources.ts"
53
+
import { a, defineData, typeClientSchema } from'@aws-amplify/backend';
54
+
55
+
const schema =a.schema({
56
+
// This will add a new conversation route to your Amplify Data backend.
57
+
chat: a.conversation({
58
+
aiModel: a.ai.model('Claude 3 Haiku'),
59
+
systemPrompt: 'You are a helpful assistant',
60
+
}),
61
+
62
+
// This adds a new generation route to your Amplify Data backend.
63
+
generateRecipe: a.generation({
64
+
aiModel: a.ai.model('Claude 3 Haiku'),
65
+
systemPrompt: 'You are a helpful assistant that generates recipes.',
66
+
})
67
+
.arguments({
68
+
description: a.string(),
69
+
})
70
+
// This specifies the return type of the generation route.
71
+
.returns(
72
+
a.customType({
73
+
name: a.string(),
74
+
ingredients: a.string().array(),
75
+
instructions: a.string(),
76
+
})
77
+
)
78
+
// only logged in users can access this
79
+
.authorization((allow) =>allow.authenticated()),
80
+
});
81
+
```
82
+
83
+
To deploy these resources to your cloud sandbox, run the following CLI command in your terminal:
84
+
85
+
```bash title="Terminal"
86
+
npx ampx sandbox
87
+
```
88
+
89
+
## Connect your application code the the AI routes
90
+
91
+
Once the cloud sandbox is up and running, it will also create an `amplify_outputs.json` file, which includes relevant connection information to your AI routes.
92
+
93
+
To connect your frontend code to your backend, you need to:
94
+
95
+
1. Configure the Amplify library with the Amplify client configuration file (`amplify_outputs.json`).
96
+
2. Generate a new API client from the Amplify library.
97
+
3. Make an API request with end-to-end type-safety.
98
+
99
+
## AI Route UI
100
+
101
+
_NOTE: If you are not using React in your frontend, check out the section for using the Amplify Javascript libraries._
102
+
103
+
First, install the Amplify client library to your project:
0 commit comments