Skip to content

Commit

Permalink
chore(ui): update export code to use get_calls
Browse files Browse the repository at this point in the history
  • Loading branch information
gtarpenning committed Jan 14, 2025
1 parent 46b0e9f commit 7faa4d0
Showing 1 changed file with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -529,28 +529,24 @@ function makeCodeText(
sortBy: Array<{field: string; direction: 'asc' | 'desc'}>,
includeFeedback: boolean
) {
let codeStr = `import weave\nassert weave.__version__ >= "0.50.14", "Please upgrade weave!" \n\nclient = weave.init("${entity}/${project}")`;
codeStr += `\ncalls = client.server.calls_query_stream({\n`;
codeStr += ` "project_id": "${entity}/${project}",\n`;

let codeStr = `import weave\nassert weave.__version__ >= "0.51.29", "Please upgrade weave!"\n\napi = weave.init("${project}")`;
codeStr += `\ncalls = api.get_calls(\n`;
const filteredCallIds = callIds ?? filter.callIds;
if (filteredCallIds && filteredCallIds.length > 0) {
codeStr += ` "filter": {"call_ids": ["${filteredCallIds.join(
'", "'
)}"]},\n`;
codeStr += ` filter={"call_ids": ["${filteredCallIds.join('", "')}"]},\n`;
if (expandColumns.length > 0) {
const expandColumnsStr = JSON.stringify(expandColumns, null, 0);
codeStr += ` "expand_columns": ${expandColumnsStr},\n`;
codeStr += ` expand_columns=${expandColumnsStr},\n`;
}
if (includeFeedback) {
codeStr += ` "include_feedback": true,\n`;
codeStr += ` include_feedback=True,\n`;
}
// specifying call_ids ignores other filters, return early
codeStr += `})`;
return codeStr;
}
if (Object.values(filter).some(value => value !== undefined)) {
codeStr += ` "filter": {`;
codeStr += ` filter={`;
if (filter.opVersionRefs) {
codeStr += `"op_names": ["${filter.opVersionRefs.join('", "')}"],`;
}
Expand All @@ -573,21 +569,21 @@ function makeCodeText(
codeStr += `},\n`;
}
if (query) {
codeStr += ` "query": ${JSON.stringify(query, null, 0)},\n`;
codeStr += ` query=${JSON.stringify(query, null, 0)},\n`;
}
if (expandColumns.length > 0) {
const expandColumnsStr = JSON.stringify(expandColumns, null, 0);
codeStr += ` "expand_columns": ${expandColumnsStr},\n`;
codeStr += ` expand_columns=${expandColumnsStr},\n`;
}

if (sortBy.length > 0) {
codeStr += ` "sort_by": ${JSON.stringify(sortBy, null, 0)},\n`;
codeStr += ` sort_by=${JSON.stringify(sortBy, null, 0)},\n`;
}
if (includeFeedback) {
codeStr += ` "include_feedback": True,\n`;
codeStr += ` include_feedback=True,\n`;
}

codeStr += `})`;
codeStr += `)`;

return codeStr;
}
Expand Down

0 comments on commit 7faa4d0

Please sign in to comment.