Skip to content

Commit

Permalink
Premium -> basic, send raw menu if AI fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatu Päkkilä committed Nov 5, 2023
1 parent 3e115a5 commit 22cdc18
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!' };
Expand Down
4 changes: 2 additions & 2 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const postToSlack = async (slackUrl: string, headline: string, message: s
}
};

export const queryOpenAI = async (url: string, prompt: string): Promise<string> => {
export const queryOpenAI = async (url: string, prompt: string, rawData: string): Promise<string> => {
try {
const payload = {
"messages": [{
Expand All @@ -61,7 +61,7 @@ export const queryOpenAI = async (url: string, prompt: string): Promise<string>
} 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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 22cdc18

Please sign in to comment.