Rooni commited on
Commit
c2ca7e4
·
verified ·
1 Parent(s): 2a4f441

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +14 -4
server.js CHANGED
@@ -79,12 +79,22 @@ app.post('/gen', async (req, res) => {
79
  'x-goog-api-key': `${openai_key}`,
80
  'Content-Type': 'application/json',
81
  },
 
82
  });
83
 
84
- console.log(response.data);
85
-
86
- const content = JSON.parse(response.data);
87
- res.json({ content: content.candidates[0].content.parts.map(part => part.text).join('') });
 
 
 
 
 
 
 
 
 
88
 
89
  /*
90
  if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
 
79
  'x-goog-api-key': `${openai_key}`,
80
  'Content-Type': 'application/json',
81
  },
82
+ responseType: 'stream',
83
  });
84
 
85
+ let fullData = '';
86
+ response.data.on('data', (chunk) => {
87
+ fullData += chunk.toString();
88
+ });
89
+
90
+ await new Promise((resolve) => {
91
+ response.data.on('end', () => {
92
+ resolve();
93
+ });
94
+ });
95
+
96
+ const jsonData = JSON.parse(fullData);
97
+ res.json({ content: jsonData.candidates[0].content.parts.map(part => part.text).join('') });
98
 
99
  /*
100
  if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {