Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
buttonsbond authored Oct 7, 2023
2 parents bad2957 + 9027794 commit 5e1f18d
Show file tree
Hide file tree
Showing 60 changed files with 1,117 additions and 217 deletions.
29 changes: 29 additions & 0 deletions docs/install/options/gcp.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: "GCP"
description: ""
---

This documentation is to deploy activepieces on VM Instance or VM Instance Group, we should first create VM template

## Create VM Template

First choose machine type (e.g e2-medium)

After configuring the VM Template, you can proceed to click on "Deploy Container" and specify the following container-specific settings:

- Image: activepieces/activepieces
- Run as a privileged container: true
- Environment Variables:
- `AP_QUEUE_MODE`: MEMORY
- `AP_DB_TYPE`: SQLITE3
- `AP_FRONTEND_URL`: http://localhost:80
- `AP_EXECUTION_MODE`: SANDBOXED
- Firewall: Allow HTTP traffic (for testing purposes only)

Once these details are entered, click on the "Deploy" button and patiently wait for the container deployment process to complete.\

After a successful deployment, you can access the ActivePieces application by visiting the external IP address of the VM on GCP.

## Production Deployment

Please visit [ActivePieces](../configuration) for more details on how to customize the application.
13 changes: 12 additions & 1 deletion docs/install/options/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Community Editions is focused on **individuals**, It is **free** and **open sour
You can read the difference between the editions [here](.././editions).
</Tip>

## Self Hosting Options (Community Edition)
## Recommended Options

<CardGroup cols={2}>
<Card title="Docker (Fastest)" icon="docker" color="#248fe0" href="./docker">
Expand All @@ -22,6 +22,12 @@ Deploy Activepieces as a single Docker container using the sqllite database.
Deploy Activepieces with **redis** and **postgres** setup
</Card>

</CardGroup>

## Other Options

<CardGroup cols={2}>

<Card title="Easypanel" icon={
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 245 245">
<g clip-path="url(#a)">
Expand All @@ -45,6 +51,11 @@ Deploy Activepieces as a single Docker container using the sqllite database.
Install on AWS with Pulumi
</Card>


<Card title="GCP" icon="cloud" color="#4385f5" href="./gcp">
Install on GCP as VM template
</Card>

</CardGroup>

## Cloud Edition
Expand Down
3 changes: 2 additions & 1 deletion docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
"install/options/docker",
"install/options/docker-compose",
"install/options/easypanel",
"install/options/aws"
"install/options/aws",
"install/options/gcp"
]
},
{
Expand Down
6 changes: 5 additions & 1 deletion packages/backend/src/app/chatbot/bots/chatbots.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ActivepiecesError, ErrorCode, SecretTextConnectionValue } from '@activepieces/shared'
import { APChatMessage as APChatMessage, ActivepiecesError, ErrorCode, SecretTextConnectionValue } from '@activepieces/shared'
import { customBot } from './custom-bot'
import { embeddings } from '../embedings'
import { llm } from '../framework/llm'


const chatbots = [customBot]

