mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-26 18:26:38 +00:00
Remove prompt enhancer file (#97)
This commit is contained in:
parent
83e71fa91b
commit
317441e3ba
@ -33,8 +33,6 @@ interface BaseChatProps {
|
|||||||
hasPendingMessage?: boolean;
|
hasPendingMessage?: boolean;
|
||||||
pendingMessageStatus?: string;
|
pendingMessageStatus?: string;
|
||||||
messages?: Message[];
|
messages?: Message[];
|
||||||
enhancingPrompt?: boolean;
|
|
||||||
promptEnhanced?: boolean;
|
|
||||||
input?: string;
|
input?: string;
|
||||||
handleStop?: () => void;
|
handleStop?: () => void;
|
||||||
sendMessage?: (messageInput?: string) => void;
|
sendMessage?: (messageInput?: string) => void;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
export * from './usePromptEnhancer';
|
|
||||||
export * from './useSnapScroll';
|
export * from './useSnapScroll';
|
||||||
export * from './useEditChatDescription';
|
export * from './useEditChatDescription';
|
||||||
export { default } from './useViewport';
|
export { default } from './useViewport';
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
import { useState } from 'react';
|
|
||||||
import { createScopedLogger } from '~/utils/logger';
|
|
||||||
|
|
||||||
const logger = createScopedLogger('usePromptEnhancement');
|
|
||||||
|
|
||||||
export function usePromptEnhancer() {
|
|
||||||
const [enhancingPrompt, setEnhancingPrompt] = useState(false);
|
|
||||||
const [promptEnhanced, setPromptEnhanced] = useState(false);
|
|
||||||
|
|
||||||
const resetEnhancer = () => {
|
|
||||||
setEnhancingPrompt(false);
|
|
||||||
setPromptEnhanced(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const enhancePrompt = async (input: string, setInput: (value: string) => void) => {
|
|
||||||
setEnhancingPrompt(true);
|
|
||||||
setPromptEnhanced(false);
|
|
||||||
|
|
||||||
const requestBody: any = {
|
|
||||||
message: input,
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await fetch('/api/enhancer', {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(requestBody),
|
|
||||||
});
|
|
||||||
|
|
||||||
const reader = response.body?.getReader();
|
|
||||||
|
|
||||||
const originalInput = input;
|
|
||||||
|
|
||||||
if (reader) {
|
|
||||||
const decoder = new TextDecoder();
|
|
||||||
|
|
||||||
let _input = '';
|
|
||||||
let _error;
|
|
||||||
|
|
||||||
try {
|
|
||||||
setInput('');
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
const { value, done } = await reader.read();
|
|
||||||
|
|
||||||
if (done) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
_input += decoder.decode(value);
|
|
||||||
|
|
||||||
logger.trace('Set input', _input);
|
|
||||||
|
|
||||||
setInput(_input);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
_error = error;
|
|
||||||
setInput(originalInput);
|
|
||||||
} finally {
|
|
||||||
if (_error) {
|
|
||||||
logger.error(_error);
|
|
||||||
}
|
|
||||||
|
|
||||||
setEnhancingPrompt(false);
|
|
||||||
setPromptEnhanced(true);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
setInput(_input);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return { enhancingPrompt, promptEnhanced, enhancePrompt, resetEnhancer };
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user