diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ba3ab99..6dd2de7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -28,6 +28,19 @@ jobs: with: run_install: false + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - uses: actions/cache@v4 + name: Setup pnpm cache + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install Dependencies run: pnpm install --frozen-lockfile diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 109082f..4845eba 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -44,6 +44,19 @@ jobs: with: run_install: false + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - uses: actions/cache@v4 + name: Setup pnpm cache + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install dependencies run: pnpm i --frozen-lockfile diff --git a/apps/wapi-ai-chatbot/src/index.ts b/apps/wapi-ai-chatbot/src/index.ts index ae37a9c..957fcba 100644 --- a/apps/wapi-ai-chatbot/src/index.ts +++ b/apps/wapi-ai-chatbot/src/index.ts @@ -4,52 +4,52 @@ import { askAi } from './utils/gpt' import { getCache, setCache } from './utils/cache' async function init() { - try { - whatsappClient.on('Ready', () => { - console.log('Client is ready') - }) - - whatsappClient.on('Error', error => { - console.error('Error', error.message) - }) - - whatsappClient.on('TextMessage', async (event: TextMessageEvent) => { - const cachedResponse = await getCache(event.text.data.text) - console.log({ cachedResponse }) - let response = 'Sorry, I am not able to understand that.' - if (cachedResponse) { - response = String(cachedResponse) - } else { - const aiResponse = await askAi(event.text.data.text) - response = aiResponse || response - if (aiResponse) { - setCache(event.text.data.text, aiResponse) - } - } - - console.log({ response }) - await event.reply({ - message: new TextMessage({ - text: response - }) - }) - }) - - whatsappClient.initiate() - } catch (error) { - console.error(error) - // ! TODO: you may prefer to send a notification to your slack channel or email here - } + try { + whatsappClient.on('Ready', () => { + console.log('Client is ready') + }) + + whatsappClient.on('Error', error => { + console.error('Error', error.message) + }) + + whatsappClient.on('TextMessage', async (event: TextMessageEvent) => { + const cachedResponse = await getCache(event.text.data.text) + console.log({ cachedResponse }) + let response = 'Sorry, I am not able to understand that.' + if (cachedResponse) { + response = String(cachedResponse) + } else { + const aiResponse = await askAi(event.text.data.text) + response = aiResponse || response + if (aiResponse) { + setCache(event.text.data.text, aiResponse) + } + } + + console.log({ response }) + await event.reply({ + message: new TextMessage({ + text: response + }) + }) + }) + + whatsappClient.initiate() + } catch (error) { + console.error(error) + // ! TODO: you may prefer to send a notification to your slack channel or email here + } } init().catch(error => console.error(error)) process.on('unhandledRejection', error => { - console.error('unhandledRejection', error) - process.exit(1) + console.error('unhandledRejection', error) + process.exit(1) }) process.on('uncaughtException', error => { - console.error('uncaughtException', error) - process.exit(1) + console.error('uncaughtException', error) + process.exit(1) }) diff --git a/apps/wapi-ai-chatbot/src/utils/gpt.ts b/apps/wapi-ai-chatbot/src/utils/gpt.ts index 9046fc3..8d336c2 100644 --- a/apps/wapi-ai-chatbot/src/utils/gpt.ts +++ b/apps/wapi-ai-chatbot/src/utils/gpt.ts @@ -3,27 +3,32 @@ import { OpenAI } from 'openai' const openAiApiKey = process.env.OPEN_AI_API_KEY if (!openAiApiKey) { - throw new Error('OPEN_AI_API_KEY not defined!') + throw new Error('OPEN_AI_API_KEY not defined!') } const OpenApiClient = new OpenAI({ - apiKey: openAiApiKey, - project: 'proj_viwVq5nzCR5Mj4TnIw4FQoNO', - organization: 'org-wwfaGhYXIA7CBUSg6x8DbKYj' + apiKey: openAiApiKey, + project: 'proj_viwVq5nzCR5Mj4TnIw4FQoNO', + organization: 'org-wwfaGhYXIA7CBUSg6x8DbKYj' }) export async function askAi(message: string): Promise { - try { - const chatCompletion = await OpenApiClient.chat.completions.create({ - messages: [{ role: 'user', content: message }], - model: 'gpt-3.5-turbo' - }) - - console.log(JSON.stringify({ chatCompletion })) - - return chatCompletion.choices[0].message.content - } catch (error) { - console.log({ error }) - return null - } + try { + const chatCompletion = await OpenApiClient.chat.completions.create({ + messages: [{ role: 'user', content: message }], + model: 'gpt-3.5-turbo' + }) + + console.log(JSON.stringify({ chatCompletion })) + + return chatCompletion.choices[0].message.content + } catch (error) { + console.log({ error }) + return null + } } + + +export async function generateTranscription(){ + +} \ No newline at end of file