-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add increased memory limit * fix: include `bundle/` dir * fix: disable new arch * feat: add chat ui * feat: add network state information
- Loading branch information
1 parent
e87bebc
commit 9295c10
Showing
15 changed files
with
635 additions
and
103 deletions.
There are no files selected for viewing
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
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.developer.kernel.increased-memory-limit</key> | ||
<true/> | ||
</dict> | ||
</plist> |
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
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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
import 'react-native-get-random-values'; | ||
|
||
// @ts-ignore | ||
import { polyfillGlobal } from 'react-native/Libraries/Utilities/PolyfillFunctions'; | ||
const webStreamPolyfills = require('web-streams-polyfill/ponyfill/es6'); | ||
|
||
polyfillGlobal('TextEncoder', () => require('text-encoding').TextEncoder); | ||
polyfillGlobal('TextDecoder', () => require('text-encoding').TextDecoder); | ||
polyfillGlobal('ReadableStream', () => webStreamPolyfills.ReadableStream); | ||
polyfillGlobal('TransformStream', () => webStreamPolyfills.TransformStream); | ||
polyfillGlobal('WritableStream', () => webStreamPolyfills.WritableStream); | ||
polyfillGlobal('TextEncoderStream', () => webStreamPolyfills.TextEncoderStream); |
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 |
---|---|---|
@@ -1,32 +1,69 @@ | ||
import React from 'react'; | ||
import { StyleSheet, View, Text, TouchableOpacity } from 'react-native'; | ||
import { doGenerate } from 'react-native-ai'; | ||
|
||
export default function App() { | ||
const askQuestion = async () => { | ||
try { | ||
const data = await doGenerate('ai', 'whats react native'); | ||
console.log(data); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
import React, { useState } from 'react'; | ||
import { SafeAreaView, StyleSheet } from 'react-native'; | ||
import { GiftedChat, type IMessage } from 'react-native-gifted-chat'; | ||
import { getModel } from 'react-native-ai'; | ||
import { generateText } from 'ai'; | ||
import { v4 as uuid } from 'uuid'; | ||
import NetworkInfo from './NetworkInfo'; | ||
|
||
const modelId = 'Phi-3-mini-4k-instruct-q4f16_1-MLC'; | ||
|
||
const aiBot = { | ||
_id: 2, | ||
name: 'AI Chat Bot', | ||
avatar: require('./../assets/avatar.png'), | ||
}; | ||
|
||
export default function Example() { | ||
const [messages, setMessages] = useState<IMessage[]>([ | ||
{ | ||
_id: uuid(), | ||
text: 'Hello! How can I help you today?', | ||
createdAt: new Date(), | ||
user: aiBot, | ||
}, | ||
]); | ||
|
||
const onSendMessage = async (prompt: string) => { | ||
const { text } = await generateText({ | ||
model: getModel(modelId), | ||
prompt, | ||
}); | ||
|
||
setMessages((previousMessages) => | ||
GiftedChat.append(previousMessages, { | ||
// @ts-ignore | ||
_id: uuid(), | ||
text, | ||
createdAt: new Date(), | ||
user: aiBot, | ||
}) | ||
); | ||
}; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<TouchableOpacity style={styles.button} onPress={askQuestion}> | ||
<Text>Ask a question</Text> | ||
</TouchableOpacity> | ||
</View> | ||
<SafeAreaView style={styles.container}> | ||
<NetworkInfo /> | ||
<GiftedChat | ||
messages={messages} | ||
onSend={(newMessage) => { | ||
setMessages((previousMessages) => | ||
GiftedChat.append(previousMessages, newMessage) | ||
); | ||
|
||
onSendMessage(newMessage[0]!.text); | ||
}} | ||
user={{ | ||
_id: 1, | ||
}} | ||
/> | ||
</SafeAreaView> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
backgroundColor: 'darkblue', | ||
backgroundColor: '#fff', | ||
}, | ||
button: { width: 200, height: 200, backgroundColor: 'red' }, | ||
}); |
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 React from 'react'; | ||
import { View, Text, StyleSheet } from 'react-native'; | ||
import { useNetInfo } from '@react-native-community/netinfo'; | ||
|
||
const NetworkInfo = () => { | ||
const netInfo = useNetInfo(); | ||
|
||
const getStatusColor = () => { | ||
if (netInfo.isConnected) return styles.connected; | ||
return styles.disconnected; | ||
}; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<View style={[styles.statusIndicator, getStatusColor()]} /> | ||
<Text style={styles.statusText}> | ||
{netInfo.isConnected ? 'Connected ✅' : 'Disconnected ❌'} | ||
</Text> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
padding: 10, | ||
backgroundColor: '#f0f0f0', | ||
borderRadius: 8, | ||
}, | ||
statusIndicator: { | ||
width: 12, | ||
height: 12, | ||
borderRadius: 6, | ||
marginRight: 10, | ||
}, | ||
connected: { | ||
backgroundColor: '#4CAF50', | ||
}, | ||
disconnected: { | ||
backgroundColor: '#F44336', | ||
}, | ||
textContainer: { | ||
flex: 1, | ||
}, | ||
statusText: { | ||
fontSize: 16, | ||
fontWeight: 'bold', | ||
}, | ||
detailText: { | ||
fontSize: 14, | ||
color: '#666', | ||
}, | ||
}); | ||
|
||
export default NetworkInfo; |
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
#import <React/RCTEventEmitter.h> | ||
|
||
#ifdef RCT_NEW_ARCH_ENABLED | ||
#import "RNAiSpec.h" | ||
|
||
@interface Ai : NSObject <NativeAiSpec> | ||
@interface Ai : RCTEventEmitter <NativeAiSpec> | ||
#else | ||
#import <React/RCTBridgeModule.h> | ||
|
||
@interface Ai : NSObject <RCTBridgeModule> | ||
@interface Ai : RCTEventEmitter <RCTBridgeModule> | ||
#endif | ||
|
||
@end |
Oops, something went wrong.