forked from activepieces/activepieces
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/buttonsbond/activepieces
- Loading branch information
Showing
60 changed files
with
1,117 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.