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

Make it smarter bytecode #103

Open
wants to merge 2 commits into
base: dev-make-it-smarter
Choose a base branch
from
Open
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
95 changes: 91 additions & 4 deletions explore-assistant-extension/src/hooks/useSendVertexMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,97 @@ ${
}
const currentDateTime = new Date().toISOString()

let exampleText = ''
if(exploreGenerationExamples && exploreGenerationExamples.length > 0) {
exampleText = exploreGenerationExamples.map((item) => `input: "${item.input}" ; output: ${item.output}`).join('\n')
}
const parseLookerURL = (url: string): { [key: string]: any } => {
// Split URL and extract model & explore
const urlSplit = url.split("?");
let model = ""
let explore = ""
let queryString = ""
if (urlSplit.length == 2) {
const rootURL = urlSplit[0]
queryString = urlSplit[1]
const rootURLElements = rootURL.split("/");
model = rootURLElements[rootURLElements.length - 2];
explore = rootURLElements[rootURLElements.length - 1];
}
else if (urlSplit.length == 1) {
model = "tbd"
explore = "tbd"
queryString = urlSplit[0]
}
// Initialize lookerEncoding object
const lookerEncoding: { [key: string]: any } = {};
lookerEncoding['model'] = ""
lookerEncoding['explore'] = ""
lookerEncoding['fields'] = []
lookerEncoding['pivots'] = []
lookerEncoding['fill_fields'] = []
lookerEncoding['filters'] = {}
lookerEncoding['filter_expression'] = null
lookerEncoding['sorts'] = []
lookerEncoding['limit'] = 500
lookerEncoding['column_limit'] = 50
lookerEncoding['total'] = null
lookerEncoding['row_total'] = null
lookerEncoding['subtotals'] = null
lookerEncoding['vis'] = []
// Split query string and iterate key-value pairs
const keyValuePairs = queryString.split("&");
for (const qq of keyValuePairs) {
const [key, value] = qq.split('=');
console.log(qq)
lookerEncoding['model'] = model
lookerEncoding['explore'] = explore
switch (key) {
case "fields":
case "pivots":
case "fill_fields":
case "sorts":
lookerEncoding[key] = value.split(",");
break;
case "filter_expression":
case "total":
case "row_total":
case "subtotals":
lookerEncoding[key] = value;
break;
case "limit":
case "column_limit":
lookerEncoding[key] = parseInt(value);
break;
case "vis":
lookerEncoding[key] = JSON.parse(decodeURIComponent(value));
break;
default:
if (key.startsWith("f[")) {
const filterKey = key.slice(2, -1);
lookerEncoding.filters[filterKey] = value;
} else if (key.includes(".")) {
const path = key.split(".");
let currentObject = lookerEncoding;
for (let i = 0; i < path.length - 1; i++) {
const segment = path[i];
if (!currentObject[segment]) {
currentObject[segment] = {};
}
currentObject = currentObject[segment];
}
currentObject[path[path.length - 1]] = value;
}
}
}
return lookerEncoding;
};






let exampleText = ''
if(exploreGenerationExamples && exploreGenerationExamples.length > 0) {
exampleText = exploreGenerationExamples.map((item) => `input: "${item.input}" ; output: ${JSON.stringify(parseLookerURL(item.output))}`).join('\n')
}

const contents = `
# Context
Expand Down