-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource.ts
141 lines (137 loc) · 4.03 KB
/
resource.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { type ClientSchema, a, defineData } from "@aws-amplify/backend";
import {
getCurrentDate,
getEverything,
getFoods,
getHeights,
getWeights,
} from "../function/resource";
const schema = a
.schema({
Food: a
.model({
name: a.string(),
calories: a.integer().required(),
protein: a.integer(),
day: a.string().required(),
notes: a.string(),
photos: a.string().array(),
})
.secondaryIndexes((index) => [index("day")])
.authorization((allow) => [allow.owner()]),
Goal: a
.model({
dietCalories: a.integer().required(),
})
.authorization((allow) => [allow.owner()]),
QuickAdd: a
.model({
name: a.string().required(),
calories: a.integer().required(),
protein: a.integer(),
icon: a.string().required(),
})
.authorization((allow) => [allow.owner()]),
Weight: a
.model({
currentWeight: a.integer().required(),
})
.authorization((allow) => [allow.owner()]),
Height: a
.model({
currentHeight: a.integer().required(),
})
.authorization((allow) => [allow.owner()]),
HealthKitCache: a
.model({
activeCalories: a.float().required(),
baseCalories: a.float().required(),
weight: a.float(),
steps: a.float(),
day: a.string().required(),
})
.authorization((allow) => [allow.owner()]),
Preferences: a
.model({
hideProtein: a.boolean(),
hideSteps: a.boolean(),
})
.authorization((allow) => [allow.owner()]),
StringType: a.customType({
value: a.string(),
}),
getWeights: a
.query()
.arguments({ ignoreThisArgument: a.string() })
.returns(a.ref("StringType"))
.handler(a.handler.function(getWeights))
.authorization((allow) => allow.authenticated()),
getHeights: a
.query()
.arguments({ ignoreThisArgument: a.string() })
.returns(a.ref("StringType"))
.handler(a.handler.function(getHeights))
.authorization((allow) => allow.authenticated()),
getFoods: a
.query()
.arguments({ ignoreThisArgument: a.string() })
.returns(a.ref("StringType"))
.handler(a.handler.function(getFoods))
.authorization((allow) => allow.authenticated()),
getCurrentDate: a
.query()
.arguments({ ignoreThisArgument: a.string() })
.returns(a.ref("StringType"))
.handler(a.handler.function(getCurrentDate))
.authorization((allow) => allow.authenticated()),
getEverything: a
.query()
.arguments({ userId: a.string().required() })
.returns(a.ref("StringType"))
.handler(a.handler.function(getEverything))
.authorization((allow) => allow.authenticated()),
chat: a.conversation({
aiModel: a.ai.model("Claude 3.5 Sonnet"),
systemPrompt: `You are motivating users to lose weight. You answer in three sentences or less, using simple english words.`,
tools: [
{
// query: a.ref("getWeights"),
query: a.ref("listWeights"),
description: "How much the user weighs.",
},
{
query: a.ref("listHeights"),
// query: a.ref("getHeights"),
description: "How tall the user is.",
},
{
query: a.ref("listFoods"),
// query: a.ref("getFoods"),
description: "The food the user has eaten.",
},
{
query: a.ref("getCurrentDate"),
description: "Provides the current day and time",
},
],
inferenceConfiguration: {
maxTokens: 500,
temperature: 1,
topP: 0.5,
},
}),
})
.authorization((allow) => [
allow.resource(getCurrentDate),
allow.resource(getHeights),
allow.resource(getWeights),
allow.resource(getFoods),
allow.resource(getEverything),
]);
export type Schema = ClientSchema<typeof schema>;
export const data = defineData({
schema,
authorizationModes: {
defaultAuthorizationMode: "userPool",
},
});