Skip to content

Commit

Permalink
intention
Browse files Browse the repository at this point in the history
  • Loading branch information
louyk18 committed Jan 21, 2025
1 parent 315ba11 commit bf7988d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
13 changes: 6 additions & 7 deletions packages/studio-explore/src/components/Report/Intention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,21 +280,20 @@ const Intention: React.FunctionComponent<IReportProps> = props => {
let category_dict = {};
let outputs = {};
let res = { data: [{ data_id: '' }], categories: [] };
let prompt_size_bound = 62.8;
let prompt_size_bound = 120;

while (all_ids.length > 0) {
let filtered_ids = all_ids.slice();
let current_prompt = '';

if (iterate_time === 0) {
while (true) {
const { filtered_nodes, filter_edges } = getInducedSubgraph(nodes, edges, all_ids);
debugger;

const { filtered_nodes, filtered_edges } = getInducedSubgraph(nodes, edges, filtered_ids);

current_prompt = getPrompt({
'zh-CN': TEMPLATE_MIND_MAP_GENERATOR_CHN,
'en-US': TEMPLATE_MIND_MAP_GENERATOR_EN,
})(JSON.stringify({ filtered_nodes, filter_edges }), JSON.stringify(filtered_ids), task);
})(JSON.stringify({ filtered_nodes, filtered_edges }), JSON.stringify(filtered_ids), task);
if (getStrSizeInKB(current_prompt) < prompt_size_bound || filtered_ids.length === 1) {
break;
}
Expand All @@ -311,13 +310,13 @@ const Intention: React.FunctionComponent<IReportProps> = props => {
res = JSON.parse(_res.message.content);
} else {
while (true) {
const { filtered_nodes, filter_edges } = getInducedSubgraph(nodes, edges, all_ids);
const { filtered_nodes, filtered_edges } = getInducedSubgraph(nodes, edges, filtered_ids);

current_prompt = getPrompt({
'zh-CN': TEMPLATE_MIND_MAP_GENERATOR_INCREMENTAL_CHN,
'en-US': TEMPLATE_MIND_MAP_GENERATOR_INCREMENTAL_EN,
})(
JSON.stringify({ filtered_nodes, filter_edges }),
JSON.stringify({ filtered_nodes, filtered_edges }),
JSON.stringify(filtered_ids),
JSON.stringify(category_dict),
task,
Expand Down
18 changes: 9 additions & 9 deletions packages/studio-explore/src/components/Report/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export const filterDataByParticalSchema = (schema, data) => {
return {
id,
label,
source,
target,
source:typeof source ==='object' ? source.id:source,
target:typeof target ==='object' ? target.id:target,
properties: (match.properties || []).reduce((acc, curr) => {
return {
...acc,
Expand Down Expand Up @@ -118,18 +118,18 @@ export const getCategories = (output, categories) => {
};

export const getInducedSubgraph = (nodes, edges, target_nodes) => {
const filter_edges = edges.filter(edge => {
return edge.source in target_nodes || edge.target in target_nodes;
const filtered_edges = edges.filter(edge => {
return target_nodes.includes(edge.source) || target_nodes.includes(edge.target);
});
console.log(filter_edges);

const connectedNodeIds = new Set();
filter_edges.forEach(edge => {
connectedNodeIds.add(edge.source.id);
connectedNodeIds.add(edge.target.id);
filtered_edges.forEach(edge => {
connectedNodeIds.add(edge.source);
connectedNodeIds.add(edge.target);
});
const filtered_nodes = nodes.filter(node => connectedNodeIds.has(node.id));

return { filtered_nodes, filter_edges };
return { filtered_nodes, filtered_edges };
}

import { Utils } from '@graphscope/studio-components';
Expand Down

0 comments on commit bf7988d

Please sign in to comment.