From 364bd424bde6200cd609e173d25da1a6bb70b1d2 Mon Sep 17 00:00:00 2001 From: Jamesb Date: Sat, 9 Mar 2024 17:17:10 +0000 Subject: [PATCH] fix: iimprove question generator --- .../createQueriesFromProfile.ts | 26 +++++++++---------- .../prompts/shared.ts | 7 ----- .../prompts/zeroShotFreeForm.ts | 19 ++++++++++---- .../prompts/zeroShotShort.ts | 26 ------------------- .../server/src/tasks/twitterPipeline.saga.ts | 9 ------- 5 files changed, 27 insertions(+), 60 deletions(-) delete mode 100644 packages/cli/src/recommender/prompts/createQueriesFromProfile/prompts/shared.ts delete mode 100644 packages/cli/src/recommender/prompts/createQueriesFromProfile/prompts/zeroShotShort.ts diff --git a/packages/cli/src/recommender/prompts/createQueriesFromProfile/createQueriesFromProfile.ts b/packages/cli/src/recommender/prompts/createQueriesFromProfile/createQueriesFromProfile.ts index 45f2c38..4242e3b 100644 --- a/packages/cli/src/recommender/prompts/createQueriesFromProfile/createQueriesFromProfile.ts +++ b/packages/cli/src/recommender/prompts/createQueriesFromProfile/createQueriesFromProfile.ts @@ -3,15 +3,11 @@ import { CreateQueriesFromProfileInput, createQueriesFromProfileInputSchema, } from "./schemas/createQueriesFromProfileInputSchema"; -import { createQueriesFromProfileOutputSchema } from "./schemas/createQueriesFromProfileOutputSchema"; -import { - RequestTagsWithoutName, - formatPromptName, -} from "../../../openpipe/requestTags"; -import { openpipe } from "../../../openpipe/openpipe"; import { experilearningDataset } from "./datasets/experilearningDataset"; import { createQueriesFromProfileZeroShotFreeFormPrompt } from "./prompts/zeroShotFreeForm"; import { DefaultRun } from "modelfusion"; +import { z } from "zod"; +import dotenv from "dotenv"; export const CREATE_SEARCH_QUERIES_FROM_PROFILE = "Create Questions"; @@ -21,7 +17,7 @@ export const CREATE_SEARCH_QUERIES_FROM_PROFILE = "Create Questions"; */ export class CreateSearchQueriesFromProfile extends Prompt< typeof createQueriesFromProfileInputSchema, - typeof createQueriesFromProfileOutputSchema + z.ZodString > { constructor() { super({ @@ -30,7 +26,6 @@ export class CreateSearchQueriesFromProfile extends Prompt< prompts: [createQueriesFromProfileZeroShotFreeFormPrompt], model: "gpt-4", input: createQueriesFromProfileInputSchema, - output: createQueriesFromProfileOutputSchema, exampleData: [], }); } @@ -47,12 +42,16 @@ export class CreateSearchQueriesFromProfile extends Prompt< profile: args.profile, }; try { - const res = await this.run({ - promptVariables, - stream: false, - run: args.run, + const res = + (await this.run({ + promptVariables, + stream: false, + run: args.run, + })) || ""; + const queries = res.split("\n").map((query) => { + return query.replace(/(^- )|(^\d+\. )/g, "").trim(); }); - return res || { queries: [] }; + return { queries }; } catch (e) { console.error(e); return { queries: [] }; @@ -72,6 +71,7 @@ export const createQueriesFromProfile = () => if (require.main === module) { (async () => { + dotenv.config({ path: "packages/cli/.env" }); const res = await createQueriesFromProfile().execute({ user: experilearningDataset.user.value, bio: experilearningDataset.bio.value, diff --git a/packages/cli/src/recommender/prompts/createQueriesFromProfile/prompts/shared.ts b/packages/cli/src/recommender/prompts/createQueriesFromProfile/prompts/shared.ts deleted file mode 100644 index 24b744d..0000000 --- a/packages/cli/src/recommender/prompts/createQueriesFromProfile/prompts/shared.ts +++ /dev/null @@ -1,7 +0,0 @@ -export const sharedCreateQueriesInstructions = (args: { short: boolean }) => - ` -# Instructions -- Your job is to analyze the user's profile to identify ideas, concepts, problems, people and events that interest them. -- Then you should brainstorm a list of 10 questions the user would be interested in researching. -- DO NOT USE ACRONYMS OR ABBREVIATIONS, ALWAYS USE THE FULL NAME WITH THE ACRONYM IN PARANTHESES. -`.trim(); diff --git a/packages/cli/src/recommender/prompts/createQueriesFromProfile/prompts/zeroShotFreeForm.ts b/packages/cli/src/recommender/prompts/createQueriesFromProfile/prompts/zeroShotFreeForm.ts index 8120c91..d7b13d7 100644 --- a/packages/cli/src/recommender/prompts/createQueriesFromProfile/prompts/zeroShotFreeForm.ts +++ b/packages/cli/src/recommender/prompts/createQueriesFromProfile/prompts/zeroShotFreeForm.ts @@ -1,5 +1,4 @@ import { CandidatePrompt, ChatMessage } from "prompt-iteration-assistant"; -import { sharedCreateQueriesInstructions } from "./shared"; import { CreateQueriesFromProfileInput } from "../schemas/createQueriesFromProfileInputSchema"; export const createQueriesFromProfileZeroShotFreeFormPrompt = @@ -7,17 +6,27 @@ export const createQueriesFromProfileZeroShotFreeFormPrompt = name: "zero shot free form-2", compile() { return [ - ChatMessage.system(sharedCreateQueriesInstructions({ short: false })), + ChatMessage.system( + ` +# Instructions +- Based on your persona, write 10 research questions you would be interested in investigating based on ideas, concepts, problems, people and events that interest you. +- Don't include introductory or background questions. +- Make sure the questions are interesting. Don't ask questions you likely know the answer to based on your persona. +- Don't ask duplicate questions. +`.trim() + ), { role: "user", content: ` -# My Twitter Username +# Your Persona + +## Your Username ${this.getVariable("user")} -# My Twitter Bio +## Your Bio ${this.getVariable("bio")} -# My Profile +## Your Profile ${this.getVariable("profile")} `.trim(), }, diff --git a/packages/cli/src/recommender/prompts/createQueriesFromProfile/prompts/zeroShotShort.ts b/packages/cli/src/recommender/prompts/createQueriesFromProfile/prompts/zeroShotShort.ts deleted file mode 100644 index 7bb4983..0000000 --- a/packages/cli/src/recommender/prompts/createQueriesFromProfile/prompts/zeroShotShort.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { CandidatePrompt, ChatMessage } from "prompt-iteration-assistant"; -import { sharedCreateQueriesInstructions } from "./shared"; -import { CreateQueriesFromProfileInput } from "../schemas/createQueriesFromProfileInputSchema"; - -export const createQueriesFromProfileZeroShotPrompt = - new CandidatePrompt({ - name: "zero shot", - compile() { - return [ - ChatMessage.system(sharedCreateQueriesInstructions({ short: true })), - { - role: "user", - content: ` -# My Twitter Username -${this.getVariable("user")} - -# My Twitter Bio -${this.getVariable("bio")} - -# My Profile -${this.getVariable("profile")} -`.trim(), - }, - ]; - }, - }); diff --git a/packages/server/src/tasks/twitterPipeline.saga.ts b/packages/server/src/tasks/twitterPipeline.saga.ts index 9424ba2..536348f 100644 --- a/packages/server/src/tasks/twitterPipeline.saga.ts +++ b/packages/server/src/tasks/twitterPipeline.saga.ts @@ -396,15 +396,6 @@ export const twitterPipeline = new Saga( }), { concurrency: 2 } ); - console.log( - "all results", - JSON.stringify({ - metaphorArticleResults, - metaphorYouTubeResults, - youtubeResults, - }) - ); - const all = [ ...youtubeResults, ...metaphorYouTubeResults,