mirror of
https://github.com/stackblitz/bolt.new
synced 2025-02-06 04:48:04 +00:00
Merge pull request #10 from SujalXplores/feat/prompt-caching
Feat/prompt caching
This commit is contained in:
commit
78d5202360
@ -31,6 +31,7 @@ https://thinktank.ottomator.ai
|
|||||||
- ✅ Ability to revert code to earlier version (@wonderwhy-er)
|
- ✅ Ability to revert code to earlier version (@wonderwhy-er)
|
||||||
- ✅ Cohere Integration (@hasanraiyan)
|
- ✅ Cohere Integration (@hasanraiyan)
|
||||||
- ✅ Dynamic model max token length (@hasanraiyan)
|
- ✅ Dynamic model max token length (@hasanraiyan)
|
||||||
|
- ✅ Prompt caching (@SujalXplores)
|
||||||
- ⬜ **HIGH PRIORITY** - Prevent Bolt from rewriting files as often (file locking and diffs)
|
- ⬜ **HIGH PRIORITY** - Prevent Bolt from rewriting files as often (file locking and diffs)
|
||||||
- ⬜ **HIGH PRIORITY** - Better prompting for smaller LLMs (code window sometimes doesn't start)
|
- ⬜ **HIGH PRIORITY** - Better prompting for smaller LLMs (code window sometimes doesn't start)
|
||||||
- ⬜ **HIGH PRIORITY** - Load local projects into the app
|
- ⬜ **HIGH PRIORITY** - Load local projects into the app
|
||||||
@ -42,7 +43,6 @@ https://thinktank.ottomator.ai
|
|||||||
- ⬜ Perplexity Integration
|
- ⬜ Perplexity Integration
|
||||||
- ⬜ Vertex AI Integration
|
- ⬜ Vertex AI Integration
|
||||||
- ⬜ Deploy directly to Vercel/Netlify/other similar platforms
|
- ⬜ Deploy directly to Vercel/Netlify/other similar platforms
|
||||||
- ⬜ Prompt caching
|
|
||||||
- ⬜ Better prompt enhancing
|
- ⬜ Better prompt enhancing
|
||||||
- ⬜ Have LLM plan the project in a MD file for better results/transparency
|
- ⬜ Have LLM plan the project in a MD file for better results/transparency
|
||||||
- ⬜ VSCode Integration with git-like confirmations
|
- ⬜ VSCode Integration with git-like confirmations
|
||||||
|
@ -6,19 +6,20 @@ import { useStore } from '@nanostores/react';
|
|||||||
import type { Message } from 'ai';
|
import type { Message } from 'ai';
|
||||||
import { useChat } from 'ai/react';
|
import { useChat } from 'ai/react';
|
||||||
import { useAnimate } from 'framer-motion';
|
import { useAnimate } from 'framer-motion';
|
||||||
import { memo, useEffect, useRef, useState } from 'react';
|
import { memo, useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { cssTransition, toast, ToastContainer } from 'react-toastify';
|
import { cssTransition, toast, ToastContainer } from 'react-toastify';
|
||||||
import { useMessageParser, usePromptEnhancer, useShortcuts, useSnapScroll } from '~/lib/hooks';
|
import { useMessageParser, usePromptEnhancer, useShortcuts, useSnapScroll } from '~/lib/hooks';
|
||||||
import { description, useChatHistory } from '~/lib/persistence';
|
import { description, useChatHistory } from '~/lib/persistence';
|
||||||
import { chatStore } from '~/lib/stores/chat';
|
import { chatStore } from '~/lib/stores/chat';
|
||||||
import { workbenchStore } from '~/lib/stores/workbench';
|
import { workbenchStore } from '~/lib/stores/workbench';
|
||||||
import { fileModificationsToHTML } from '~/utils/diff';
|
import { fileModificationsToHTML } from '~/utils/diff';
|
||||||
import { DEFAULT_MODEL, DEFAULT_PROVIDER, PROVIDER_LIST } from '~/utils/constants';
|
import { DEFAULT_MODEL, DEFAULT_PROVIDER, PROMPT_COOKIE_KEY, PROVIDER_LIST } from '~/utils/constants';
|
||||||
import { cubicEasingFn } from '~/utils/easings';
|
import { cubicEasingFn } from '~/utils/easings';
|
||||||
import { createScopedLogger, renderLogger } from '~/utils/logger';
|
import { createScopedLogger, renderLogger } from '~/utils/logger';
|
||||||
import { BaseChat } from './BaseChat';
|
import { BaseChat } from './BaseChat';
|
||||||
import Cookies from 'js-cookie';
|
import Cookies from 'js-cookie';
|
||||||
import type { ProviderInfo } from '~/utils/types';
|
import type { ProviderInfo } from '~/utils/types';
|
||||||
|
import { debounce } from '~/utils/debounce';
|
||||||
|
|
||||||
const toastAnimation = cssTransition({
|
const toastAnimation = cssTransition({
|
||||||
enter: 'animated fadeInRight',
|
enter: 'animated fadeInRight',
|
||||||
@ -120,6 +121,7 @@ export const ChatImpl = memo(
|
|||||||
logger.debug('Finished streaming');
|
logger.debug('Finished streaming');
|
||||||
},
|
},
|
||||||
initialMessages,
|
initialMessages,
|
||||||
|
initialInput: Cookies.get(PROMPT_COOKIE_KEY) || '',
|
||||||
});
|
});
|
||||||
|
|
||||||
const { enhancingPrompt, promptEnhanced, enhancePrompt, resetEnhancer } = usePromptEnhancer();
|
const { enhancingPrompt, promptEnhanced, enhancePrompt, resetEnhancer } = usePromptEnhancer();
|
||||||
@ -225,12 +227,33 @@ export const ChatImpl = memo(
|
|||||||
}
|
}
|
||||||
|
|
||||||
setInput('');
|
setInput('');
|
||||||
|
Cookies.remove(PROMPT_COOKIE_KEY);
|
||||||
|
|
||||||
resetEnhancer();
|
resetEnhancer();
|
||||||
|
|
||||||
textareaRef.current?.blur();
|
textareaRef.current?.blur();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the change event for the textarea and updates the input state.
|
||||||
|
* @param event - The change event from the textarea.
|
||||||
|
*/
|
||||||
|
const onTextareaChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||||
|
handleInputChange(event);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debounced function to cache the prompt in cookies.
|
||||||
|
* Caches the trimmed value of the textarea input after a delay to optimize performance.
|
||||||
|
*/
|
||||||
|
const debouncedCachePrompt = useCallback(
|
||||||
|
debounce((event: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||||
|
const trimmedValue = event.target.value.trim();
|
||||||
|
Cookies.set(PROMPT_COOKIE_KEY, trimmedValue, { expires: 30 });
|
||||||
|
}, 1000),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
const [messageRef, scrollRef] = useSnapScroll();
|
const [messageRef, scrollRef] = useSnapScroll();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -268,7 +291,10 @@ export const ChatImpl = memo(
|
|||||||
setProvider={handleProviderChange}
|
setProvider={handleProviderChange}
|
||||||
messageRef={messageRef}
|
messageRef={messageRef}
|
||||||
scrollRef={scrollRef}
|
scrollRef={scrollRef}
|
||||||
handleInputChange={handleInputChange}
|
handleInputChange={(e) => {
|
||||||
|
onTextareaChange(e);
|
||||||
|
debouncedCachePrompt(e);
|
||||||
|
}}
|
||||||
handleStop={abort}
|
handleStop={abort}
|
||||||
description={description}
|
description={description}
|
||||||
importChat={importChat}
|
importChat={importChat}
|
||||||
|
@ -7,6 +7,7 @@ export const MODIFICATIONS_TAG_NAME = 'bolt_file_modifications';
|
|||||||
export const MODEL_REGEX = /^\[Model: (.*?)\]\n\n/;
|
export const MODEL_REGEX = /^\[Model: (.*?)\]\n\n/;
|
||||||
export const PROVIDER_REGEX = /\[Provider: (.*?)\]\n\n/;
|
export const PROVIDER_REGEX = /\[Provider: (.*?)\]\n\n/;
|
||||||
export const DEFAULT_MODEL = 'claude-3-5-sonnet-latest';
|
export const DEFAULT_MODEL = 'claude-3-5-sonnet-latest';
|
||||||
|
export const PROMPT_COOKIE_KEY = 'cachedPrompt';
|
||||||
|
|
||||||
const PROVIDER_LIST: ProviderInfo[] = [
|
const PROVIDER_LIST: ProviderInfo[] = [
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user