Skip to content

Commit 861dfc5

Browse files
committed
Classification and Timing runs
1 parent 335ac53 commit 861dfc5

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import {
2+
parseArrayAsJSON,
3+
parseObjectEntries, parseStringAsJSON,
4+
} from "../../common/utils.mjs";
5+
import utopianLabs from "../../utopian_labs.app.mjs";
6+
7+
export default {
8+
key: "utopian_labs-initiate-classification-run",
9+
name: "Initiate Classification Run",
10+
description: "Initiate a classification run of the R1-Classification agent. [See the documentation](https://docs.utopianlabs.ai/classification#initiate-a-classification-run)",
11+
version: "0.0.1",
12+
type: "action",
13+
props: {
14+
utopianLabs,
15+
agent: {
16+
propDefinition: [
17+
utopianLabs,
18+
"agent",
19+
],
20+
options: [
21+
{
22+
label: "r1-classification - the default research agent, which has access to a larger set of research sources",
23+
value: "r1-classification",
24+
},
25+
{
26+
label: "r1-classification-light - the light research agent, more affordable",
27+
value: "r1-classification-light",
28+
},
29+
],
30+
},
31+
lead: {
32+
propDefinition: [
33+
utopianLabs,
34+
"lead",
35+
],
36+
description: "The lead to determine the classification for. [See the documentation](https://docs.utopianlabs.ai/types#the-lead-type) for more information. Example: `{ \"company\": { \"website\": \"https://pipedream.com/\" } }`",
37+
},
38+
options: {
39+
type: "string[]",
40+
label: "Options",
41+
description: "The options to classify the lead into (minimum 2, maximum 10). Each option should be an object such as: `{ \"name\": \"option name\", \"description\": \"option description\" }`",
42+
},
43+
minResearchSteps: {
44+
propDefinition: [
45+
utopianLabs,
46+
"minResearchSteps",
47+
],
48+
},
49+
maxResearchSteps: {
50+
propDefinition: [
51+
utopianLabs,
52+
"maxResearchSteps",
53+
],
54+
},
55+
context: {
56+
propDefinition: [
57+
utopianLabs,
58+
"context",
59+
],
60+
},
61+
additionalOptions: {
62+
propDefinition: [
63+
utopianLabs,
64+
"additionalOptions",
65+
],
66+
description: "Additional parameters to send in the request. [See the documentation](https://docs.utopianlabs.ai/classification#initiate-a-classification-run) for all available parameters. Values will be parsed as JSON where applicable.",
67+
},
68+
},
69+
async run({ $ }) {
70+
const response = await this.utopianLabs.initiateRun({
71+
agent: this.agent,
72+
lead: parseStringAsJSON(this.lead),
73+
options: parseArrayAsJSON(this.options),
74+
min_research_steps: this.minResearchSteps,
75+
max_research_steps: this.maxResearchSteps,
76+
context: this.context,
77+
...parseObjectEntries(this.additionalOptions),
78+
});
79+
$.export("$summary", `Successfully initiated run (ID: ${response.id}`);
80+
return response;
81+
},
82+
};
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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-timing-run",
8+
name: "Initiate Timing Run",
9+
description: "Initiate a timing run of the R1-Timing agent. [See the documentation](https://docs.utopianlabs.ai/timing#initiate-a-timing-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-timing - the default research agent, which has access to a larger set of research sources",
22+
value: "r1-timing",
23+
},
24+
{
25+
label: "r1-timing-light - the light research agent, more affordable",
26+
value: "r1-timing-light",
27+
},
28+
],
29+
},
30+
lead: {
31+
propDefinition: [
32+
utopianLabs,
33+
"lead",
34+
],
35+
description: "The lead to determine the timing for. [See the documentation](https://docs.utopianlabs.ai/types#the-lead-type) for more information. Example: `{ \"company\": { \"website\": \"https://pipedream.com/\" } }`",
36+
},
37+
minResearchSteps: {
38+
propDefinition: [
39+
utopianLabs,
40+
"minResearchSteps",
41+
],
42+
},
43+
maxResearchSteps: {
44+
propDefinition: [
45+
utopianLabs,
46+
"maxResearchSteps",
47+
],
48+
},
49+
context: {
50+
propDefinition: [
51+
utopianLabs,
52+
"context",
53+
],
54+
},
55+
additionalOptions: {
56+
propDefinition: [
57+
utopianLabs,
58+
"additionalOptions",
59+
],
60+
description: "Additional parameters to send in the request. [See the documentation](https://docs.utopianlabs.ai/timing#initiate-a-timing-run) for all available parameters. Values will be parsed as JSON where applicable.",
61+
},
62+
},
63+
async run({ $ }) {
64+
const response = await this.utopianLabs.initiateRun({
65+
agent: this.agent,
66+
lead: parseStringAsJSON(this.lead),
67+
min_research_steps: this.minResearchSteps,
68+
max_research_steps: this.maxResearchSteps,
69+
context: this.context,
70+
...parseObjectEntries(this.additionalOptions),
71+
});
72+
$.export("$summary", `Successfully initiated run (ID: ${response.id}`);
73+
return response;
74+
},
75+
};

components/utopian_labs/common/utils.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ export function parseStringAsJSON(value) {
3232
throw new ConfigurationError(`Error parsing JSON string: ${err}`);
3333
}
3434
}
35+
36+
export function parseArrayAsJSON(value) {
37+
try {
38+
return value.map((item) => JSON.parse(item));
39+
} catch (err) {
40+
throw new ConfigurationError(`Error parsing JSON string in array: ${err}`);
41+
}
42+
}

0 commit comments

Comments
 (0)