From 08b56e13f3f9d607594c2556ead4401a898507ac Mon Sep 17 00:00:00 2001 From: silentsilas Date: Sun, 22 Sep 2024 03:14:28 -0400 Subject: [PATCH] adjust system prompt, add a toast component, add more questions to ask --- src/lib/components/Toast.svelte | 33 ++++++++++ src/routes/ai/+page.svelte | 104 ++++++++++++++++++++++++++++++++ src/routes/api/ai/+server.ts | 2 +- 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 src/lib/components/Toast.svelte diff --git a/src/lib/components/Toast.svelte b/src/lib/components/Toast.svelte new file mode 100644 index 0000000..b10103e --- /dev/null +++ b/src/lib/components/Toast.svelte @@ -0,0 +1,33 @@ + + +{#if visible} +
+
+ {message} +
+
+{/if} + + diff --git a/src/routes/ai/+page.svelte b/src/routes/ai/+page.svelte index ca0a66d..f916c74 100644 --- a/src/routes/ai/+page.svelte +++ b/src/routes/ai/+page.svelte @@ -6,10 +6,52 @@ import { marked } from 'marked'; import { HumanMessage, AIMessage } from '@langchain/core/messages'; import { PUBLIC_LOAD_DUMMY_HISTORY } from '$env/static/public'; + import Toast from '$lib/components/Toast.svelte'; let searchResultsValue: SearchResult[] = []; let query = ''; let loading = false; + let showToast = false; + let toastMessage = ''; + + type Questions = { + [key: string]: string[]; + }; + + const QUESTIONS: Questions = { + brewing: [ + 'What is the difference between Western and Eastern styles of tea brewing?', + 'How does water temperature and steeping time affect the flavor of different types of tea?', + 'What are some traditional tea brewing methods from around the world?', + 'What is gongfu cha (功夫茶), and how does it differ from other tea preparation methods?' + ], + varieties: [ + 'What is the difference between raw and ripe pu-erh tea, and how does aging affect their taste and value?', + 'Can you explain the grading system for teas, particularly for varieties like Darjeeling and Assam?', + 'What are some rare or unusual tea varieties and what makes them unique?', + 'How do flavored teas (like Earl Grey or Jasmine) differ in production and taste from pure teas?' + ], + history: [ + 'How did tea influence global trade routes and international relations, particularly between China, Britain, and India?', + 'What role did Buddhism play in the spread of tea culture throughout Asia?', + "How did the British East India Company's involvement in the tea trade impact both India and China?", + 'How did the Opium Wars, which were closely tied to the tea trade, alter the course of Chinese history?', + 'What role did tea play in the American Revolution, and how did this event change tea consumption patterns in America?' + ], + culture: [ + 'In what ways did tea ceremonies in different cultures (like Japan and England) reflect and shape social norms?', + 'How did the democratization of tea drinking in Europe affect social structures and daily life?', + 'How has the perception of tea as a medicinal substance evolved from ancient times to the present day?', + 'What are some of the most popular tea-related idioms and proverbs, and what do they mean?' + ], + production: [ + 'How did the processing and preparation of tea evolve over time, and what factors influenced these changes?', + 'What impact did tea plantations have on local ecosystems and labor practices in countries like India and Sri Lanka?', + 'What are the main differences in production methods between black, green, oolong, and white teas?', + 'How does the terroir (environmental factors) affect the flavor and quality of tea?' + ] + }; + function generateDummyHistory() { return [ JSON.parse(JSON.stringify(new HumanMessage({ content: 'Hello, AI!' }))), @@ -101,6 +143,23 @@ console.error('Error starting new session:', error); } } + + function copyToClipboard(text: string) { + navigator.clipboard + .writeText(text) + .then(() => { + toastMessage = 'Copied to clipboard!'; + showToast = true; + }) + .catch((err) => { + toastMessage = 'Failed to copy text.'; + showToast = true; + }); + } + + function handleToastClose() { + showToast = false; + } @@ -166,6 +225,51 @@ > New Session +
+ +
+ Interesting things to ask: +
+
+ {#each Object.entries(QUESTIONS) as [category, questions]} +
+

{category}

+
    + {#each questions as item} +
  • + {item} + +
  • + {/each} +
+
+ {/each} +
+
{/if} + +{#if showToast} + +{/if} diff --git a/src/routes/api/ai/+server.ts b/src/routes/api/ai/+server.ts index 784cd0b..c809ede 100644 --- a/src/routes/api/ai/+server.ts +++ b/src/routes/api/ai/+server.ts @@ -35,7 +35,7 @@ export async function POST({ request, locals }: RequestEvent): Promise const SYSTEM_TEMPLATE = `The following pieces of context are the book you've just read. You are a tea guru, and the book was "A History of Tea: The Life and Times of the World's Favorite Beverage" by Laura C. Martin. -You might be asked questions about the book, or about tea in general. Try to augment your answer with relevant information from the book. +You might be asked questions about the book, or about tea in general. If you don't know the answer, just say that you don't know, don't try to make up an answer. Always format your response in markdown.