-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Cannot fetch stream api response #48314
Comments
Warning Unsupported version: It looks like your issue or the example you provided uses an unsupported version of React Native. |
Warning Unsupported version: It looks like your issue or the example you provided uses an unsupported version of React Native. |
upgraded react-native 0.75.4 and trying now |
0.75.4 has same issue |
Hi @huseyinaltas, It would be really helpful if you could provide a sample reproducer. You can use this template to create one. Also, I noticed that the link to your repository (Shock) is returning a 404 error, so I’m unable to access it. Could you let me know if this issue is platform-specific (i.e., Android or iOS)? I see that you're using the old architecture—would it be possible to try with the new architecture as well? |
Description
When I implement this fetch curl api on node.js standalone project, I get stream response,
And I implement in react-native project I cannot get response
async function chat(prompt) {
const API_KEY = "XXXX";
const url = new URL(
https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:streamGenerateContent?key={API_KEY}
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
contents: [
{
parts: [{ text: prompt }],
},
],
}),
});
if (!response.ok) {
console.error("Request failed", response.statusText);
return;
}
const reader = response.body.getReader();
const decoder = new TextDecoder();
let done = false;
let content = "";
while (!done) {
const { value, done: readerDone } = await reader.read();
done = readerDone;
content += decoder.decode(value, { stream: true });
console.log(content);
}
// Final content received
console.log("Final Content:", content);
}
Steps to reproduce
Copy above code and use fetch in single node.js project
It gets logging out stream response
When I copy and past on react-native project
And I call it,
Not getting response.body in fetch
"dependencies": {
"@google/generative-ai": "^0.21.0",
"@react-native-firebase/analytics": "^19.3.0",
"@react-native-firebase/app": "^19.3.0",
"@react-native-firebase/auth": "^19.3.0",
"@react-native-firebase/firestore": "19.3.0",
"@react-native-firebase/functions": "^19.3.0",
"@react-native-firebase/messaging": "^19.3.0",
"@react-native-firebase/remote-config": "^19.3.0",
"@react-navigation/stack": "^6.3.29",
"axios": "^1.7.9",
"country-flag-icons": "^1.5.13",
"https-browserify": "^1.0.0",
"moment-timezone": "^0.5.45",
"react": "18.2.0",
"react-native": "^0.73.9",
"react-native-device-info": "^10.13.1",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "^2.16.1",
"react-native-keychain": "^8.1.3",
"react-native-localize": "^3.2.1",
"react-native-paper": "^5.12.3",
"react-native-safe-area-context": "^4.9.0",
"react-native-screens": "^3.29.0",
"react-native-sound": "^0.11.2",
"react-native-sse": "^1.2.1",
"react-native-vector-icons": "^10.0.3"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@react-native/babel-preset": "0.73.21",
"@react-native/eslint-config": "0.73.2",
"@react-native/metro-config": "0.73.5",
"@react-native/typescript-config": "0.73.1",
"@types/react": "^18.2.6",
"@types/react-native-vector-icons": "^6.4.18",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.6.3",
"eslint": "^8.19.0",
"jest": "^29.6.3",
"prettier": "2.8.8",
"react-test-renderer": "18.2.0",
"typescript": "5.0.4"
},
React Native Version
"react-native": "^0.73.9"
Affected Platforms
Runtime - Android, Runtime - iOS
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/huseyinaltas/Shock
Screenshots and Videos
No response
The text was updated successfully, but these errors were encountered: