Skip to content

Commit e86ec7b

Browse files
authored
chore: Suggest prompts in llm demo apps (#984)
## Description This change add suggestions in llm apps to make it easier for testing. Also changes color in hamburger in llm navigation. ### Introduces a breaking change? - [ ] Yes - [x] No ### Type of change - [ ] Bug fix (change which fixes an issue) - [ ] New feature (change which adds functionality) - [ ] Documentation update (improves or adds clarity to existing documentation) - [x] Other (chores, tests, code style improvements etc.) ### Tested on - [x] iOS - [ ] Android ### Testing instructions - [x] Test if suggestions appear correctly in llm apps - [x] Check that hamburger icons are now visible in llm demo apps. ### Screenshots <img width="375" height="843" alt="image" src="https://github.com/user-attachments/assets/49b59057-61ed-41af-ae61-a6733e51a0b9" /> ### Related issues Closes #957 ### Checklist - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [x] My changes generate no new warnings ### Additional notes <!-- Include any additional information, assumptions, or context that reviewers might need to understand this PR. -->
1 parent 1fc061c commit e86ec7b

File tree

8 files changed

+140
-1
lines changed

8 files changed

+140
-1
lines changed

apps/bare_rn/App.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
StyleSheet,
1010
Text,
1111
TextInput,
12+
TouchableOpacity,
1213
TouchableWithoutFeedback,
1314
View,
1415
} from 'react-native';
@@ -176,6 +177,22 @@ function App() {
176177
<Text style={styles.welcomeSubtitle}>
177178
What can I help you with?
178179
</Text>
180+
<View style={styles.suggestionsContainer}>
181+
{[
182+
'Explain quantum computing in simple terms',
183+
'Write a short poem about coding',
184+
'What are the benefits of on-device AI?',
185+
'Give me 3 fun facts about space',
186+
].map((prompt, i) => (
187+
<TouchableOpacity
188+
key={i}
189+
style={styles.suggestionChip}
190+
onPress={() => setUserInput(prompt)}
191+
>
192+
<Text style={styles.suggestionChipText}>{prompt}</Text>
193+
</TouchableOpacity>
194+
))}
195+
</View>
179196
</View>
180197
</TouchableWithoutFeedback>
181198
)}
@@ -253,6 +270,25 @@ const styles = StyleSheet.create({
253270
color: ColorPalette.blueDark,
254271
textAlign: 'center',
255272
},
273+
suggestionsContainer: {
274+
flexDirection: 'row',
275+
flexWrap: 'wrap',
276+
justifyContent: 'center',
277+
gap: 8,
278+
paddingTop: 16,
279+
},
280+
suggestionChip: {
281+
borderWidth: 1,
282+
borderColor: ColorPalette.blueLight,
283+
borderRadius: 20,
284+
paddingHorizontal: 14,
285+
paddingVertical: 8,
286+
backgroundColor: '#fafbff',
287+
},
288+
suggestionChipText: {
289+
fontSize: 13,
290+
color: ColorPalette.primary,
291+
},
256292
messageBubble: {
257293
maxWidth: '80%',
258294
padding: 12,

apps/bare_rn/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2717,7 +2717,7 @@ SPEC CHECKSUMS:
27172717
React-Mapbuffer: 94f4264de2cb156960cd82b338a403f4653f2fd9
27182718
React-microtasksnativemodule: 6c4ee39a36958c39c97b074d28f360246a335e84
27192719
react-native-background-downloader: 114f96122822fa97b06ea0f2250b8e8270696995
2720-
react-native-executorch: 86764f0bd936e8ff18fdb30c36343bb01aab54da
2720+
react-native-executorch: 517da022131a15a98ea5337f02a88e7807a1ec3d
27212721
react-native-safe-area-context: befb5404eb8a16fdc07fa2bebab3568ecabcbb8a
27222722
React-NativeModulesApple: ebf2ce72b35870036900d6498b33724386540a71
27232723
React-oscompat: eb0626e8ba1a2c61673c991bf9dc21834898475d

apps/llm/app/_layout.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
DrawerContentComponentProps,
99
DrawerContentScrollView,
1010
DrawerItemList,
11+
DrawerToggleButton,
1112
} from '@react-navigation/drawer';
1213
import { GeneratingContext } from '../context';
1314

@@ -55,6 +56,9 @@ export default function _layout() {
5556
drawerInactiveTintColor: '#888',
5657
headerTintColor: ColorPalette.primary,
5758
headerTitleStyle: { color: ColorPalette.primary },
59+
headerLeft: () => (
60+
<DrawerToggleButton tintColor={ColorPalette.primary} />
61+
),
5862
}}
5963
>
6064
<Drawer.Screen

