From 29a84c39e1cb4772c2071bb1c4c1eed5890640ad Mon Sep 17 00:00:00 2001 From: Joe Fernandez Date: Sun, 17 Mar 2024 22:12:37 -0700 Subject: [PATCH 1/3] Update Wordcraft project to use Gemini API - first draft commit --- app/models/palm/api.ts | 194 ++++++++++++++++++++++---------------- app/models/palm/dialog.ts | 26 ++--- app/models/palm/index.ts | 37 ++++---- package-lock.json | 14 +++ package.json | 1 + 5 files changed, 157 insertions(+), 115 deletions(-) diff --git a/app/models/palm/api.ts b/app/models/palm/api.ts index 5af6d04..eaa55d5 100644 --- a/app/models/palm/api.ts +++ b/app/models/palm/api.ts @@ -17,98 +17,134 @@ * ============================================================================== */ -export const BLOCK_CONFIDENCE_THRESHOLDS = [ - 'BLOCK_CONFIDENCE_THRESHOLD_UNSPECIFIED', - 'BLOCK_LOW_MEDIUM_AND_HIGH_HARM_CONFIDENCE', - 'BLOCK_MEDIUM_AND_HIGH_HARM_CONFIDENCE', - 'BLOCK_HIGH_HARM_CONFIDENCE_ONLY', - 'BLOCK_NONE', -]; -export type BlockConfidenceThreshold = - (typeof BLOCK_CONFIDENCE_THRESHOLDS)[number]; - -export const SAFETY_CATEGORIES = [ - 'HATE', - 'TOXICITY', - 'VIOLENCE', - 'SEXUAL', - 'MEDICAL', - 'DANGEROUS', -]; -export type SafetyCategory = (typeof SAFETY_CATEGORIES)[number]; +// set up Gemini generative AI library +const { GoogleGenerativeAI } = require("@google/generative-ai"); +const genAI = new GoogleGenerativeAI(process.env.API_KEY); +// Remember to set an environment variable for API_KEY in .env -export interface SafetySetting { - category: number; - threshold: BlockConfidenceThreshold; -} +import { HarmBlockThreshold, HarmCategory } from "@google/generative-ai"; +import { DialogParams } from '@core/shared/interfaces'; + +// Default safety settings +const safetySettings = [ + { + category: HarmCategory.HARM_CATEGORY_HARASSMENT, + threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH, + }, + { + category: HarmCategory.HARM_CATEGORY_HATE_SPEECH, + threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE, + }, + { + category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, + threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH, + }, + { + category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, + threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH, + }, +]; export interface ModelParams { - topK?: number; - topP?: number; - candidateCount?: number; - maxOutputTokens?: number; - temperature?: number; - safetySettings?: SafetySetting[]; + generationConfig?: { + topK?: number; + topP?: number; + candidateCount?: number; + maxOutputTokens?: number; + temperature?: number; + } } -const DEFAULT_PARAMS: ModelParams = { - temperature: 1, - topK: 40, - topP: 0.95, - candidateCount: 8, +const DEFAULT_GENERATION_PARAMS: ModelParams = { + generationConfig: { + temperature: 0.8, + topK: 40, + topP: 0.95, + candidateCount: 8 + } }; -const DEFAULT_TEXT_PARAMS: ModelParams = { - ...DEFAULT_PARAMS, - maxOutputTokens: 1024, - safetySettings: SAFETY_CATEGORIES.map((category, index) => ({ - category: index, - threshold: 'BLOCK_NONE', - })), -}; +const TEXT_MODEL_ID = 'gemini-pro'; +const DIALOG_MODEL_ID = 'gemini-pro'; -const DEFAULT_DIALOG_PARAMS: ModelParams = { - ...DEFAULT_PARAMS, -}; +export async function callTextModel( + textPrompt: string, + genConfig: ModelParams) { + // set any passed parameters + genConfig = Object.assign({}, DEFAULT_GENERATION_PARAMS, genConfig); + genConfig.generationConfig.maxOutputTokens = 1024; + + const model = genAI.getGenerativeModel({ + model: TEXT_MODEL_ID, genConfig, safetySettings + }); + const result = await model.generateContent(textPrompt); + const response = await result.response; + return response.text(); +} -const API_URL = 'https://generativelanguage.googleapis.com/v1beta2'; +export async function callDialogModel( + chatParams: DialogParams, + genConfig: ModelParams) { + // set any passed parameters + genConfig = Object.assign({}, DEFAULT_GENERATION_PARAMS, genConfig); + // set dialog-specific model parameters + genConfig.generationConfig.temperature = 0.7; + genConfig.generationConfig.candidateCount = 1; -const TEXT_MODEL_ID = 'text-bison-001'; -const TEXT_METHOD = 'generateText'; + const model = genAI.getGenerativeModel({ + model: DIALOG_MODEL_ID, genConfig, safetySettings + }); -const DIALOG_MODEL_ID = 'chat-bison-001'; -const DIALOG_METHOD = 'generateMessage'; + // get lastest chat request (last message) + const lastMsgIndex = chatParams.messages.length - 1; + const message = chatParams.messages[lastMsgIndex].content; -export async function callTextModel(params: ModelParams) { - params = { - ...DEFAULT_TEXT_PARAMS, - ...params, - }; - return callApi(TEXT_MODEL_ID, TEXT_METHOD, params); -} + // set chat history + const history = remapHistory(chatParams); + + // chat history TESTS + const history1 = [ + { + role: "user", + parts: "Who are you?" + }, + { + role: "model", + parts: "I am a model trained by Google" + } + ]; + const history2 = [ + { + role: "user", + parts: "Here's my story so far: {The man sat in his chair and closed his eyes. His voice was filled with sadness, but also with hope and let out a single tear. He whispered, \"I've finally found my way home,\" as the light from the lantern flickered and grew faint. With those words, the man's body relaxed and a peaceful smile spread across his face. As the light from the lantern slowly faded, it left behind a lingering sense of warmth and belonging. }", + }, + { + role: "model", + parts: "That's a great start for your story. How can I help?", + } + ]; -export async function callDialogModel(params: ModelParams) { - params = { - ...DEFAULT_DIALOG_PARAMS, - ...params, - }; - return callApi(DIALOG_MODEL_ID, DIALOG_METHOD, params); + // end test + console.log("history1 (static):\n", history1); + console.log("history2 (static):\n", history2); + console.log("history (object):\n", history); + + const chat = model.startChat({ history2 }); + + const result = await chat.sendMessage(message); + const response = await result.response; + return response.text(); } -export async function callApi( - modelId: string, - method: string, - params: Partial -) { - const urlPrefix = `${API_URL}/models/${modelId}:${method}`; - const url = new URL(urlPrefix); - url.searchParams.append('key', process.env.PALM_API_KEY); - - return fetch(url.toString(), { - method: 'POST', - headers: { - 'Content-Type': 'text/plain', - }, - body: JSON.stringify(params), - }); +export function remapHistory(chatParams: DialogParams) { + const remappedMessageHistory = []; + + // skip the first and last messages + for (let i = 1; i < chatParams.messages.length - 1; i++) { + remappedMessageHistory.push({ + role: chatParams.messages[i].author, + parts: chatParams.messages[i].content + }); + } + return remappedMessageHistory; } diff --git a/app/models/palm/dialog.ts b/app/models/palm/dialog.ts index e7cdf0b..5abc50b 100644 --- a/app/models/palm/dialog.ts +++ b/app/models/palm/dialog.ts @@ -19,7 +19,7 @@ import {DialogParams} from '@core/shared/interfaces'; import {DialogModel} from '../dialog_model'; -import {callDialogModel, ModelParams} from './api'; +import { callDialogModel, ModelParams } from './api'; import {createModelResults} from '../utils'; import {ContextService, StatusService} from '@services/services'; @@ -37,27 +37,15 @@ export class PalmDialogModel extends DialogModel { } override async query( - params: DialogParams, + chatParams: DialogParams, modelParams: Partial = {} ) { - let temperature = (params as any).temperature; - temperature = temperature === undefined ? 0.7 : temperature; + console.log('🚀 DialogParams: ', JSON.stringify(chatParams)); - const queryParams = { - ...modelParams, - candidateCount: 1, - prompt: { - messages: params.messages, - }, - temperature: temperature, - }; - - const res = await callDialogModel(queryParams); - const response = await res.json(); - console.log('🚀 model results: ', response); - - const responseText = response.candidates?.length - ? response.candidates.map((candidate) => candidate.content) + const singleResponse = await callDialogModel(chatParams, modelParams); + console.log('🚀 model results: ', singleResponse); + const responseText = singleResponse.length + ? [singleResponse] : []; const results = createModelResults(responseText); diff --git a/app/models/palm/index.ts b/app/models/palm/index.ts index c19915b..0a75dd2 100644 --- a/app/models/palm/index.ts +++ b/app/models/palm/index.ts @@ -125,26 +125,15 @@ export class PalmModel extends Model { params: Partial = {}, shouldParse = true ) { - let temperature = (params as any).temperature; - temperature = temperature === undefined ? 1 : temperature; - - const modelParams = { - ...params, - prompt: { - text: promptText, - }, - temperature: temperature, - }; - + // candidateCount: setting is being rejected or ignored. workaround: + promptText = promptText + "\nGenerate 8 responses. " + + "Each response must start with: " + D0 + " and end with: " + D1; console.log('🚀 prompt text: ', promptText); - const res = await callTextModel(modelParams); - const response = await res.json(); - console.log('🚀 model results: ', response); + const res = await callTextModel(promptText, params); + console.log('🚀 model results: ', res); - const responseText = response.candidates?.length - ? response.candidates.map((candidate) => candidate.output) - : []; + const responseText = getListOfReponses(res, D0, D1); const results = createModelResults(responseText); const output = shouldParse @@ -169,3 +158,17 @@ export class PalmModel extends Model { override rewriteSentence = this.makePromptHandler(rewriteSentence); override suggestRewrite = this.makePromptHandler(suggestRewrite); } + +/** Get text between two delimiters */ +export function getListOfReponses(txt: string, d0: string, d1: string) { + // Note: s flag indicates a "single line", which counts newlines as characters + // allowing the regex to capture multi-line output + const re = new RegExp(`(?<=${d0})(.*?)(?=${d1})`, 'gms'); + const matches = txt.match(re); + const responseList = []; + for (const match of matches) { + // re-add the curly brackets + responseList.push("{" + match + "}"); + } + return responseList; +} diff --git a/package-lock.json b/package-lock.json index 86f047b..c3336b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "Apache-2.0", "dependencies": { "@adobe/lit-mobx": "^2.0.0-rc.4", + "@google/generative-ai": "^0.3.0", "@material/mwc-checkbox": "^0.27.0", "@material/mwc-circular-progress-four-color": "^0.27.0", "@material/mwc-dialog": "^0.27.0", @@ -86,6 +87,14 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/@google/generative-ai": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@google/generative-ai/-/generative-ai-0.3.0.tgz", + "integrity": "sha512-6xbaA/JPpwCoe+lfxE2RavVB8JI8F3P6mCse1Sbm586HhJkyuSevK7Opt4l2dbQZFej+M8ALhMMpfBiRW05Fag==", + "engines": { + "node": ">=18.0.0" + } + }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.7", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.7.tgz", @@ -5759,6 +5768,11 @@ "strip-json-comments": "^3.1.1" } }, + "@google/generative-ai": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@google/generative-ai/-/generative-ai-0.3.0.tgz", + "integrity": "sha512-6xbaA/JPpwCoe+lfxE2RavVB8JI8F3P6mCse1Sbm586HhJkyuSevK7Opt4l2dbQZFej+M8ALhMMpfBiRW05Fag==" + }, "@humanwhocodes/config-array": { "version": "0.11.7", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.7.tgz", diff --git a/package.json b/package.json index 7cc1501..440169c 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "license": "Apache-2.0", "dependencies": { "@adobe/lit-mobx": "^2.0.0-rc.4", + "@google/generative-ai": "^0.3.0", "@material/mwc-checkbox": "^0.27.0", "@material/mwc-circular-progress-four-color": "^0.27.0", "@material/mwc-dialog": "^0.27.0", From b9380b75d2e09f1bf183c26f0c1f67ed1485910d Mon Sep 17 00:00:00 2001 From: Joe Fernandez Date: Tue, 19 Mar 2024 14:41:45 -0700 Subject: [PATCH 2/3] Fixed problem with chat history not loading --- app/models/palm/api.ts | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/app/models/palm/api.ts b/app/models/palm/api.ts index eaa55d5..d5b5c69 100644 --- a/app/models/palm/api.ts +++ b/app/models/palm/api.ts @@ -101,35 +101,8 @@ export async function callDialogModel( // set chat history const history = remapHistory(chatParams); - - // chat history TESTS - const history1 = [ - { - role: "user", - parts: "Who are you?" - }, - { - role: "model", - parts: "I am a model trained by Google" - } - ]; - const history2 = [ - { - role: "user", - parts: "Here's my story so far: {The man sat in his chair and closed his eyes. His voice was filled with sadness, but also with hope and let out a single tear. He whispered, \"I've finally found my way home,\" as the light from the lantern flickered and grew faint. With those words, the man's body relaxed and a peaceful smile spread across his face. As the light from the lantern slowly faded, it left behind a lingering sense of warmth and belonging. }", - }, - { - role: "model", - parts: "That's a great start for your story. How can I help?", - } - ]; - - // end test - console.log("history1 (static):\n", history1); - console.log("history2 (static):\n", history2); console.log("history (object):\n", history); - - const chat = model.startChat({ history2 }); + const chat = model.startChat( history ); const result = await chat.sendMessage(message); const response = await result.response; From ec6c5b88f1e49013ddf49b8eb9d3f26ed6a848f0 Mon Sep 17 00:00:00 2001 From: Joe Fernandez Date: Tue, 19 Mar 2024 15:12:41 -0700 Subject: [PATCH 3/3] Renamed Palm model references to Gemini - object names - directory names --- README.md | 20 +++++++++---------- app/main.ts | 8 ++++---- app/models/{palm => gemini}/api.ts | 0 app/models/{palm => gemini}/dialog.ts | 4 ++-- app/models/{palm => gemini}/index.ts | 4 ++-- .../{palm => gemini}/prompts/continue.ts | 4 ++-- .../{palm => gemini}/prompts/elaborate.ts | 4 ++-- .../prompts/first_sentence.ts | 4 ++-- .../{palm => gemini}/prompts/freeform.ts | 4 ++-- .../prompts/generate_within_sentence.ts | 4 ++-- .../{palm => gemini}/prompts/meta_prompt.ts | 4 ++-- .../{palm => gemini}/prompts/new_story.ts | 4 ++-- .../{palm => gemini}/prompts/next_sentence.ts | 4 ++-- .../{palm => gemini}/prompts/replace.ts | 4 ++-- .../prompts/rewrite_end_of_sentence.ts | 4 ++-- .../prompts/rewrite_selection.ts | 4 ++-- .../prompts/rewrite_sentence.ts | 4 ++-- .../prompts/suggest_rewrite.ts | 4 ++-- 18 files changed, 44 insertions(+), 44 deletions(-) rename app/models/{palm => gemini}/api.ts (100%) rename app/models/{palm => gemini}/dialog.ts (94%) rename app/models/{palm => gemini}/index.ts (98%) rename app/models/{palm => gemini}/prompts/continue.ts (93%) rename app/models/{palm => gemini}/prompts/elaborate.ts (93%) rename app/models/{palm => gemini}/prompts/first_sentence.ts (95%) rename app/models/{palm => gemini}/prompts/freeform.ts (94%) rename app/models/{palm => gemini}/prompts/generate_within_sentence.ts (97%) rename app/models/{palm => gemini}/prompts/meta_prompt.ts (95%) rename app/models/{palm => gemini}/prompts/new_story.ts (93%) rename app/models/{palm => gemini}/prompts/next_sentence.ts (97%) rename app/models/{palm => gemini}/prompts/replace.ts (96%) rename app/models/{palm => gemini}/prompts/rewrite_end_of_sentence.ts (97%) rename app/models/{palm => gemini}/prompts/rewrite_selection.ts (96%) rename app/models/{palm => gemini}/prompts/rewrite_sentence.ts (95%) rename app/models/{palm => gemini}/prompts/suggest_rewrite.ts (94%) diff --git a/README.md b/README.md index 4cbe990..352bbbe 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ Wordcraft is an LLM-powered text editor with an emphasis on short story writing. Wordcraft is a tool built by researchers at Google [PAIR](https://pair.withgoogle.com/) for writing stories with AI. The -application is powered by LLMs such as -[PaLM](https://developers.generativeai.google/), one of the latest generation of -large language models. At its core, LLMs are simple machines — it's trained to +application is powered by generative models such as +[Gemini](https://ai.google.dev/docs/). +At its core, generative models are simple machines — it's trained to predict the most likely next word given a textual prompt. But because the model is so large and has been trained on a massive amount of text, it's able to learn higher-level concepts. It also demonstrates a fascinating emergent capability @@ -32,14 +32,14 @@ npm run dev # ☁️ API -In order to run Wordcraft, you'll need a PaLM API key. Please follow the +In order to run Wordcraft, you'll need a Gemini API key. Please follow the instructions at -[developers.generativeai.google/tutorials/setup](https://developers.generativeai.google/tutorials/setup). +[ai.google.dev/tutorials/setup](https://ai.google.dev/tutorials/setup). Once you have your API key, create a .env file and add the key! ```bash touch .env -echo "PALM_API_KEY=\"\"" > .env +echo "API_KEY=\"\"" > .env ``` Remember, use your API keys securely. Do not share them with others, or embed @@ -47,8 +47,8 @@ them directly in code that's exposed to the public! This application stores/loads API keys on the client for ease of development, but these should be removed in all production apps! -You can find more information about the PaLM 2 API at -[developers.generativeai.google](https://developers.generativeai.google/) +You can find more information about the Gemini API at +[ai.google.dev/docs/](https://ai.google.dev/docs/) # 🤖 App @@ -88,9 +88,9 @@ To add a new custom control (e.g. a button that translates into pig latin): - Create a new `pig_latin_examples.json` in `/app/context/json/` - Register the examples int the `WordCraftContext` constructor (`/app/context/index.ts`) -- Create a corresponding prompt handler in `/app/models/palm/prompts` +- Create a corresponding prompt handler in `/app/models/gemini/prompts` - Register that prompt handler with the underlying `Model` class in - `/app/models/palm/index.ts` + `/app/models/gemini/index.ts` - Create a new `PigLatinOperation` in `/app/core/operations` - Register the operation in `main.ts` diff --git a/app/main.ts b/app/main.ts index 2b31e22..9e9b910 100644 --- a/app/main.ts +++ b/app/main.ts @@ -28,8 +28,8 @@ import {OperationsService} from '@services/operations_service'; import {WordcraftContext} from './context'; import {makeServiceProvider} from './service_provider'; import {InitializationService} from '@services/initialization_service'; -import {PalmModel} from '@models/palm'; -import {PalmDialogModel} from '@models/palm/dialog'; +import {GeminiModel} from '@models/gemini'; +import {GeminiDialogModel} from '@models/gemini/dialog'; wordcraftCore.initialize(makeServiceProvider); @@ -55,8 +55,8 @@ operationsService.registerOperations( // Register prompts with models const modelService = wordcraftCore.getService(ModelService); -modelService.useModel(PalmModel); -modelService.useDialogModel(PalmDialogModel); +modelService.useModel(GeminiModel); +modelService.useDialogModel(GeminiDialogModel); // Initialize the app after page load, so that all of the javascript is present // before we build the app. diff --git a/app/models/palm/api.ts b/app/models/gemini/api.ts similarity index 100% rename from app/models/palm/api.ts rename to app/models/gemini/api.ts diff --git a/app/models/palm/dialog.ts b/app/models/gemini/dialog.ts similarity index 94% rename from app/models/palm/dialog.ts rename to app/models/gemini/dialog.ts index 5abc50b..8fa3ac6 100644 --- a/app/models/palm/dialog.ts +++ b/app/models/gemini/dialog.ts @@ -29,9 +29,9 @@ interface ServiceProvider { statusService: StatusService; } /** - * A Model representing PaLM Dialog API. + * A Model representing Gemini API for chat. */ -export class PalmDialogModel extends DialogModel { +export class GeminiDialogModel extends DialogModel { constructor(serviceProvider: ServiceProvider) { super(serviceProvider); } diff --git a/app/models/palm/index.ts b/app/models/gemini/index.ts similarity index 98% rename from app/models/palm/index.ts rename to app/models/gemini/index.ts index 0a75dd2..becd8b4 100644 --- a/app/models/palm/index.ts +++ b/app/models/gemini/index.ts @@ -53,9 +53,9 @@ interface ServiceProvider { } /** - * A Model representing PaLM API. + * A Model representing Gemini API. */ -export class PalmModel extends Model { +export class GeminiModel extends Model { constructor(serviceProvider: ServiceProvider) { super(serviceProvider); } diff --git a/app/models/palm/prompts/continue.ts b/app/models/gemini/prompts/continue.ts similarity index 93% rename from app/models/palm/prompts/continue.ts rename to app/models/gemini/prompts/continue.ts index d545408..cbf4790 100644 --- a/app/models/palm/prompts/continue.ts +++ b/app/models/gemini/prompts/continue.ts @@ -20,9 +20,9 @@ import {ContinuePromptParams} from '@core/shared/interfaces'; import {ContinueExample, WordcraftContext} from '../../../context'; import {OperationType} from '@core/shared/types'; -import {PalmModel} from '..'; +import { GeminiModel } from '..'; -export function makePromptHandler(model: PalmModel, context: WordcraftContext) { +export function makePromptHandler(model: GeminiModel, context: WordcraftContext) { function generatePrompt(text: string) { const prefix = model.getStoryPrefix(); const suffix = 'Continue the story: '; diff --git a/app/models/palm/prompts/elaborate.ts b/app/models/gemini/prompts/elaborate.ts similarity index 93% rename from app/models/palm/prompts/elaborate.ts rename to app/models/gemini/prompts/elaborate.ts index 258b8ec..6d25932 100644 --- a/app/models/palm/prompts/elaborate.ts +++ b/app/models/gemini/prompts/elaborate.ts @@ -20,9 +20,9 @@ import {ElaboratePromptParams} from '@core/shared/interfaces'; import {ElaborateExample, WordcraftContext} from '../../../context'; import {OperationType} from '@core/shared/types'; -import {PalmModel} from '..'; +import { GeminiModel } from '..'; -export function makePromptHandler(model: PalmModel, context: WordcraftContext) { +export function makePromptHandler(model: GeminiModel, context: WordcraftContext) { function generatePrompt(text: string, subject: string) { const prefix = model.getStoryPrefix(); const suffix = `Describe "${subject}" in more detail.`; diff --git a/app/models/palm/prompts/first_sentence.ts b/app/models/gemini/prompts/first_sentence.ts similarity index 95% rename from app/models/palm/prompts/first_sentence.ts rename to app/models/gemini/prompts/first_sentence.ts index 3b37a77..a9b1631 100644 --- a/app/models/palm/prompts/first_sentence.ts +++ b/app/models/gemini/prompts/first_sentence.ts @@ -20,10 +20,10 @@ import {FirstSentencePromptParams} from '@core/shared/interfaces'; import {FirstSentenceExample, WordcraftContext} from '../../../context'; import {OperationType} from '@core/shared/types'; -import {PalmModel} from '..'; +import { GeminiModel } from '..'; import {parseSentences} from '@lib/parse_sentences'; -export function makePromptHandler(model: PalmModel, context: WordcraftContext) { +export function makePromptHandler(model: GeminiModel, context: WordcraftContext) { function generatePrompt(textAfterBlank: string) { const prefix = model.getStoryPrefix(); const suffix = 'Tell me the first sentence that fills in the blank: '; diff --git a/app/models/palm/prompts/freeform.ts b/app/models/gemini/prompts/freeform.ts similarity index 94% rename from app/models/palm/prompts/freeform.ts rename to app/models/gemini/prompts/freeform.ts index c2b9e2f..38ab5b7 100644 --- a/app/models/palm/prompts/freeform.ts +++ b/app/models/gemini/prompts/freeform.ts @@ -21,9 +21,9 @@ import {shuffle} from '@lib/utils'; import {FreeformPromptParams} from '@core/shared/interfaces'; import {FreeformExample, WordcraftContext} from '../../../context'; import {OperationType} from '@core/shared/types'; -import {PalmModel} from '..'; +import { GeminiModel } from '..'; -export function makePromptHandler(model: PalmModel, context: WordcraftContext) { +export function makePromptHandler(model: GeminiModel, context: WordcraftContext) { function getPromptContext() { const examples = context.getExampleData( OperationType.FREEFORM diff --git a/app/models/palm/prompts/generate_within_sentence.ts b/app/models/gemini/prompts/generate_within_sentence.ts similarity index 97% rename from app/models/palm/prompts/generate_within_sentence.ts rename to app/models/gemini/prompts/generate_within_sentence.ts index e36d137..b933ea3 100644 --- a/app/models/palm/prompts/generate_within_sentence.ts +++ b/app/models/gemini/prompts/generate_within_sentence.ts @@ -25,9 +25,9 @@ import { WordcraftContext, } from '../../../context'; import {OperationType} from '@core/shared/types'; -import {PalmModel} from '..'; +import { GeminiModel } from '..'; -export function makePromptHandler(model: PalmModel, context: WordcraftContext) { +export function makePromptHandler(model: GeminiModel, context: WordcraftContext) { function generatePrompt( textBeforeBlank: string, textAfterBlank: string, diff --git a/app/models/palm/prompts/meta_prompt.ts b/app/models/gemini/prompts/meta_prompt.ts similarity index 95% rename from app/models/palm/prompts/meta_prompt.ts rename to app/models/gemini/prompts/meta_prompt.ts index 7747517..c6df301 100644 --- a/app/models/palm/prompts/meta_prompt.ts +++ b/app/models/gemini/prompts/meta_prompt.ts @@ -21,9 +21,9 @@ import {MetaPromptPromptParams} from '@core/shared/interfaces'; import {MetaPromptExample, WordcraftContext} from '../../../context'; import {OperationType} from '@core/shared/types'; import {endsWithPunctuation} from '@lib/parse_sentences/utils'; -import {PalmModel} from '..'; +import { GeminiModel } from '..'; -export function makePromptHandler(model: PalmModel, context: WordcraftContext) { +export function makePromptHandler(model: GeminiModel, context: WordcraftContext) { function generatePrompt(text: string) { const prefix = model.getStoryPrefix(); const suffix = 'Next prompt:'; diff --git a/app/models/palm/prompts/new_story.ts b/app/models/gemini/prompts/new_story.ts similarity index 93% rename from app/models/palm/prompts/new_story.ts rename to app/models/gemini/prompts/new_story.ts index 6ac1591..e5613a8 100644 --- a/app/models/palm/prompts/new_story.ts +++ b/app/models/gemini/prompts/new_story.ts @@ -20,9 +20,9 @@ import {NewStoryPromptParams} from '@core/shared/interfaces'; import {NewStoryExample, WordcraftContext} from '../../../context'; import {OperationType} from '@core/shared/types'; -import {PalmModel} from '..'; +import { GeminiModel } from '..'; -export function makePromptHandler(model: PalmModel, context: WordcraftContext) { +export function makePromptHandler(model: GeminiModel, context: WordcraftContext) { function getPromptContext() { const examples = context.getExampleData( OperationType.NEW_STORY diff --git a/app/models/palm/prompts/next_sentence.ts b/app/models/gemini/prompts/next_sentence.ts similarity index 97% rename from app/models/palm/prompts/next_sentence.ts rename to app/models/gemini/prompts/next_sentence.ts index 9062fc5..c9688c9 100644 --- a/app/models/palm/prompts/next_sentence.ts +++ b/app/models/gemini/prompts/next_sentence.ts @@ -20,10 +20,10 @@ import {NextSentencePromptParams} from '@core/shared/interfaces'; import {NextSentenceExample, WordcraftContext} from '../../../context'; import {OperationType} from '@core/shared/types'; -import {PalmModel} from '..'; +import { GeminiModel } from '..'; import {parseSentences} from '@lib/parse_sentences'; -export function makePromptHandler(model: PalmModel, context: WordcraftContext) { +export function makePromptHandler(model: GeminiModel, context: WordcraftContext) { function generatePrompt( textBeforeBlank: string, textAfterBlank: string, diff --git a/app/models/palm/prompts/replace.ts b/app/models/gemini/prompts/replace.ts similarity index 96% rename from app/models/palm/prompts/replace.ts rename to app/models/gemini/prompts/replace.ts index 3b9c731..4d9dcdd 100644 --- a/app/models/palm/prompts/replace.ts +++ b/app/models/gemini/prompts/replace.ts @@ -22,7 +22,7 @@ import {wordinessOptions, WordinessOption} from '../../shared'; import {ReplacePromptParams} from '@core/shared/interfaces'; import {ReplaceExample, WordcraftContext} from '../../../context'; import {OperationType} from '@core/shared/types'; -import {PalmModel} from '..'; +import { GeminiModel } from '..'; function nWordsToWordiness(length: number) { const index = @@ -32,7 +32,7 @@ function nWordsToWordiness(length: number) { } // tslint:disable-next-line:enforce-comments-on-exported-symbols -export function makePromptHandler(model: PalmModel, context: WordcraftContext) { +export function makePromptHandler(model: GeminiModel, context: WordcraftContext) { function generatePrompt( storyBeforeBlank: string, storyAfterBlank: string, diff --git a/app/models/palm/prompts/rewrite_end_of_sentence.ts b/app/models/gemini/prompts/rewrite_end_of_sentence.ts similarity index 97% rename from app/models/palm/prompts/rewrite_end_of_sentence.ts rename to app/models/gemini/prompts/rewrite_end_of_sentence.ts index 459660a..e61e612 100644 --- a/app/models/palm/prompts/rewrite_end_of_sentence.ts +++ b/app/models/gemini/prompts/rewrite_end_of_sentence.ts @@ -21,9 +21,9 @@ import {parseSentences} from '@lib/parse_sentences'; import {RewriteEndOfSentencePromptParams} from '@core/shared/interfaces'; import {RewriteEndOfSentenceExample, WordcraftContext} from '../../../context'; import {OperationType} from '@core/shared/types'; -import {PalmModel} from '..'; +import { GeminiModel } from '..'; -export function makePromptHandler(model: PalmModel, context: WordcraftContext) { +export function makePromptHandler(model: GeminiModel, context: WordcraftContext) { function generatePrompt( textBeforeBlank: string, textAfterBlank: string, diff --git a/app/models/palm/prompts/rewrite_selection.ts b/app/models/gemini/prompts/rewrite_selection.ts similarity index 96% rename from app/models/palm/prompts/rewrite_selection.ts rename to app/models/gemini/prompts/rewrite_selection.ts index e6ab94b..cbd7da0 100644 --- a/app/models/palm/prompts/rewrite_selection.ts +++ b/app/models/gemini/prompts/rewrite_selection.ts @@ -21,13 +21,13 @@ import {shuffle} from '@lib/utils'; import {RewriteSelectionPromptParams} from '@core/shared/interfaces'; import {RewriteSelectionExample, WordcraftContext} from '../../../context'; import {OperationType} from '@core/shared/types'; -import {PalmModel} from '..'; +import { GeminiModel } from '..'; function capitalize(str: string) { return str.charAt(0).toUpperCase() + str.slice(1); } -export function makePromptHandler(model: PalmModel, context: WordcraftContext) { +export function makePromptHandler(model: GeminiModel, context: WordcraftContext) { function insertBlank(pre: string, post: string) { return `${pre}${model.getBlank()}${post}`; } diff --git a/app/models/palm/prompts/rewrite_sentence.ts b/app/models/gemini/prompts/rewrite_sentence.ts similarity index 95% rename from app/models/palm/prompts/rewrite_sentence.ts rename to app/models/gemini/prompts/rewrite_sentence.ts index 6eb2e07..323644b 100644 --- a/app/models/palm/prompts/rewrite_sentence.ts +++ b/app/models/gemini/prompts/rewrite_sentence.ts @@ -21,9 +21,9 @@ import {shuffle} from '@lib/utils'; import {RewriteSentencePromptParams} from '@core/shared/interfaces'; import {RewriteSentenceExample, WordcraftContext} from '../../../context'; import {OperationType} from '@core/shared/types'; -import {PalmModel} from '..'; +import { GeminiModel } from '..'; -export function makePromptHandler(model: PalmModel, context: WordcraftContext) { +export function makePromptHandler(model: GeminiModel, context: WordcraftContext) { function insertBlank(pre: string, post: string) { return `${pre}${model.getBlank()}${post}`; } diff --git a/app/models/palm/prompts/suggest_rewrite.ts b/app/models/gemini/prompts/suggest_rewrite.ts similarity index 94% rename from app/models/palm/prompts/suggest_rewrite.ts rename to app/models/gemini/prompts/suggest_rewrite.ts index f88e3fc..2922554 100644 --- a/app/models/palm/prompts/suggest_rewrite.ts +++ b/app/models/gemini/prompts/suggest_rewrite.ts @@ -21,9 +21,9 @@ import {SuggestRewritePromptParams} from '@core/shared/interfaces'; import {SuggestRewriteExample, WordcraftContext} from '../../../context'; import {OperationType} from '@core/shared/types'; import {TextType} from '@core/shared/types'; -import {PalmModel} from '..'; +import { GeminiModel } from '..'; -export function makePromptHandler(model: PalmModel, context: WordcraftContext) { +export function makePromptHandler(model: GeminiModel, context: WordcraftContext) { function generatePrompt(text: string, toRewrite: string) { const prefix = model.getStoryPrefix(); const instruction = `Here's the sentence to rewrite: `;