Merge pull request #2299 from automatisch/anthropic-ai-integration
feat(anthropic): add anthropic app with send message action
This commit is contained in:
3
packages/backend/src/apps/anthropic/actions/index.js
Normal file
3
packages/backend/src/apps/anthropic/actions/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import sendMessage from './send-message/index.js';
|
||||
|
||||
export default [sendMessage];
|
||||
@@ -0,0 +1,124 @@
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
const castFloatOrUndefined = (value) => {
|
||||
return value === '' ? undefined : parseFloat(value);
|
||||
};
|
||||
|
||||
export default defineAction({
|
||||
name: 'Send message',
|
||||
key: 'send Message',
|
||||
description:
|
||||
'Sends a structured list of input messages with text content, and the model will generate the next message in the conversation.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Model',
|
||||
key: 'model',
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
variables: true,
|
||||
description: 'The model that will complete your prompt.',
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listModels',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Messages',
|
||||
key: 'messages',
|
||||
type: 'dynamic',
|
||||
required: true,
|
||||
description: 'Add or remove messages as needed',
|
||||
value: [{ role: 'assistant', body: '' }],
|
||||
fields: [
|
||||
{
|
||||
label: 'Role',
|
||||
key: 'role',
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
options: [
|
||||
{
|
||||
label: 'Assistant',
|
||||
value: 'assistant',
|
||||
},
|
||||
{
|
||||
label: 'User',
|
||||
value: 'user',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Content',
|
||||
key: 'content',
|
||||
type: 'string',
|
||||
required: true,
|
||||
variables: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Maximum tokens',
|
||||
key: 'maxTokens',
|
||||
type: 'string',
|
||||
required: true,
|
||||
variables: true,
|
||||
description: 'The maximum number of tokens to generate before stopping.',
|
||||
},
|
||||
{
|
||||
label: 'Temperature',
|
||||
key: 'temperature',
|
||||
type: 'string',
|
||||
required: false,
|
||||
variables: true,
|
||||
value: '1.0',
|
||||
description:
|
||||
'Amount of randomness injected into the response. Defaults to 1.0. Ranges from 0.0 to 1.0. Use temperature closer to 0.0 for analytical / multiple choice, and closer to 1.0 for creative and generative tasks.',
|
||||
},
|
||||
{
|
||||
label: 'Stop sequences',
|
||||
key: 'stopSequences',
|
||||
type: 'dynamic',
|
||||
required: false,
|
||||
variables: true,
|
||||
description:
|
||||
'Custom text sequences that will cause the model to stop generating.',
|
||||
fields: [
|
||||
{
|
||||
label: 'Stop sequence',
|
||||
key: 'stopSequence',
|
||||
type: 'string',
|
||||
required: false,
|
||||
variables: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const nonEmptyStopSequences = $.step.parameters.stopSequences
|
||||
.filter(({ stopSequence }) => stopSequence)
|
||||
.map(({ stopSequence }) => stopSequence);
|
||||
|
||||
const payload = {
|
||||
model: $.step.parameters.model,
|
||||
temperature: castFloatOrUndefined($.step.parameters.temperature),
|
||||
max_tokens: castFloatOrUndefined($.step.parameters.maxTokens),
|
||||
stop_sequences: nonEmptyStopSequences,
|
||||
messages: $.step.parameters.messages.map((message) => ({
|
||||
role: message.role,
|
||||
content: message.content,
|
||||
})),
|
||||
};
|
||||
|
||||
const { data } = await $.http.post('/v1/messages', payload);
|
||||
|
||||
$.setActionItem({
|
||||
raw: data,
|
||||
});
|
||||
},
|
||||
});
|
||||
8
packages/backend/src/apps/anthropic/assets/favicon.svg
Normal file
8
packages/backend/src/apps/anthropic/assets/favicon.svg
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="256px" height="176px" viewBox="0 0 256 176" version="1.1" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid">
|
||||
<title>Anthropic</title>
|
||||
<g fill="#181818">
|
||||
<path d="M147.486878,0 C147.486878,0 217.568251,175.780074 217.568251,175.780074 C217.568251,175.780074 256,175.780074 256,175.780074 C256,175.780074 185.918621,0 185.918621,0 C185.918621,0 147.486878,0 147.486878,0 C147.486878,0 147.486878,0 147.486878,0 Z"></path>
|
||||
<path d="M66.1828124,106.221191 C66.1828124,106.221191 90.1624677,44.4471185 90.1624677,44.4471185 C90.1624677,44.4471185 114.142128,106.221191 114.142128,106.221191 C114.142128,106.221191 66.1828124,106.221191 66.1828124,106.221191 C66.1828124,106.221191 66.1828124,106.221191 66.1828124,106.221191 Z M70.0705318,0 C70.0705318,0 0,175.780074 0,175.780074 C0,175.780074 39.179211,175.780074 39.179211,175.780074 C39.179211,175.780074 53.5097704,138.86606 53.5097704,138.86606 C53.5097704,138.86606 126.817544,138.86606 126.817544,138.86606 C126.817544,138.86606 141.145724,175.780074 141.145724,175.780074 C141.145724,175.780074 180.324935,175.780074 180.324935,175.780074 C180.324935,175.780074 110.254409,0 110.254409,0 C110.254409,0 70.0705318,0 70.0705318,0 C70.0705318,0 70.0705318,0 70.0705318,0 Z"></path>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
34
packages/backend/src/apps/anthropic/auth/index.js
Normal file
34
packages/backend/src/apps/anthropic/auth/index.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import verifyCredentials from './verify-credentials.js';
|
||||
import isStillVerified from './is-still-verified.js';
|
||||
|
||||
export default {
|
||||
fields: [
|
||||
{
|
||||
key: 'screenName',
|
||||
label: 'Screen Name',
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
placeholder: null,
|
||||
description:
|
||||
'Screen name of your connection to be used on Automatisch UI.',
|
||||
clickToCopy: false,
|
||||
},
|
||||
{
|
||||
key: 'apiKey',
|
||||
label: 'API Key',
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
placeholder: null,
|
||||
description: 'Anthropic AI API key of your account.',
|
||||
docUrl: 'https://automatisch.io/docs/anthropic#api-key',
|
||||
clickToCopy: false,
|
||||
},
|
||||
],
|
||||
|
||||
verifyCredentials,
|
||||
isStillVerified,
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
const isStillVerified = async ($) => {
|
||||
await $.http.get('/v1/models');
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
||||
@@ -0,0 +1,5 @@
|
||||
const verifyCredentials = async ($) => {
|
||||
await $.http.get('/v1/models');
|
||||
};
|
||||
|
||||
export default verifyCredentials;
|
||||
@@ -0,0 +1,7 @@
|
||||
const addAuthHeader = ($, requestConfig) => {
|
||||
requestConfig.headers['anthropic-version'] = '2023-06-01';
|
||||
|
||||
return requestConfig;
|
||||
};
|
||||
|
||||
export default addAuthHeader;
|
||||
@@ -0,0 +1,9 @@
|
||||
const addAuthHeader = ($, requestConfig) => {
|
||||
if ($.auth.data?.apiKey) {
|
||||
requestConfig.headers['x-api-key'] = $.auth.data.apiKey;
|
||||
}
|
||||
|
||||
return requestConfig;
|
||||
};
|
||||
|
||||
export default addAuthHeader;
|
||||
@@ -0,0 +1,3 @@
|
||||
import listModels from './list-models/index.js';
|
||||
|
||||
export default [listModels];
|
||||
@@ -0,0 +1,31 @@
|
||||
export default {
|
||||
name: 'List models',
|
||||
key: 'listModels',
|
||||
|
||||
async run($) {
|
||||
const models = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const params = {
|
||||
limit: 999,
|
||||
};
|
||||
|
||||
let hasMore = false;
|
||||
|
||||
do {
|
||||
const { data } = await $.http.get('/v1/models', { params });
|
||||
params.after_id = data.last_id;
|
||||
hasMore = data.has_more;
|
||||
|
||||
for (const base of data.data) {
|
||||
models.data.push({
|
||||
value: base.id,
|
||||
name: base.display_name,
|
||||
});
|
||||
}
|
||||
} while (hasMore);
|
||||
|
||||
return models;
|
||||
},
|
||||
};
|
||||
21
packages/backend/src/apps/anthropic/index.js
Normal file
21
packages/backend/src/apps/anthropic/index.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import defineApp from '../../helpers/define-app.js';
|
||||
import addAuthHeader from './common/add-auth-header.js';
|
||||
import addAnthropicVersionHeader from './common/add-anthropic-version-header.js';
|
||||
import auth from './auth/index.js';
|
||||
import actions from './actions/index.js';
|
||||
import dynamicData from './dynamic-data/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Anthropic',
|
||||
key: 'anthropic',
|
||||
baseUrl: 'https://anthropic.com',
|
||||
apiBaseUrl: 'https://api.anthropic.com',
|
||||
iconUrl: '{BASE_URL}/apps/anthropic/assets/favicon.svg',
|
||||
authDocUrl: '{DOCS_URL}/apps/anthropic/connection',
|
||||
primaryColor: '#181818',
|
||||
supportsConnections: true,
|
||||
beforeRequest: [addAuthHeader, addAnthropicVersionHeader],
|
||||
auth,
|
||||
actions,
|
||||
dynamicData,
|
||||
});
|
||||
@@ -3,6 +3,7 @@
|
||||
exports[`App model > list should have list of applications keys 1`] = `
|
||||
[
|
||||
"airtable",
|
||||
"anthropic",
|
||||
"appwrite",
|
||||
"azure-openai",
|
||||
"carbone",
|
||||
|
||||
@@ -41,6 +41,15 @@ export default defineConfig({
|
||||
{ text: 'Connection', link: '/apps/airtable/connection' },
|
||||
],
|
||||
},
|
||||
{
|
||||
text: 'Anthropic',
|
||||
collapsible: true,
|
||||
collapsed: true,
|
||||
items: [
|
||||
{ text: 'Actions', link: '/apps/anthropic/actions' },
|
||||
{ text: 'Connection', link: '/apps/anthropic/connection' },
|
||||
],
|
||||
},
|
||||
{
|
||||
text: 'Appwrite',
|
||||
collapsible: true,
|
||||
|
||||
12
packages/docs/pages/apps/anthropic/actions.md
Normal file
12
packages/docs/pages/apps/anthropic/actions.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
favicon: /favicons/anthropic.svg
|
||||
items:
|
||||
- name: Send message
|
||||
desc: Sends a structured list of input messages with text content, and the model will generate the next message in the conversation.
|
||||
---
|
||||
|
||||
<script setup>
|
||||
import CustomListing from '../../components/CustomListing.vue'
|
||||
</script>
|
||||
|
||||
<CustomListing />
|
||||
8
packages/docs/pages/apps/anthropic/connection.md
Normal file
8
packages/docs/pages/apps/anthropic/connection.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Anthropic
|
||||
|
||||
1. Go to [API Keys page](https://console.anthropic.com/settings/keys) on Anthropic.
|
||||
2. Create a new key.
|
||||
3. Paste the key into the `API Key` field in Automatisch.
|
||||
4. Write any screen name to be displayed in Automatisch.
|
||||
5. Click `Save`.
|
||||
6. Start using Anthropic integration with Automatisch!
|
||||
@@ -3,6 +3,7 @@
|
||||
The following integrations are currently supported by Automatisch.
|
||||
|
||||
- [Airtable](/apps/airtable/actions)
|
||||
- [Anthropic](/apps/anthropic/actions)
|
||||
- [Appwrite](/apps/appwrite/triggers)
|
||||
- [Carbone](/apps/carbone/actions)
|
||||
- [ClickUp](/apps/clickup/triggers)
|
||||
|
||||
8
packages/docs/pages/public/favicons/anthropic.svg
Normal file
8
packages/docs/pages/public/favicons/anthropic.svg
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="256px" height="176px" viewBox="0 0 256 176" version="1.1" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid">
|
||||
<title>Anthropic</title>
|
||||
<g fill="#181818">
|
||||
<path d="M147.486878,0 C147.486878,0 217.568251,175.780074 217.568251,175.780074 C217.568251,175.780074 256,175.780074 256,175.780074 C256,175.780074 185.918621,0 185.918621,0 C185.918621,0 147.486878,0 147.486878,0 C147.486878,0 147.486878,0 147.486878,0 Z"></path>
|
||||
<path d="M66.1828124,106.221191 C66.1828124,106.221191 90.1624677,44.4471185 90.1624677,44.4471185 C90.1624677,44.4471185 114.142128,106.221191 114.142128,106.221191 C114.142128,106.221191 66.1828124,106.221191 66.1828124,106.221191 C66.1828124,106.221191 66.1828124,106.221191 66.1828124,106.221191 Z M70.0705318,0 C70.0705318,0 0,175.780074 0,175.780074 C0,175.780074 39.179211,175.780074 39.179211,175.780074 C39.179211,175.780074 53.5097704,138.86606 53.5097704,138.86606 C53.5097704,138.86606 126.817544,138.86606 126.817544,138.86606 C126.817544,138.86606 141.145724,175.780074 141.145724,175.780074 C141.145724,175.780074 180.324935,175.780074 180.324935,175.780074 C180.324935,175.780074 110.254409,0 110.254409,0 C110.254409,0 70.0705318,0 70.0705318,0 C70.0705318,0 70.0705318,0 70.0705318,0 Z"></path>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
Reference in New Issue
Block a user