Skip to content

Commit fc2caed

Browse files
authored
fix: truncated JSON formate issue (#57)
1 parent 8a72d5f commit fc2caed

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

.github/workflows/release-template.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
name: Release Template
22

33
on:
4-
push:
5-
branches: [ "main" ]
6-
pull_request:
7-
branches: [ "main" ]
4+
workflow_dispatch:
5+
inputs:
6+
reason:
7+
description: 'the reason for triggering this workflow'
8+
required: false
9+
default: 'manually publish the ecr images and templates'
810
jobs:
911
release_template:
1012
runs-on: ubuntu-latest

react-native/src/api/ollama-api.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ export const invokeOllamaWithCallBack = async (
100100
callback(completeMessage, done, false);
101101
}
102102
if (done) {
103+
if (lastChunk.length > 0) {
104+
callback(
105+
completeMessage + '\n\n' + '**Parse error**:\n' + lastChunk,
106+
true,
107+
true,
108+
undefined
109+
);
110+
}
103111
return;
104112
}
105113
} catch (readError) {
@@ -155,11 +163,10 @@ const parseStreamData = (chunk: string, lastChunk: string = '') => {
155163
};
156164
}
157165
} catch (error) {
158-
if (lastChunk.length > 0) {
159-
return { error: error + chunk };
160-
}
161-
if (content.length > 0) {
166+
if (dataChunk === dataChunks[dataChunks.length - 1]) {
162167
return { content, dataChunk, usage };
168+
} else {
169+
return { error: chunk };
163170
}
164171
}
165172
}

react-native/src/api/open-api.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ export const invokeOpenAIWithCallBack = async (
134134
);
135135
}
136136
if (done) {
137+
if (lastChunk.length > 0) {
138+
callback(
139+
completeMessage + '\n\n' + '**Parse error**:\n' + lastChunk,
140+
true,
141+
true,
142+
undefined,
143+
completeReasoning
144+
);
145+
}
137146
return;
138147
}
139148
} catch (readError) {
@@ -226,17 +235,11 @@ const parseStreamData = (chunk: string, lastChunk: string = '') => {
226235
};
227236
}
228237
} catch (error) {
229-
if (lastChunk.length > 0) {
238+
if (dataChunk === dataChunks[dataChunks.length - 1]) {
230239
return { reason, content, dataChunk, usage };
231-
} else if (reason === '' && content === '') {
232-
if (dataChunk === 'data: ') {
233-
return { reason, content, dataChunk, usage };
234-
}
240+
} else {
235241
return { error: chunk };
236242
}
237-
if (reason || content) {
238-
return { reason, content, dataChunk, usage };
239-
}
240243
}
241244
}
242245
return { reason, content, usage };

0 commit comments

Comments
 (0)