From 22cdc1893230446d235b7d17953e8304b9d6c6c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatu=20P=C3=A4kkil=C3=A4?= Date: Sun, 5 Nov 2023 10:47:46 +0200 Subject: [PATCH] Premium -> basic, send raw menu if AI fails. --- README.md | 6 +++--- src/index.ts | 2 +- src/lib.ts | 4 ++-- src/openai.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ece38db..c15faeb 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Fetches lunch menu from Origo restaurant and asks descriptions and recommendatio ## Code and CI/CD -Github: https://github.com/Vincit/lunch-assistant. All pushes to `main` branch will trigger GitHub Actions Workflow, which deploys app to Azure Function `lunch-premium`. +Github: https://github.com/Vincit/lunch-assistant. All pushes to `main` branch will trigger GitHub Actions Workflow, which deploys app to Azure Function `lunch-basic`. ## Prerequisites @@ -36,10 +36,10 @@ You have to have permissions to Vincit Azure OpenAI Playground. ## Scheduling -Workdays at 10:30 am. +Workdays at 10:30 am. Currently not taking daylight saving time into account, so need to update twice a year or find out how to detect DST. ## Hosting -As Azure Function App called `lunch-premium`. We had to use Premium plan to make integration to OpenAI Playground working. +As Azure Function App called `lunch-basic`. It is running in Basic App Service Plan. Cheaper consumption plan does not allow VNET, which in turn is needed for OpenAI access. Manual trigger by HTTP GET: http://lunch-premium.azurewebsites.net/api/slack \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index c9ad8d0..61c9af5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,7 +21,7 @@ export async function helloLunchChannelInternal() { const prompt = `Kuvaile näitä ruokalajeja lyhyesti mutta hauskasti ja anna suositus mitä syödä. Lisää viestiin ruokalajia kuvaava emoji. ${currentDayDishes} Tähän loppuun hauskasti sanottuna pyyntö reagoida emojilla, jos olet tulossa mukaan syömään!`; - const completion = await queryOpenAI(openAiUrl, prompt); + const completion = await queryOpenAI(openAiUrl, prompt, currentDayDishes); postToSlack(slackUrl, currentDayDishes, completion); return { body: 'Slakkiä spämmätty!' }; diff --git a/src/lib.ts b/src/lib.ts index 7959317..16f80c9 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -35,7 +35,7 @@ export const postToSlack = async (slackUrl: string, headline: string, message: s } }; -export const queryOpenAI = async (url: string, prompt: string): Promise => { +export const queryOpenAI = async (url: string, prompt: string, rawData: string): Promise => { try { const payload = { "messages": [{ @@ -61,7 +61,7 @@ export const queryOpenAI = async (url: string, prompt: string): Promise } catch (error: any) { console.log('Error in OpenAI integration!'); console.log(error.message); - return ''; + return 'Valitettavasti Azure OpenAI ei vastaa, mutta tässä lounaslista sellaisenaan: ' + rawData; } } diff --git a/src/openai.ts b/src/openai.ts index d61589c..c1da31e 100644 --- a/src/openai.ts +++ b/src/openai.ts @@ -3,7 +3,7 @@ import { queryOpenAI } from "./lib"; const url = process.env.OPENAI_API_URL || ''; const prompt = process.argv[2] ?? 'Say this is a test'; -queryOpenAI(url, prompt).then((completion) => { +queryOpenAI(url, prompt, 'Test').then((completion) => { if (completion) { console.log('OpenAI response:'); console.log(completion);