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

fix: source nodes is empty #1391

Merged
merged 2 commits into from
Oct 24, 2024
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
5 changes: 5 additions & 0 deletions .changeset/pretty-swans-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@llamaindex/core": patch
---

fix: source nodes is empty
4 changes: 2 additions & 2 deletions packages/core/src/response-synthesizers/base-synthesizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export abstract class BaseSynthesizer extends PromptMixin {
let response: EngineResponse | AsyncIterable<EngineResponse>;
if (query.nodes.length === 0) {
if (stream) {
response = EngineResponse.fromResponse("Empty Response", true);
response = EngineResponse.fromResponse("Empty Response", true, []);
} else {
response = EngineResponse.fromResponse("Empty Response", false);
response = EngineResponse.fromResponse("Empty Response", false, []);
}
} else {
const queryMessage: MessageContent =
Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/response-synthesizers/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ class Refine extends BaseSynthesizer {

// fixme: no source nodes provided, cannot fix right now due to lack of context
if (typeof response === "string") {
return EngineResponse.fromResponse(response, false);
return EngineResponse.fromResponse(response, false, nodes);
} else {
return streamConverter(response!, (text) =>
EngineResponse.fromResponse(text, true),
EngineResponse.fromResponse(text, true, nodes),
);
}
}
Expand Down Expand Up @@ -293,12 +293,13 @@ class TreeSummarize extends BaseSynthesizer {
if (stream) {
const response = await this.llm.complete({ ...params, stream });
return streamConverter(response, (chunk) =>
EngineResponse.fromResponse(chunk.text, true),
EngineResponse.fromResponse(chunk.text, true, nodes),
);
}
return EngineResponse.fromResponse(
(await this.llm.complete(params)).text,
false,
nodes,
);
} else {
const summaries = await Promise.all(
Expand Down Expand Up @@ -393,13 +394,13 @@ class MultiModal extends BaseSynthesizer {
stream,
});
return streamConverter(response, ({ text }) =>
EngineResponse.fromResponse(text, true),
EngineResponse.fromResponse(text, true, nodes),
);
}
const response = await llm.complete({
prompt,
});
return EngineResponse.fromResponse(response.text, false);
return EngineResponse.fromResponse(response.text, false, nodes);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/schema/type/engine–response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class EngineResponse implements ChatResponse, ChatResponseChunk {
static fromResponse(
response: string,
stream: boolean,
sourceNodes?: NodeWithScore[],
sourceNodes: NodeWithScore[],
): EngineResponse {
return new EngineResponse(
EngineResponse.toChatResponse(response),
Expand Down