login view not hide after login; last message does not always contain message in stream mode.
lalalic opened this issue ยท 0 comments
lalalic commented
Hi! ๐
Firstly, thanks for your work on this project! ๐
Today I used patch-package to patch react-native-chatgpt@0.9.0
for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/react-native-chatgpt/src/components/ChatGpt.tsx b/node_modules/react-native-chatgpt/src/components/ChatGpt.tsx
index f1b3f62..c2ff3e7 100644
--- a/node_modules/react-native-chatgpt/src/components/ChatGpt.tsx
+++ b/node_modules/react-native-chatgpt/src/components/ChatGpt.tsx
@@ -113,6 +113,7 @@ export default function ChatGpt({
onAccessTokenChange={(token) => {
setIsWaitingForJWT(false);
setAccessToken(token);
+ modalRef?.current?.close();
}}
onAccumulatedResponse={(result) => callbackRef.current?.(result)}
onStreamError={(error) => errorCallbackRef.current?.(error)}
diff --git a/node_modules/react-native-chatgpt/src/components/ModalWebView.tsx b/node_modules/react-native-chatgpt/src/components/ModalWebView.tsx
index dba7a4d..f85804d 100644
--- a/node_modules/react-native-chatgpt/src/components/ModalWebView.tsx
+++ b/node_modules/react-native-chatgpt/src/components/ModalWebView.tsx
@@ -44,6 +44,7 @@ type Props = PassedProps & PublicProps;
export interface ModalWebViewMethods {
open: () => void;
+ close: () => void;
}
const ModalWebView = forwardRef<ModalWebViewMethods, Props>(
@@ -80,7 +81,7 @@ const ModalWebView = forwardRef<ModalWebViewMethods, Props>(
useImperativeHandle(ref, () => ({
open: () => {
animateWebView('show');
- },
+ },close:()=>{animateWebView('hide');}
}));
useEffect(() => {
diff --git a/node_modules/react-native-chatgpt/src/utils/parseStreamedGptResponse.ts b/node_modules/react-native-chatgpt/src/utils/parseStreamedGptResponse.ts
index 736c607..42b9c2d 100644
--- a/node_modules/react-native-chatgpt/src/utils/parseStreamedGptResponse.ts
+++ b/node_modules/react-native-chatgpt/src/utils/parseStreamedGptResponse.ts
@@ -33,11 +33,17 @@ export default function parseStreamedGptResponse(data: string) {
return null;
}
// @ts-ignore
- const response = JSON.parse(sanitizedChunks[sanitizedChunks.length - 1]);
- return {
- message: response.message.content.parts[0],
- messageId: response.message.id,
- conversationId: response.conversation_id,
- isDone: response.message?.end_turn === true,
- };
+ for(let i=sanitizedChunks.length-1; i>-1;i--){
+ try{
+ const response = JSON.parse(sanitizedChunks[i]);
+ return {
+ message: response.message.content.parts[0],
+ messageId: response.message.id,
+ conversationId: response.conversation_id,
+ isDone: response.message?.end_turn === true,
+ };
+ }catch(e){
+
+ }
+ }
}
This issue body was partially generated by patch-package.