-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathApp.tsx
More file actions
118 lines (107 loc) · 3.43 KB
/
App.tsx
File metadata and controls
118 lines (107 loc) · 3.43 KB
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
import { useFonts } from 'expo-font';
import ScrollPicker from 'react-native-wheel-scrollview-picker';
import SWMIcon from './assets/icons/swm_icon.svg';
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
import { useState } from 'react';
import ColorPalette from './colors';
import {
View,
StyleSheet,
Text,
KeyboardAvoidingView,
Platform,
} from 'react-native';
import LLMScreen from './screens/LLMScreen';
import LLMToolCallingScreen from './screens/LLMToolCallingScreen';
import VoiceChatScreen from './screens/VocieChatScreen';
enum Mode {
LLM,
LLM_VOICE_CHAT,
LLM_TOOL_CALLING,
}
export default function App() {
useFonts({
medium: require('./assets/fonts/Aeonik-Medium.otf'),
regular: require('./assets/fonts/Aeonik-Regular.otf'),
});
const [selectedMode, setSelectedMode] = useState<Mode>(Mode.LLM);
const [isGenerating, setIsGenerating] = useState(false);
const handleModeChange = (mode: Mode) => {
if (!isGenerating) {
setSelectedMode(mode);
}
};
const renderScreen = () => {
switch (selectedMode) {
case Mode.LLM:
return <LLMScreen setIsGenerating={setIsGenerating} />;
case Mode.LLM_VOICE_CHAT:
return <VoiceChatScreen setIsGenerating={setIsGenerating} />;
case Mode.LLM_TOOL_CALLING:
return <LLMToolCallingScreen setIsGenerating={setIsGenerating} />;
default:
return <LLMScreen setIsGenerating={setIsGenerating} />;
}
};
return (
<SafeAreaProvider>
<SafeAreaView style={styles.container}>
<KeyboardAvoidingView
style={styles.keyboardAvoidingView}
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
keyboardVerticalOffset={Platform.OS === 'android' ? 30 : 0}
>
<View style={styles.topContainer}>
<SWMIcon width={45} height={45} />
<Text style={styles.textModelName}>LLM on device demo</Text>
{!isGenerating ? (
<View style={styles.wheelPickerContainer}>
<ScrollPicker
dataSource={['Chat with LLM', 'Talk to LLM', 'Tool calling']}
onValueChange={(_, selectedIndex) => {
handleModeChange(selectedIndex);
}}
wrapperHeight={120}
highlightColor={ColorPalette.primary}
wrapperBackground="#fff"
highlightBorderWidth={3}
itemHeight={40}
activeItemTextStyle={styles.activeScrollItem}
/>
</View>
) : (
<Text style={styles.placeholderText}>
Model is generating. Interrupt to swap models!
</Text>
)}
</View>
{renderScreen()}
</KeyboardAvoidingView>
</SafeAreaView>
</SafeAreaProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'space-between',
backgroundColor: '#fff',
},
keyboardAvoidingView: { flex: 1 },
topContainer: {
marginTop: 5,
height: 165,
width: '100%',
alignItems: 'center',
justifyContent: 'center',
},
wheelPickerContainer: { width: '100%', height: 120 },
activeScrollItem: { color: ColorPalette.primary, fontWeight: 'bold' },
textModelName: { color: ColorPalette.primary },
placeholderText: {
color: ColorPalette.primary,
fontSize: 25,
marginTop: 20,
textAlign: 'center',
},
});