Skip to content

Commit dda3b56

Browse files
danmichaeljonesDan Jones
andauthored
Add option to skip final state when streaming QA (#19)
* Add includeFinalState option to QA streaming * Add overloads to narrow return types --------- Co-authored-by: Dan Jones <[email protected]>
1 parent e6f6c0d commit dda3b56

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/query/agent.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,25 @@ export class QueryAgent {
9797
* @param options - Additional options for the run.
9898
* @returns The response from the query agent.
9999
*/
100+
stream(
101+
query: string,
102+
options: QueryAgentStreamOptions & { includeProgress: false; includeFinalState: false }
103+
): AsyncGenerator<StreamedTokens>;
104+
stream(
105+
query: string,
106+
options: QueryAgentStreamOptions & { includeProgress: false; includeFinalState?: true }
107+
): AsyncGenerator<StreamedTokens | QueryAgentResponse>;
108+
stream(
109+
query: string,
110+
options: QueryAgentStreamOptions & { includeProgress?: true; includeFinalState: false }
111+
): AsyncGenerator<ProgressMessage | StreamedTokens>;
112+
stream(
113+
query: string,
114+
options?: QueryAgentStreamOptions & { includeProgress?: true; includeFinalState?: true }
115+
): AsyncGenerator<ProgressMessage | StreamedTokens | QueryAgentResponse>;
100116
async *stream(
101117
query: string,
102-
{ collections, context, includeProgress }: QueryAgentStreamOptions = {}
118+
{ collections, context, includeProgress, includeFinalState }: QueryAgentStreamOptions = {}
103119
): AsyncGenerator<ProgressMessage | StreamedTokens | QueryAgentResponse> {
104120
const targetCollections = collections ?? this.collections;
105121

@@ -126,6 +142,7 @@ export class QueryAgent {
126142
system_prompt: this.systemPrompt,
127143
previous_response: context ? mapApiResponse(context) : undefined,
128144
include_progress: includeProgress ?? true,
145+
include_final_state: includeFinalState ?? true,
129146
}),
130147
}
131148
);
@@ -177,4 +194,6 @@ export type QueryAgentStreamOptions = {
177194
context?: QueryAgentResponse;
178195
/** Include progress messages in the stream. */
179196
includeProgress?: boolean;
197+
/** Include final state in the stream. */
198+
includeFinalState?: boolean;
180199
};

0 commit comments

Comments
 (0)