From 407069ca27056d985fb77360551b0ecd48af6793 Mon Sep 17 00:00:00 2001
From: Yi Ding <yi.s.ding@gmail.com>
Date: Tue, 4 Jul 2023 08:16:28 -0700
Subject: [PATCH] prompt work for question generator

---
 packages/core/src/Prompt.ts            | 79 ++++++++++++++++++++++++++
 packages/core/src/QuestionGenerator.ts |  8 +--
 2 files changed, 83 insertions(+), 4 deletions(-)

diff --git a/packages/core/src/Prompt.ts b/packages/core/src/Prompt.ts
index 74d02c4bd..ecfddcdc7 100644
--- a/packages/core/src/Prompt.ts
+++ b/packages/core/src/Prompt.ts
@@ -114,3 +114,82 @@ ${context}
 Question: ${query}
 Answer:`;
 };
+
+/*
+PREFIX = """\
+Given a user question, and a list of tools, output a list of relevant sub-questions \
+that when composed can help answer the full user question:
+
+"""
+
+
+example_query_str = (
+    "Compare and contrast the revenue growth and EBITDA of Uber and Lyft for year 2021"
+)
+example_tools = [
+    ToolMetadata(
+        name="uber_10k",
+        description="Provides information about Uber financials for year 2021",
+    ),
+    ToolMetadata(
+        name="lyft_10k",
+        description="Provides information about Lyft financials for year 2021",
+    ),
+]
+example_tools_str = build_tools_text(example_tools)
+example_output = [
+    SubQuestion(
+        sub_question="What is the revenue growth of Uber", tool_name="uber_10k"
+    ),
+    SubQuestion(sub_question="What is the EBITDA of Uber", tool_name="uber_10k"),
+    SubQuestion(
+        sub_question="What is the revenue growth of Lyft", tool_name="lyft_10k"
+    ),
+    SubQuestion(sub_question="What is the EBITDA of Lyft", tool_name="lyft_10k"),
+]
+example_output_str = json.dumps([x.dict() for x in example_output], indent=4)
+
+EXAMPLES = (
+    """\
+# Example 1
+<Tools>
+```json
+{tools_str}
+```
+
+<User Question>
+{query_str}
+
+
+<Output>
+```json
+{output_str}
+```
+
+""".format(
+        query_str=example_query_str,
+        tools_str=example_tools_str,
+        output_str=example_output_str,
+    )
+    .replace("{", "{{")
+    .replace("}", "}}")
+)
+
+SUFFIX = """\
+# Example 2
+<Tools>
+```json
+{tools_str}
+```
+
+<User Question>
+{query_str}
+
+<Output>
+"""
+
+DEFAULT_SUB_QUESTION_PROMPT_TMPL = PREFIX + EXAMPLES + SUFFIX
+*/
+export const defaultSubQuestionPrompt: SimplePrompt = (input) => {
+  return "";
+};
diff --git a/packages/core/src/QuestionGenerator.ts b/packages/core/src/QuestionGenerator.ts
index 739188831..35689160b 100644
--- a/packages/core/src/QuestionGenerator.ts
+++ b/packages/core/src/QuestionGenerator.ts
@@ -1,5 +1,5 @@
-import { BaseLLMPredictor } from "./LLMPredictor";
-import { SimplePrompt } from "./Prompt";
+import { BaseLLMPredictor, ChatGPTLLMPredictor } from "./LLMPredictor";
+import { SimplePrompt, defaultSubQuestionPrompt } from "./Prompt";
 import { ToolMetadata } from "./Tool";
 
 export interface BaseQuestionGenerator {
@@ -11,8 +11,8 @@ export class LLMQuestionGenerator implements BaseQuestionGenerator {
   prompt: SimplePrompt;
 
   constructor(init?: Partial<LLMQuestionGenerator>) {
-    this.llmPredictor = init?.llmPredictor ?? new BaseLLMPredictor();
-    this.prompt = init?.prompt ?? new SimplePrompt();
+    this.llmPredictor = init?.llmPredictor ?? new ChatGPTLLMPredictor();
+    this.prompt = init?.prompt ?? defaultSubQuestionPrompt;
   }
 
   async agenerate(
-- 
GitLab