Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

login view not hide after login; last message does not always contain message in stream mode. #14

Open
lalalic opened this issue Aug 5, 2023 · 0 comments

Comments

@lalalic
Copy link

lalalic commented Aug 5, 2023

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant