Код: Выделить всё
const schema = a.schema({
...
generateRecipe: a.generation({
aiModel: a.ai.model('Amazon Nova Pro'), // this is the only part that was changed!
systemPrompt: 'You are a helpful assistant that generates recipes.',
})
.arguments({ description: a.string() })
.returns(
a.customType({
name: a.string(),
ingredients: a.string().array(),
instructions: a.string(),
})
)
.authorization((allow) => allow.authenticated()),
...
}).authorization((allow) => [
// just some lambda functions here
]);
export type Schema = ClientSchema;
export const data = defineData({
schema,
authorizationModes: {
defaultAuthorizationMode: "userPool",
apiKeyAuthorizationMode: {
expiresInDays: 30,
},
},
});
Код: Выделить всё
import { generateClient } from "aws-amplify/api";
import { createAIHooks } from "@aws-amplify/ui-react-ai";
import { Schema } from "../amplify/data/resource";
const client = generateClient({ authMode: "userPool" });
const { useAIGeneration } = createAIHooks(client);
...
const [{ data, isLoading }, generateRecipe] = useAIGeneration("generateRecipe");
const generateSummary = async () => {
await generateRecipe({
description: 'I would like to bake a birthday cake for my friend. She has celiac disease and loves chocolate.',
});
};
useEffect(() => console.log(isLoading, data), [isLoading, data]);
...
generateSummary()}>click me!
Код: Выделить всё
{
"data": {
"generateRecipe": null
},
"errors": [
{
"path": [
"generateRecipe"
],
"data": null,
"errorType": "ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "A custom error was thrown from a mapping template."
}
]
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... pping-erro
Мобильная версия