Skip to content

Commit d31193e

Browse files
committed
Initiate Research Run + utils
1 parent 3f56c91 commit d31193e

File tree

5 files changed

+116
-3
lines changed

5 files changed

+116
-3
lines changed

components/utopian_labs/actions/get-run-status/get-run-status.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default {
1111
runId: {
1212
type: "string",
1313
label: "Run ID",
14-
description: "The ID of the run you want to retrieve the status for.",
14+
description: "The ID of the run you want to retrieve the status for",
1515
},
1616
},
1717
async run({ $ }) {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import {
2+
parseObjectEntries, parseStringAsJSON,
3+
} from "../../common/utils.mjs";
4+
import utopianLabs from "../../utopian_labs.app.mjs";
5+
6+
export default {
7+
key: "utopian_labs-initiate-research-run",
8+
name: "Initiate Research Run",
9+
description: "Initiate a research run of the R1 agent. [See the documentation](https://docs.utopianlabs.ai/research#initiate-a-research-run)",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
utopianLabs,
14+
agent: {
15+
propDefinition: [
16+
utopianLabs,
17+
"agent",
18+
],
19+
options: [
20+
{
21+
label: "r1 - a more powerful agent that has access to a larger set of research sources",
22+
value: "r1",
23+
},
24+
{
25+
label: "r1-light - a more affordable version of R1",
26+
value: "r1-light",
27+
},
28+
],
29+
},
30+
lead: {
31+
type: "object",
32+
label: "Lead",
33+
description: "The lead to research. [See the documentation](https://docs.utopianlabs.ai/types#the-lead-type) for more information. Example: `{ \"company\": { \"website\": \"https://pipedream.com/\" } }`",
34+
},
35+
minResearchSteps: {
36+
type: "integer",
37+
label: "Minimum Research Steps",
38+
description: "Optionally limit R1 to a minimum amount of research steps (default is 0)",
39+
optional: true,
40+
},
41+
maxResearchSteps: {
42+
type: "integer",
43+
label: "Maximum Research Steps",
44+
description: "Optionally limit R1 to a maximum amount of research steps (default is 5)",
45+
optional: true,
46+
},
47+
context: {
48+
type: "string",
49+
label: "Context",
50+
description: "The context for the research run. This is a free-form string that will be used to guide R1's research",
51+
optional: true,
52+
},
53+
additionalOptions: {
54+
type: "object",
55+
label: "Additional Options",
56+
description: "Additional parameters to send in the request. [See the documentation](https://docs.utopianlabs.ai/research#initiate-a-research-run) for all available parameters. Values will be parsed as JSON where applicable.",
57+
optional: true,
58+
},
59+
},
60+
async run({ $ }) {
61+
const response = await this.utopianLabs.initiateRun({
62+
agent: this.agent,
63+
lead: parseStringAsJSON(this.lead),
64+
min_research_steps: this.minResearchSteps,
65+
max_research_steps: this.maxResearchSteps,
66+
context: this.context,
67+
...parseObjectEntries(this.additionalOptions),
68+
});
69+
$.export("$summary", `Successfully initiated run (ID: ${response.runId}`);
70+
return response;
71+
},
72+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
3+
function optionalParseAsJSON(value) {
4+
try {
5+
return JSON.parse(value);
6+
} catch (e) {
7+
return value;
8+
}
9+
}
10+
11+
export function parseObjectEntries(value) {
12+
const obj = typeof value === "string"
13+
? JSON.parse(value)
14+
: value;
15+
return Object.fromEntries(
16+
Object.entries(obj).map(([
17+
key,
18+
value,
19+
]) => [
20+
key,
21+
optionalParseAsJSON(value),
22+
]),
23+
);
24+
}
25+
26+
export function parseStringAsJSON(value) {
27+
try {
28+
return typeof value === "string"
29+
? JSON.parse(value)
30+
: value;
31+
} catch (err) {
32+
throw new ConfigurationError(`Error parsing JSON string: ${err}`);
33+
}
34+
}

components/utopian_labs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"utopianlabs": "^0.1.11"
16+
"utopianlabs": "^0.1.11",
17+
"@pipedream/platform": "^3.0.3"
1718
}
1819
}

components/utopian_labs/utopian_labs.app.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { UtopianLabs } from "utopianlabs";
33
export default {
44
type: "app",
55
app: "utopian_labs",
6-
propDefinitions: {},
6+
propDefinitions: {
7+
agent: {
8+
type: "string",
9+
label: "Agent",
10+
description: "The agent to run",
11+
},
12+
},
713
methods: {
814
_client() {
915
return new UtopianLabs({

0 commit comments

Comments
 (0)