Skip to content

Commit

Permalink
add server github actions + make payload compatible with openAI + sma…
Browse files Browse the repository at this point in the history
…ll UI changes to widget
  • Loading branch information
eg9y committed May 27, 2023
1 parent 31a4d09 commit 4645b22
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 28 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Deploy
on:
push:
branches:
- main # Or your default branch
jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Execute remote ssh commands
uses: appleboy/ssh-action@master
with:
host: chatserver.chatbutler.ai
username: root
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd promptsandbox.io
git pull
yarn workspace @chatbutler/shared build
yarn workspace @chatbutler/server build
pm2 restart ecosystem.config.js
2 changes: 1 addition & 1 deletion packages/chat-widget/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
Expand Down
6 changes: 5 additions & 1 deletion packages/chat-widget/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,12 @@ function App({
}} />
)}
{!isChatbotOpen && (
<ChatBubbleLeftIcon className="bg-blue-400 rounded-full p-4 w-16 h-16 m-4 text-blue-50 cursor-pointer hover:text-blue-100" onClick={() => {
<ChatBubbleLeftIcon className="bg-blue-400 rounded-full p-4 w-16 h-16 m-4 text-blue-50 cursor-pointer hover:text-blue-100" onClick={async () => {
setIsChatbotOpen(true);
// await onUserSendMessage({
// role: 'user',
// content: 'hello',
// })
}} />
)}
</div>
Expand Down
9 changes: 3 additions & 6 deletions packages/chat-widget/src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ interface Props {
export const Chat: FC<Props> = ({ messages, loading, onSend, onReset }) => {
return (
<>
<div className="flex flex-row justify-between items-center mb-4 sm:mb-8">
<ResetChat onReset={onReset} />
</div>

<div className="flex flex-col rounded-lg px-2 sm:p-4 sm:border border-neutral-300">
<div className="flex flex-col md:w-[400px] rounded-lg px-2 sm:p-4 sm:border border-neutral-300">
{messages.map((message, index) => (
<div
key={index}
Expand All @@ -35,7 +31,8 @@ export const Chat: FC<Props> = ({ messages, loading, onSend, onReset }) => {
</div>
)}

<div className="mt-4 sm:mt-8 bottom-[56px] left-0 w-full">
<div className="mt-4 sm:mt-8 bottom-[56px] left-0 w-full flex gap-2 justify-between">
<ResetChat onReset={onReset} />
<ChatInput onSend={onSend} />
</div>
</div>
Expand Down
6 changes: 1 addition & 5 deletions packages/chat-widget/src/components/Chat/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const ChatInput = ({ onSend }: Props) => {
}, [content]);

return (
<div className="relative">
<div className="relative grow">
<textarea
ref={textareaRef}
className="min-h-[44px] rounded-lg pl-4 pr-12 py-2 w-full focus:outline-none focus:ring-1 focus:ring-neutral-300 border-2 border-neutral-200"
Expand All @@ -57,10 +57,6 @@ export const ChatInput = ({ onSend }: Props) => {
onInput={handleChange}
onKeyDown={handleKeyDown}
/>

<button onClick={() => handleSend()}>
<ArrowUpIcon className="absolute right-2 bottom-3 h-8 w-8 hover:cursor-pointer rounded-full p-1 bg-blue-500 text-white hover:opacity-80" />
</button>
</div>
);
};
Expand Down
6 changes: 3 additions & 3 deletions packages/chat-widget/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export function initializeChatbot({ chatBotId }: { chatBotId: string }) {

window.initializeChatbot = initializeChatbot

initializeChatbot({
chatBotId: 'c1y7TY43AFzO7AFf0MSdY'
});
// initializeChatbot({
// chatBotId: ''
// });
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class RunNodeProcessor {
this.chatGateway.sendUpdate(sessionId, returnMessage);
} catch (error) {
console.error(error);
console.error('error message:', error.message);
this.chatGateway.sendUpdate(sessionId, { error: error.message });
}
}
Expand Down
24 changes: 12 additions & 12 deletions packages/shared/src/runNode/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ const search = async (
) => {
try {
const inputs = node.data.inputs;
const inputNodes = getNodes(nodes, inputs.inputs);
const docsLoaderNodeIndex = inputNodes.findIndex(
(node) => node.type === "docsLoader"
);
const inputIds = inputs.inputs.filter((input) => input !== "docsLoader");
const searchNode = node.data as SearchDataType;
const userQuestion = parsePromptInputs(nodes, inputIds, searchNode.text);
Expand All @@ -45,14 +41,21 @@ const search = async (
throw new Error(session.error.message);
}

let model = new ChatOpenAI({
const openAiOptions: any = {
// TODO: need to let user set the openai settings
modelName: node.data.model,
maxTokens: node.data.max_tokens,
maxTokens: Math.floor(node.data.max_tokens),
temperature: node.data.temperature,
stop: node.data.stop,
openAIApiKey: openAiKey,
});
}

if (node.data.stop) {
openAiOptions.stop = node.data.stop;
}



let model = new ChatOpenAI(openAiOptions);

const { runtime } = await getRuntimeEnvironment();

Expand Down Expand Up @@ -87,10 +90,7 @@ const search = async (
openAIApiKey: session.data.session.access_token,
});
model = new ChatOpenAI({
modelName: node.data.model,
maxTokens: node.data.max_tokens,
temperature: node.data.temperature,
stop: node.data.stop,
...openAiOptions,
// this is the supabase session key, the real openAI key is set in the proxy #ifitworksitworks
openAIApiKey: session.data.session.access_token,
});
Expand Down

1 comment on commit 4645b22

@vercel
Copy link

@vercel vercel bot commented on 4645b22 May 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.