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

better json streaming and filtering #1898

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions client-report/src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,17 @@ const App = (props) => {
const decodedChunk = decoder.decode(value, { stream: true });

if (!decodedChunk.includes("POLIS-PING:")) {
const c = JSON.parse(decodedChunk);
setNarrative((prevNarrative) => ({
...(prevNarrative || {}),
...c,
}));
decodedChunk.split(`|||`).filter(Boolean).forEach((j) => {
try {
const c = JSON.parse(j);
setNarrative((prevNarrative) => ({
...(prevNarrative || {}),
...c,
}))
} catch (error) {
console.log(error, j)
}
});
}
}
};
Expand Down
2 changes: 0 additions & 2 deletions client-report/src/components/lists/consensusNarrative.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ const ConsensusNarrative = ({
try {
const txt =
model === "claude" ? narrative.responseClaude.content[0].text : narrative.responseGemini;
console.log("Raw narrative text:", txt); // Log raw text

const narrativeJSON = model === "claude" ? JSON.parse(`{${txt}`) : JSON.parse(txt);
console.log("Parsed narrative JSON:", narrativeJSON); // Log parsed JSON

// Extract all citation IDs from the narrative structure
const uniqueTids = narrativeJSON.paragraphs.reduce((acc, paragraph) => {
Expand Down
2 changes: 0 additions & 2 deletions client-report/src/components/lists/groupsNarrative.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ const GroupsNarrative = ({
try {
const txt =
model === "claude" ? narrative?.responseClaude.content[0].text : narrative?.responseGemini;
console.log("Raw narrative text:", txt); // Log raw text

const narrativeJSON = model === "claude" ? JSON.parse(`{${txt}`) : JSON.parse(txt);
console.log("Parsed narrative JSON:", narrativeJSON); // Log parsed JSON

// Extract all citation IDs from the narrative structure
const uniqueTids = narrativeJSON.paragraphs.reduce((acc, paragraph) => {
Expand Down
2 changes: 0 additions & 2 deletions client-report/src/components/lists/topicNarrative.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ const TopicNarrative = ({
try {
const txt =
model === "claude" ? narrative?.responseClaude.content[0].text : narrative?.responseGemini;
console.log(`Raw narrative text for topic ${topicName}:`, txt);

const narrativeJSON = model === "claude" ? JSON.parse(`{${txt}`) : JSON.parse(txt);
console.log(`Parsed narrative JSON for topic ${topicName}:`, narrativeJSON);

// Extract all citation IDs from the narrative structure
const uniqueTids = narrativeJSON.paragraphs.reduce((acc, paragraph) => {
Expand Down
2 changes: 0 additions & 2 deletions client-report/src/components/lists/uncertaintyNarrative.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ const UncertaintyNarrative = ({
try {
const txt =
model === "claude" ? narrative?.responseClaude.content[0].text : narrative?.responseGemini;
console.log("Raw narrative text:", txt); // Log raw text

const narrativeJSON = model === "claude" ? JSON.parse(`{${txt}`) : JSON.parse(txt);
console.log("Parsed narrative JSON:", narrativeJSON); // Log parsed JSON

// Extract all citation IDs from the narrative structure
const uniqueTids = narrativeJSON.paragraphs.reduce((acc, paragraph) => {
Expand Down
6 changes: 3 additions & 3 deletions server/src/routes/reportNarrative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export async function handle_GET_reportNarrative(
? "NO_CONTENT_AFTER_FILTER"
: undefined,
},
})
}) + `|||`
);
} else {
if (
Expand Down Expand Up @@ -370,7 +370,7 @@ export async function handle_GET_reportNarrative(
? "NO_CONTENT_AFTER_FILTER"
: undefined,
},
})
}) + `|||`
);
} else {
const responseClaude = await anthropic.messages.create({
Expand Down Expand Up @@ -441,7 +441,7 @@ export async function handle_GET_reportNarrative(
? "NO_CONTENT_AFTER_FILTER"
: undefined,
},
})
}) + `|||`
);
}
}
Expand Down
Loading