flowquery 1.0.24 → 1.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.yml +1 -0
- package/.husky/pre-commit +3 -2
- package/dist/flowquery.min.js +1 -1
- package/dist/parsing/parser.d.ts.map +1 -1
- package/dist/parsing/parser.js +1 -0
- package/dist/parsing/parser.js.map +1 -1
- package/dist/tokenization/string_walker.d.ts.map +1 -1
- package/dist/tokenization/string_walker.js +13 -12
- package/dist/tokenization/string_walker.js.map +1 -1
- package/docs/flowquery.min.js +1 -1
- package/flowquery-py/pyproject.toml +1 -1
- package/flowquery-py/src/parsing/parser.py +1 -0
- package/flowquery-py/src/tokenization/string_walker.py +1 -1
- package/flowquery-py/tests/compute/test_runner.py +26 -0
- package/flowquery-py/tests/parsing/test_parser.py +64 -0
- package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
- package/jest.config.js +6 -9
- package/misc/apps/RAG/data/chats.json +302 -0
- package/misc/apps/RAG/data/emails.json +182 -0
- package/misc/apps/RAG/data/events.json +226 -0
- package/misc/apps/RAG/data/files.json +172 -0
- package/misc/apps/RAG/data/users.json +158 -0
- package/misc/apps/RAG/jest.config.js +21 -0
- package/misc/apps/RAG/package.json +9 -2
- package/misc/apps/RAG/src/App.tsx +5 -5
- package/misc/apps/RAG/src/components/ChatContainer.tsx +53 -124
- package/misc/apps/RAG/src/components/FlowQueryAgent.ts +151 -157
- package/misc/apps/RAG/src/components/index.ts +1 -1
- package/misc/apps/RAG/src/graph/index.ts +19 -0
- package/misc/apps/RAG/src/graph/initializeGraph.ts +254 -0
- package/misc/apps/RAG/src/index.tsx +25 -13
- package/misc/apps/RAG/src/prompts/FlowQuerySystemPrompt.ts +146 -231
- package/misc/apps/RAG/src/prompts/index.ts +4 -4
- package/misc/apps/RAG/src/tests/graph.test.ts +35 -0
- package/misc/apps/RAG/src/utils/FlowQueryExecutor.ts +20 -21
- package/misc/apps/RAG/src/utils/FlowQueryExtractor.ts +35 -30
- package/misc/apps/RAG/src/utils/Llm.ts +248 -0
- package/misc/apps/RAG/src/utils/index.ts +7 -4
- package/misc/apps/RAG/tsconfig.json +4 -3
- package/misc/apps/RAG/webpack.config.js +40 -40
- package/package.json +1 -1
- package/src/parsing/parser.ts +1 -0
- package/src/tokenization/string_walker.ts +19 -16
- package/tests/compute/runner.test.ts +1 -1
- package/tests/parsing/parser.test.ts +61 -0
- package/misc/apps/RAG/src/plugins/README.md +0 -139
- package/misc/apps/RAG/src/plugins/index.ts +0 -72
- package/misc/apps/RAG/src/plugins/loaders/CatFacts.ts +0 -70
- package/misc/apps/RAG/src/plugins/loaders/FetchJson.ts +0 -65
- package/misc/apps/RAG/src/plugins/loaders/Form.ts +0 -594
- package/misc/apps/RAG/src/plugins/loaders/Llm.ts +0 -450
- package/misc/apps/RAG/src/plugins/loaders/MockData.ts +0 -101
- package/misc/apps/RAG/src/plugins/loaders/Table.ts +0 -274
- package/misc/apps/RAG/src/plugins/loaders/Weather.ts +0 -138
|
@@ -2,16 +2,11 @@ import React, { Component, createRef, RefObject } from 'react';
|
|
|
2
2
|
import { Spinner } from '@fluentui/react-components';
|
|
3
3
|
import { ChatMessage, Message } from './ChatMessage';
|
|
4
4
|
import { ChatInput } from './ChatInput';
|
|
5
|
-
import {
|
|
6
|
-
import { processQueryStream } from './FlowQueryAgent';
|
|
5
|
+
import { FlowQueryAgent } from './FlowQueryAgent';
|
|
7
6
|
import './ChatContainer.css';
|
|
8
7
|
|
|
9
8
|
interface ChatContainerProps {
|
|
10
9
|
systemPrompt?: string;
|
|
11
|
-
llmOptions?: LlmOptions;
|
|
12
|
-
useStreaming?: boolean;
|
|
13
|
-
/** Whether to use the FlowQuery agent for processing queries */
|
|
14
|
-
useFlowQueryAgent?: boolean;
|
|
15
10
|
/** Whether to show intermediate steps (query generation, execution) */
|
|
16
11
|
showIntermediateSteps?: boolean;
|
|
17
12
|
}
|
|
@@ -25,12 +20,11 @@ interface ChatContainerState {
|
|
|
25
20
|
export class ChatContainer extends Component<ChatContainerProps, ChatContainerState> {
|
|
26
21
|
static defaultProps: Partial<ChatContainerProps> = {
|
|
27
22
|
systemPrompt: 'You are a helpful assistant. Be concise and informative in your responses.',
|
|
28
|
-
llmOptions: {},
|
|
29
|
-
useStreaming: true,
|
|
30
|
-
useFlowQueryAgent: true,
|
|
31
23
|
showIntermediateSteps: true
|
|
32
24
|
};
|
|
33
25
|
|
|
26
|
+
private readonly agent = new FlowQueryAgent();
|
|
27
|
+
|
|
34
28
|
private messagesEndRef: RefObject<HTMLDivElement | null>;
|
|
35
29
|
|
|
36
30
|
constructor(props: ChatContainerProps) {
|
|
@@ -65,7 +59,7 @@ export class ChatContainer extends Component<ChatContainerProps, ChatContainerSt
|
|
|
65
59
|
};
|
|
66
60
|
|
|
67
61
|
private handleSendMessage = async (content: string): Promise<void> => {
|
|
68
|
-
const { systemPrompt,
|
|
62
|
+
const { systemPrompt, showIntermediateSteps } = this.props;
|
|
69
63
|
const { messages } = this.state;
|
|
70
64
|
|
|
71
65
|
const userMessage: Message = {
|
|
@@ -88,134 +82,69 @@ export class ChatContainer extends Component<ChatContainerProps, ChatContainerSt
|
|
|
88
82
|
|
|
89
83
|
try {
|
|
90
84
|
const conversationHistory = this.buildConversationHistory([...messages, userMessage]);
|
|
91
|
-
|
|
92
|
-
if (useFlowQueryAgent) {
|
|
93
|
-
// Use the FlowQuery agent for processing
|
|
94
|
-
const assistantMessage: Message = {
|
|
95
|
-
id: assistantMessageId,
|
|
96
|
-
role: 'assistant',
|
|
97
|
-
content: '',
|
|
98
|
-
timestamp: new Date(),
|
|
99
|
-
isStreaming: true
|
|
100
|
-
};
|
|
101
|
-
this.setState(prev => ({
|
|
102
|
-
messages: [...prev.messages, assistantMessage]
|
|
103
|
-
}));
|
|
104
|
-
|
|
105
|
-
let fullContent = '';
|
|
106
|
-
let adaptiveCardFromStream: Record<string, unknown> | undefined;
|
|
107
|
-
|
|
108
|
-
for await (const { chunk, done, adaptiveCard, newMessage } of processQueryStream(content, {
|
|
109
|
-
systemPrompt: systemPrompt ?? 'You are a helpful assistant. Be concise and informative in your responses.',
|
|
110
|
-
llmOptions,
|
|
111
|
-
conversationHistory: conversationHistory.slice(0, -1),
|
|
112
|
-
showIntermediateSteps
|
|
113
|
-
})) {
|
|
114
|
-
// If newMessage flag is set, finalize current message and start a new one
|
|
115
|
-
if (newMessage) {
|
|
116
|
-
// Create a new assistant message for the retry
|
|
117
|
-
const previousMessageId = currentMessageId;
|
|
118
|
-
currentMessageId = this.generateMessageId();
|
|
119
|
-
fullContent = '';
|
|
120
|
-
const newAssistantMessage: Message = {
|
|
121
|
-
id: currentMessageId,
|
|
122
|
-
role: 'assistant',
|
|
123
|
-
content: '',
|
|
124
|
-
timestamp: new Date(),
|
|
125
|
-
isStreaming: true
|
|
126
|
-
};
|
|
127
|
-
// Mark previous message as done streaming AND add new message atomically
|
|
128
|
-
this.setState(prev => ({
|
|
129
|
-
messages: [...prev.messages.map(msg =>
|
|
130
|
-
msg.id === previousMessageId
|
|
131
|
-
? { ...msg, isStreaming: false }
|
|
132
|
-
: msg
|
|
133
|
-
), newAssistantMessage]
|
|
134
|
-
}));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (chunk) {
|
|
138
|
-
fullContent += chunk;
|
|
139
|
-
this.setState(prev => ({
|
|
140
|
-
messages: prev.messages.map(msg =>
|
|
141
|
-
msg.id === currentMessageId
|
|
142
|
-
? { ...msg, content: fullContent }
|
|
143
|
-
: msg
|
|
144
|
-
)
|
|
145
|
-
}));
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Capture adaptive card if present
|
|
149
|
-
if (adaptiveCard) {
|
|
150
|
-
adaptiveCardFromStream = adaptiveCard;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (done) {
|
|
154
|
-
this.setState(prev => ({
|
|
155
|
-
messages: prev.messages.map(msg =>
|
|
156
|
-
msg.id === currentMessageId
|
|
157
|
-
? { ...msg, isStreaming: false, adaptiveCard: adaptiveCardFromStream }
|
|
158
|
-
: msg
|
|
159
|
-
)
|
|
160
|
-
}));
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
} else {
|
|
164
|
-
// Original LLM-only behavior (kept for backward compatibility)
|
|
165
|
-
const { llm, llmStream } = await import('../plugins/loaders/Llm');
|
|
166
|
-
|
|
167
|
-
const options: LlmOptions = {
|
|
168
|
-
...llmOptions,
|
|
169
|
-
systemPrompt,
|
|
170
|
-
messages: conversationHistory.slice(0, -1),
|
|
171
|
-
};
|
|
172
85
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
86
|
+
const assistantMessage: Message = {
|
|
87
|
+
id: assistantMessageId,
|
|
88
|
+
role: 'assistant',
|
|
89
|
+
content: '',
|
|
90
|
+
timestamp: new Date(),
|
|
91
|
+
isStreaming: true
|
|
92
|
+
};
|
|
93
|
+
this.setState(prev => ({
|
|
94
|
+
messages: [...prev.messages, assistantMessage]
|
|
95
|
+
}));
|
|
96
|
+
|
|
97
|
+
let fullContent = '';
|
|
98
|
+
let adaptiveCardFromStream: Record<string, unknown> | undefined;
|
|
99
|
+
|
|
100
|
+
for await (const { chunk, done, adaptiveCard, newMessage } of this.agent.processQueryStream(content, {
|
|
101
|
+
systemPrompt: systemPrompt ?? 'You are a helpful assistant. Be concise and informative in your responses.',
|
|
102
|
+
conversationHistory: conversationHistory.slice(0, -1),
|
|
103
|
+
showIntermediateSteps
|
|
104
|
+
})) {
|
|
105
|
+
// If newMessage flag is set, finalize current message and start a new one
|
|
106
|
+
if (newMessage) {
|
|
107
|
+
const previousMessageId = currentMessageId;
|
|
108
|
+
currentMessageId = this.generateMessageId();
|
|
109
|
+
fullContent = '';
|
|
110
|
+
const newAssistantMessage: Message = {
|
|
111
|
+
id: currentMessageId,
|
|
176
112
|
role: 'assistant',
|
|
177
113
|
content: '',
|
|
178
114
|
timestamp: new Date(),
|
|
179
115
|
isStreaming: true
|
|
180
116
|
};
|
|
181
117
|
this.setState(prev => ({
|
|
182
|
-
messages: [...prev.messages
|
|
118
|
+
messages: [...prev.messages.map(msg =>
|
|
119
|
+
msg.id === previousMessageId
|
|
120
|
+
? { ...msg, isStreaming: false }
|
|
121
|
+
: msg
|
|
122
|
+
), newAssistantMessage]
|
|
183
123
|
}));
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if (deltaContent) {
|
|
189
|
-
fullContent += deltaContent;
|
|
190
|
-
this.setState(prev => ({
|
|
191
|
-
messages: prev.messages.map(msg =>
|
|
192
|
-
msg.id === assistantMessageId
|
|
193
|
-
? { ...msg, content: fullContent }
|
|
194
|
-
: msg
|
|
195
|
-
)
|
|
196
|
-
}));
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (chunk) {
|
|
127
|
+
fullContent += chunk;
|
|
200
128
|
this.setState(prev => ({
|
|
201
129
|
messages: prev.messages.map(msg =>
|
|
202
|
-
msg.id ===
|
|
203
|
-
? { ...msg,
|
|
130
|
+
msg.id === currentMessageId
|
|
131
|
+
? { ...msg, content: fullContent }
|
|
204
132
|
: msg
|
|
205
133
|
)
|
|
206
134
|
}));
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
content: assistantContent,
|
|
215
|
-
timestamp: new Date()
|
|
216
|
-
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (adaptiveCard) {
|
|
138
|
+
adaptiveCardFromStream = adaptiveCard;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (done) {
|
|
217
142
|
this.setState(prev => ({
|
|
218
|
-
messages:
|
|
143
|
+
messages: prev.messages.map(msg =>
|
|
144
|
+
msg.id === currentMessageId
|
|
145
|
+
? { ...msg, isStreaming: false, adaptiveCard: adaptiveCardFromStream }
|
|
146
|
+
: msg
|
|
147
|
+
)
|
|
219
148
|
}));
|
|
220
149
|
}
|
|
221
150
|
}
|