Skip to content
Merged
Show file tree
Hide file tree
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
99 changes: 99 additions & 0 deletions components/cohere_platform/actions/chat/chat.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import app from "../../cohere_platform.app.mjs";
import { clearObj } from "../../common/utils.mjs";

export default {
key: "cohere_platform-chat",
name: "Chat",
version: "0.0.1",
description: "Generates a text response to a user message. [See the documentation](https://docs.cohere.com/reference/chat)",
type: "action",
props: {
app,
message: {
propDefinition: [
app,
"message",
],
},
model: {
propDefinition: [
app,
"model",
],
},
temperature: {
propDefinition: [
app,
"temperature",
],
},
maxTokens: {
propDefinition: [
app,
"maxTokens",
],
},
k: {
propDefinition: [
app,
"k",
],
},
p: {
propDefinition: [
app,
"p",
],
},
stopSequences: {
propDefinition: [
app,
"stopSequences",
],
},
frequencyPenalty: {
propDefinition: [
app,
"frequencyPenalty",
],
},
},
methods: {
chat(data) {
return this.app.client().chat(data);
},
},
async run({ $ }) {
const {
chat,
message,
model,
temperature,
maxTokens,
k,
p,
stopSequences,
frequencyPenalty,

} = this;
const response = await chat(clearObj({
message,
model,
...(temperature && {
temperature: parseFloat(temperature),
}),
maxTokens,
k,
...(p && {
p: parseFloat(p),
}),
stopSequences,
...(frequencyPenalty && {
frequencyPenalty: parseFloat(frequencyPenalty),
}),
}));

$.export("$summary", `The message was successfully responded with ID \`${response.response_id}\``);
return response;
},
};

This file was deleted.

72 changes: 43 additions & 29 deletions components/cohere_platform/actions/classify-text/classify-text.mjs
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
import coherePlatform from "../../cohere_platform.app.mjs";
import app from "../../cohere_platform.app.mjs";
import { clearObj } from "../../common/utils.mjs";

export default {
key: "cohere_platform-classify-text",
name: "Classify Text",
version: "0.0.1",
description: "This action makes a prediction about which label fits the specified text inputs best. [See the docs here](https://docs.cohere.com/reference/classify)",
version: "0.1.0",
description: "This action makes a prediction about which label fits the specified text inputs best. [See the documentation](https://docs.cohere.com/reference/classify-1)",
type: "action",
props: {
coherePlatform,
app,
inputs: {
type: "string[]",
label: "Inputs",
description: "Represents a list of queries to be classified, each entry must not be empty. The maximum is 96 inputs.",
},
classifyModel: {
model: {
propDefinition: [
coherePlatform,
app,
"classifyModel",
],
},
preset: {
propDefinition: [
coherePlatform,
app,
"preset",
],
},
truncate: {
propDefinition: [
coherePlatform,
app,
"truncate",
],
},
numExamples: {
type: "integer",
label: "Number of Examples",
description: "To make a prediction, Classify uses provided examples of text + label pairs. Specify the number of examples to provide. Each example is a text string and its associated label/class. At least 2 labels must be provided.",
description: "To make a prediction, Classify uses provided examples of text + label pairs. Specify the number of examples to provide. Each example is a text string and its associated label/class. At least 2 unique labels must be provided and each label should have at least 2 different examples.",
default: 4,
reloadProps: true,
},
},
async additionalProps() {
additionalProps() {
const props = {};

for (let i = 0; i < this.numExamples; i++) {
Expand All @@ -56,28 +58,40 @@ export default {

return props;
},
methods: {
getExamples() {
const examples = [];
for (let i = 0; i < this.numExamples; i++) {
examples.push({
text: this[`text_${i}`],
label: this[`label_${i}`],
});
}
return examples;
},
classifyText(data) {
return this.app.client().classify(data);
},
},
async run({ $ }) {
const examples = [];
for (let i = 0; i < this.numExamples; i++) {
examples.push({
text: this[`text_${i}`],
label: this[`label_${i}`],
});
}

const response = await this.coherePlatform.classifyText({
inputs: this.inputs,
model: this.model,
preset: this.preset,
truncate: this.truncate,
examples,
});
const {
classifyText,
inputs,
model,
preset,
truncate,
getExamples,
} = this;

if (response.statusCode != "200") {
throw new Error(response.body.message);
}
const response = await classifyText(clearObj({
inputs,
model,
preset,
truncate,
examples: getExamples(),
}));

$.export("$summary", "The text was successfully classified.");
$.export("$summary", `The text was successfully classified with ID \`${response.id}\``);
return response;
},
};
147 changes: 0 additions & 147 deletions components/cohere_platform/actions/common/base.mjs

This file was deleted.

Loading