Skip to content

Instantly share code, notes, and snippets.

let axios = require('axios');
const openAiApi = axios.create({
baseURL: 'https://api.openai.com/v1/',
headers: {
Authorization: `Bearer ${gptKey}`,
'Content-Type': 'application/json'
}
});
import { ChromaClient } from 'chromadb';
export const handler = async (event: APIGatewayEvent) => {
// ... ommitted
const client = new ChromaClient(CHROMADB_BASE_PATH);
const collection = await client.getCollection(userUuid);
const result = await collection.query(queryVector, 3);
const relevantEntryIds = result.ids[0];
import { ChromaClient } from 'chromadb';
export const handler = async (event: APIGatewayEvent) => {
// ... ommitted
const chromaDbClient = new ChromaClient(CHROMADB_BASE_PATH);
let userCollection = await chromaDbClient.getOrCreateCollection(userUuid);
const entryIds = [1, 2, 3]
import { OpenAIEmbeddingFunction } from 'chromadb';
/**
* Lambda API Gateway Event Handler
*/
export const handler = async (event: APIGatewayEvent) => {
// ... ommitted
const journalEntryValues = ['entry1 data', 'entry2 data', 'entry3 data'];
const embedder = new OpenAIEmbeddingFunction(openAiApiKey);
CFDistribution:
#checkov:skip=CKV_AWS_68: "For demo purposes and to reduce cost, no WAF is configured"
Type: 'AWS::CloudFront::Distribution'
DependsOn:
- CFOriginAccessIdentity
Properties:
DistributionConfig:
Origins:
- DomainName: !GetAtt S3Bucket.RegionalDomainName
Id: myS3Origin
ViewerCertificate:
SslSupportMethod: sni-only
MinimumProtocolVersion: TLSv1.2_2021
AcmCertificateArn: !Ref TonyCodesDNSCertificate
ViewerCertificate:
SslSupportMethod: sni-only
MinimumProtocolVersion: TLSv1
AcmCertificateArn: !Ref TonyCodesDNSCertificate
TonyCodesDNSCertificate:
Type: AWS::CertificateManager::Certificate
Properties:
CertificateTransparencyLoggingPreference: DISABLED
DomainName: tonycodes.com
DomainValidationOptions:
- DomainName: tonycodes.com
HostedZoneId: Z05106722AGOCZ1FSFD3D
ValidationMethod: DNS
JumbleJournalDNSAliasRecord:
Type: AWS::Route53::RecordSetGroup
Properties:
HostedZoneId: Z05106123ABC456DEF789
RecordSets:
- Name: tonycodes.com
Type: A
AliasTarget:
HostedZoneId: Z2FDTNDATAQYW2
DNSName: !GetAtt
+─────────────────────────+───────────────────────────────────────────────────────────────────────────────────────+
| User Interface | SAM Template |
+─────────────────────────+───────────────────────────────────────────────────────────────────────────────────────+
| Routing policy | The desired routing policy is the default. So no value is needed in the SAM template |
+─────────────────────────+───────────────────────────────────────────────────────────────────────────────────────+
| Record name | Name |
+─────────────────────────+───────────────────────────────────────────────────────────────────────────────────────+
| Alias | AliasTarget |
+─────────────────────────+─────────────────────────────────────────────────────────────────────