-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a89a02
commit 15732ba
Showing
24 changed files
with
24,915 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
.yarn/install-state.gz | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
# amplify | ||
.amplify | ||
amplify_outputs* | ||
amplifyconfiguration* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineAuth } from '@aws-amplify/backend'; | ||
|
||
/** | ||
* Define and configure your auth resource | ||
* @see https://docs.amplify.aws/gen2/build-a-backend/auth | ||
*/ | ||
export const auth = defineAuth({ | ||
loginWith: { | ||
email: true, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { defineBackend } from "@aws-amplify/backend"; | ||
import { auth } from "./auth/resource"; | ||
import { data } from "./data/resource"; | ||
import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam"; | ||
import { personalAssistantFunction, MODEL_ID } from "./functions/personal-assistant/resource"; | ||
|
||
export const backend = defineBackend({ | ||
auth, | ||
data, | ||
personalAssistantFunction, | ||
}); | ||
|
||
backend.personalAssistantFunction.resources.lambda.addToRolePolicy( | ||
new PolicyStatement({ | ||
effect: Effect.ALLOW, | ||
actions: ["bedrock:InvokeModel"], | ||
resources: [ | ||
`arn:aws:bedrock:*::foundation-model/${MODEL_ID}`, | ||
], | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { type ClientSchema, a, defineData } from "@aws-amplify/backend"; | ||
import { personalAssistantFunction } from "../functions/personal-assistant/resource"; | ||
|
||
const schema = a.schema({ | ||
chat: a | ||
.query() | ||
.arguments({ | ||
conversation: a.json().required(), | ||
}) | ||
.returns(a.string()) | ||
.authorization((allow) => [allow.authenticated()]) | ||
.handler(a.handler.function(personalAssistantFunction)), | ||
}); | ||
|
||
export type Schema = ClientSchema<typeof schema>; | ||
|
||
export const data = defineData({ | ||
schema, | ||
authorizationModes: { | ||
defaultAuthorizationMode: "userPool", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
BedrockRuntimeClient, | ||
ConverseCommandInput, | ||
ConverseCommand, | ||
} from "@aws-sdk/client-bedrock-runtime"; | ||
import type { Handler } from "aws-lambda"; | ||
|
||
// Constants | ||
const AWS_REGION = process.env.AWS_REGION; | ||
const MODEL_ID = process.env.MODEL_ID; | ||
|
||
// Configuration | ||
const INFERENCE_CONFIG = { | ||
maxTokens: 1000, | ||
temperature: 0.5, | ||
}; | ||
|
||
// Initialize Bedrock Runtime Client | ||
const client = new BedrockRuntimeClient({ region: AWS_REGION }); | ||
|
||
export const handler: Handler = async (event) => { | ||
const { conversation } = event.arguments; | ||
|
||
const SYSTEM_PROMPT = ` | ||
To create a personalized travel planning experience, greet users warmly and inquire about their travel preferences | ||
such as destination, dates, budget, and interests. Based on their input, suggest tailored itineraries that include | ||
popular attractions, local experiences, and hidden gems, along with accommodation options across various price | ||
ranges and styles. Provide transportation recommendations, including flights and car rentals, along with estimated | ||
costs and travel times. Recommend dining experiences that align with dietary needs, and share insights on local | ||
customs, necessary travel documents, and packing essentials. Highlight the importance of travel insurance, offer | ||
real-time updates on weather and events, and allow users to save and modify their itineraries. Additionally, | ||
provide a budget tracking feature and the option to book flights and accommodations directly or through trusted | ||
platforms, all while maintaining a warm and approachable tone to enhance the excitement of trip planning. | ||
`; | ||
|
||
const input = { | ||
modelId: MODEL_ID, | ||
system: [{ text: SYSTEM_PROMPT }], | ||
messages: conversation, | ||
inferenceConfig: INFERENCE_CONFIG, | ||
} as ConverseCommandInput; | ||
|
||
try { | ||
const command = new ConverseCommand(input); | ||
const response = await client.send(command); | ||
|
||
if (!response.output?.message) { | ||
throw new Error("No message in the response output"); | ||
} | ||
|
||
return JSON.stringify(response.output.message); | ||
} catch (error) { | ||
console.error("Error in chat handler:", error); | ||
throw error; // Re-throw to be handled by AWS Lambda | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { defineFunction } from "@aws-amplify/backend"; | ||
|
||
export const MODEL_ID = "anthropic.claude-3-haiku-20240307-v1:0"; | ||
|
||
export const personalAssistantFunction = defineFunction({ | ||
entry: "./handler.ts", | ||
environment: { | ||
MODEL_ID, | ||
}, | ||
timeoutSeconds: 30, | ||
runtime: 20, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2022", | ||
"module": "es2022", | ||
"moduleResolution": "bundler", | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"paths": { | ||
"$amplify/*": [ | ||
"../.amplify/generated/*" | ||
] | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {}; | ||
|
||
export default nextConfig; |
Oops, something went wrong.