apps/llm/app/llm/index.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ import Messages from '../../components/Messages';
2020
import { useIsFocused } from '@react-navigation/native';
2121
import { GeneratingContext } from '../../context';
2222
import Spinner from '../../components/Spinner';
23+
import SuggestedPrompts from '../../components/SuggestedPrompts';
24+
25+
const SUGGESTED_PROMPTS = [
26+
'Explain quantum computing in simple terms',
27+
'Write a short poem about coding',
28+
'What are the benefits of on-device AI?',
29+
'Give me 3 fun facts about space',
30+
];
2331

2432
export default function LLMScreenWrapper() {
2533
const isFocused = useIsFocused();
@@ -88,6 +96,10 @@ function LLMScreen() {
8896
<Text style={styles.bottomHelloText}>
8997
What can I help you with?
9098
</Text>
99+
<SuggestedPrompts
100+
prompts={SUGGESTED_PROMPTS}
101+
onSelect={setUserInput}
102+
/>
91103
</View>
92104
)}
93105

@@ -113,6 +125,7 @@ function LLMScreen() {
113125
placeholderTextColor={'#C1C6E5'}
114126
multiline={true}
115127
ref={textInputRef}
128+
value={userInput}
116129
onChangeText={(text: string) => setUserInput(text)}
117130
/>
118131
{userInput && (

apps/llm/app/llm_structured_output/index.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ import {
1212
} from 'react-native';
1313
import SendIcon from '../../assets/icons/send_icon.svg';
1414
import Spinner from '../../components/Spinner';
15+
import SuggestedPrompts from '../../components/SuggestedPrompts';
16+
17+
const SUGGESTED_PROMPTS = [
18+
"I'm John. Is this damaged? I offer $100.",
19+
"Hi, I'm Alice! How old is it? Offering $250 USD.",
20+
"I'm Bob. Does it have warranty? I'll pay €50.",
21+
"Name's Sara. What condition? My bid is $75.",
22+
];
1523
import {
1624
useLLM,
1725
fixAndValidateStructuredOutput,
@@ -169,6 +177,10 @@ function LLMScreen() {
169177
I can parse user's questions! Introduce yourself, ask questions
170178
and offer a price for some product.
171179
</Text>
180+
<SuggestedPrompts
181+
prompts={SUGGESTED_PROMPTS}
182+
onSelect={setUserInput}
183+
/>
172184
</View>
173185
)}
174186

@@ -198,6 +210,7 @@ function LLMScreen() {
198210
placeholderTextColor={'#C1C6E5'}
199211
multiline={true}
200212
ref={textInputRef}
213+
value={userInput}
201214
onChangeText={(text: string) => setUserInput(text)}
202215
/>
203216
{userInput && (

apps/llm/app/llm_tool_calling/index.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ import * as Calendar from 'expo-calendar';
3131
import { executeTool, TOOL_DEFINITIONS_PHONE } from '../../utils/tools';
3232
import { useIsFocused } from '@react-navigation/native';
3333
import { GeneratingContext } from '../../context';
34+
import SuggestedPrompts from '../../components/SuggestedPrompts';
35+
36+
const SUGGESTED_PROMPTS = [
37+
'What events do I have today?',
38+
'Add a meeting tomorrow at 2pm',
39+
'Set screen brightness to 50%',
40+
'What do I have scheduled this week?',
41+
];
3442

3543
export default function LLMToolCallingScreenWrapper() {
3644
const isFocused = useIsFocused();
@@ -191,6 +199,10 @@ function LLMToolCallingScreen() {
191199
<Text style={styles.bottomHelloText}>
192200
I can use calendar! Ask me to check it or add an event for you!
193201
</Text>
202+
<SuggestedPrompts
203+
prompts={SUGGESTED_PROMPTS}
204+
onSelect={setUserInput}
205+
/>
194206
</View>
195207
)}
196208

@@ -239,6 +251,7 @@ function LLMToolCallingScreen() {
239251
placeholderTextColor={'#C1C6E5'}
240252
multiline={true}
241253
ref={textInputRef}
254+
value={userInput}
242255
onChangeText={(text: string) => setUserInput(text)}
243256
/>
244257
{userInput && (

apps/llm/app/multimodal_llm/index.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ import ColorPalette from '../../colors';
2020
import Messages from '../../components/Messages';
2121
import Spinner from '../../components/Spinner';
2222
import { GeneratingContext } from '../../context';
23+
import SuggestedPrompts from '../../components/SuggestedPrompts';
24+
25+
const SUGGESTED_PROMPTS = [
26+
"What's in this image?",
27+
'Describe this scene in detail',
28+
'What objects can you see?',
29+
'What text appears in this image?',
30+
];
2331

2432
export default function MultimodalLLMScreenWrapper() {
2533
const isFocused = useIsFocused();
@@ -108,6 +116,10 @@ function MultimodalLLMScreen() {
108116
<Text style={styles.bottomHelloText}>
109117
Pick an image and ask me anything about it.
110118
</Text>
119+
<SuggestedPrompts
120+
prompts={SUGGESTED_PROMPTS}
121+
onSelect={setUserInput}
122+
/>
111123
</View>
112124
)}
113125

@@ -152,6 +164,7 @@ function MultimodalLLMScreen() {
152164
placeholder={imageUri ? 'Ask about the image…' : 'Your message'}
153165
placeholderTextColor="#C1C6E5"
154166
multiline
167+
value={userInput}
155168
onChangeText={setUserInput}
156169
/>
157170

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
2+
import ColorPalette from '../colors';
3+
4+
interface Props {
5+
prompts: string[];
6+
onSelect: (prompt: string) => void;
7+
}
8+
9+
export default function SuggestedPrompts({ prompts, onSelect }: Props) {
10+
return (
11+
<View style={styles.container}>
12+
{prompts.map((prompt, i) => (
13+
<TouchableOpacity
14+
key={i}
15+
style={styles.chip}
16+
onPress={() => onSelect(prompt)}
17+
>
18+
<Text style={styles.chipText}>{prompt}</Text>
19+
</TouchableOpacity>
20+
))}
21+
</View>
22+
);
23+
}
24+
25+
const styles = StyleSheet.create({
26+
container: {
27+
flexDirection: 'row',
28+
flexWrap: 'wrap',
29+
justifyContent: 'center',
30+
gap: 8,
31+
paddingHorizontal: 16,
32+
paddingTop: 16,
33+
},
34+
chip: {
35+
borderWidth: 1,
36+
borderColor: ColorPalette.blueLight,
37+
borderRadius: 20,
38+
paddingHorizontal: 14,
39+
paddingVertical: 8,
40+
backgroundColor: '#fafbff',
41+
},
42+
chipText: {
43+
fontFamily: 'regular',
44+
fontSize: 13,
45+
color: ColorPalette.primary,
46+
},
47+
});

0 commit comments

Comments
 (0)