export const runBot = async ({
Expand All @@ -11,12 +12,14 @@ export const runBot = async ({
input,
auth,
prompt,
history,
}: {
botId: string
type: string
auth: SecretTextConnectionValue
input: string
prompt: string
history: APChatMessage[]
}): Promise<string> => {
const bot = chatbots.find((b) => b.name === type)
if (!bot) {
Expand All @@ -31,6 +34,7 @@ export const runBot = async ({
settings: {
prompt,
},
history,
})
}
catch (error) {
Expand Down
11 changes: 6 additions & 5 deletions packages/backend/src/app/chatbot/bots/custom-bot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

import { createChatbot } from '../framework/chatbot'


export const customBot = createChatbot({
name: 'custom-bot',
run: async (ctx) => {
Expand All @@ -8,13 +10,12 @@ export const customBot = createChatbot({
${ctx.settings.prompt}
[Information]:
${information.join('\n')}
[Question]:
${ctx.input}
`

return ctx.llm.chat({
input: finalPrompt,
history: [],
input: ctx.input,
history: ctx.history,
settingsPrompt: finalPrompt,
})
},
})

3 changes: 3 additions & 0 deletions packages/backend/src/app/chatbot/chatbot.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
UpdateChatbotRequest,
ListChatbotsRequest,
CreateChatBotRequest,
APChatMessage,
} from '@activepieces/shared'
import {
FastifyPluginCallbackTypebox,
Expand Down Expand Up @@ -108,6 +109,7 @@ export const chatbotController: FastifyPluginCallbackTypebox = (
params: ChatBotIdParams,
body: Type.Object({
input: Type.String(),
history: Type.Optional(Type.Array(APChatMessage)),
}),
},
},
Expand All @@ -116,6 +118,7 @@ export const chatbotController: FastifyPluginCallbackTypebox = (
projectId: request.principal.projectId,
chatbotId: request.params.id,
input: request.body.input,
history: request.body.history ?? [],
})
},
),
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/app/chatbot/chatbot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
UpdateChatbotRequest,
ChatbotResponse,
ChatbotMetadata,
APChatMessage,
} from '@activepieces/shared'
import { databaseConnection } from '../database/database-connection'
import { ChatbotEntity } from './chatbot.entity'
Expand Down Expand Up @@ -92,10 +93,12 @@ export const chatbotService = {
projectId,
chatbotId,
input,
history,
}: {
projectId: ProjectId
chatbotId: string
input: string
history: APChatMessage[]
}): Promise<ChatbotResponse> {
const chatbot = await chatbotRepo.findOneBy({
id: chatbotId,
Expand Down Expand Up @@ -126,6 +129,7 @@ export const chatbotService = {
type: chatbot.type,
auth: connection.value as SecretTextConnectionValue,
prompt: chatbot.prompt,
history,
})
return {
output,
Expand Down
9 changes: 6 additions & 3 deletions packages/backend/src/app/chatbot/framework/chatbot.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@

import { APChatMessage } from '@activepieces/shared'
import { ApEmbeddings } from '../embedings'
import { APLLM } from './llm'


type ChatbotAnswerContext = {
type ChatbotAskContext = {
settings: {
prompt: string
}
input: string
llm: APLLM
embeddings: ApEmbeddings
history: APChatMessage[]
}

class IChatbot {
constructor(
public readonly name: string,
public readonly run: (ctx: ChatbotAnswerContext) => Promise<string>,
public readonly run: (ctx: ChatbotAskContext) => Promise<string>,
) { }
}

export const createChatbot = (request: {
name: string
run: (ctx: ChatbotAnswerContext) => Promise<string>
run: (ctx: ChatbotAskContext) => Promise<string>
}) => {
return new IChatbot(
request.name,
request.run,
)
}

84 changes: 75 additions & 9 deletions packages/backend/src/app/chatbot/framework/llm.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,96 @@
import { ChatMessageHistory, ConversationSummaryMemory } from 'langchain/memory'
import { BaseChatMessageHistory, SystemMessage } from 'langchain/schema'
import { BaseLanguageModel } from 'langchain/dist/base_language'
import { OpenAI } from 'langchain/llms/openai'

import { BufferWindowMemory } from 'langchain/memory'
import { PromptTemplate } from 'langchain/prompts'
import { ConversationChain } from 'langchain/chains'
import { APChatMessage } from '@activepieces/shared'
export type APLLM = {
chat: ({ input, temperature, maxTokens }: AskChat) => Promise<string>
}

export const llm = (openAIApiKey: string, modelName: string) => {
return {
async chat({ input, temperature, maxTokens }: AskChat) {
async chat({ input, temperature, maxTokens, history, settingsPrompt }: AskChat) {
const model = new OpenAI({
modelName,
openAIApiKey,
temperature: temperature || 0.7,
maxTokens,
})
const response = await model.call(input)

const template = `
${settingsPrompt}
The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.
Current conversation:
System: {chat_summary}
{recent_chat_history}
Human: {human_input}
AI:`
const prompt = new PromptTemplate({
inputVariables: ['chat_summary', 'human_input', 'recent_chat_history'],
template,
})
const k = 10
const summary = history.length > k ? await summarizeMessages(model, history) : ''
const historyThread = await createChatMessageHistory(history)
const memory = new BufferWindowMemory({
chatHistory: historyThread,
memoryKey: 'recent_chat_history',
inputKey: 'human_input',
k,
returnMessages: false,
})
const chain = new ConversationChain({
memory,
verbose: true,
llm: model,
prompt,
})
const response = await chain.predict({
chat_summary: summary,
human_input: input,
})
return response
},
}
}

type AskChat = {
export type AskChat = {
input: string
history: {
text: string
role: 'bot' | 'user'
}[]
history: APChatMessage[]
settingsPrompt: string
temperature?: number
maxTokens?: number
}

export const summarizeMessages = async (model: BaseLanguageModel, messages: APChatMessage[]): Promise<string> => {
const summary_memory = new ConversationSummaryMemory({
llm: model,
chatHistory: await createChatMessageHistory(messages),
})

const summary = await summary_memory.predictNewSummary(await summary_memory.chatHistory.getMessages(), '')
return summary
}

export const createChatMessageHistory = async (messages: APChatMessage[]): Promise<BaseChatMessageHistory> => {
const history = new ChatMessageHistory()
for (const message of messages) {
switch (message.role) {
case 'user': {
await history.addUserMessage(message.text)
break
}
case 'bot': {
await history.addAIChatMessage(message.text)
break
}
default: {
await history.addMessage(new SystemMessage(message.text))
break
}
}
}
return history
}
11 changes: 9 additions & 2 deletions packages/backend/src/app/flags/flag.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FlagEntity } from './flag.entity'
import axios from 'axios'
import { webhookService } from '../webhooks/webhook-service'
import { getEdition } from '../helper/secret-helper'
import { theme } from './theme'

const flagRepo = databaseConnection.getRepository(FlagEntity)

Expand Down Expand Up @@ -56,15 +57,21 @@ export const flagService = {
created,
updated,
},
{
id: ApFlagId.THEME,
value: theme,
created,
updated,
},
{
id: ApFlagId.SHOW_DOCS,
value: getEdition() !== ApEdition.ENTERPRISE,
value: false,
created,
updated,
},
{
id: ApFlagId.SHOW_COMMUNITY,
value: getEdition() !== ApEdition.ENTERPRISE,
value: false,
created,
updated,
},
Expand Down
Loading

0 comments on commit 5e1f18d

Please sign in to comment.