Remove console.log statements and unused dependencies
This commit is contained in:
@@ -96,7 +96,6 @@ chrome.runtime.onMessage.addListener(async (message) => {
|
||||
clearBadge()
|
||||
}, 5000)
|
||||
}
|
||||
console.log("Pulling model", message.modelName)
|
||||
|
||||
await streamDownload(ollamaURL, message.modelName)
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ export const PlaygroundForm = ({ dropedFile }: Props) => {
|
||||
initialValues: {
|
||||
message: "",
|
||||
image: ""
|
||||
},
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
React.useEffect(() => {
|
||||
@@ -93,6 +92,43 @@ export const PlaygroundForm = ({ dropedFile }: Props) => {
|
||||
}
|
||||
})
|
||||
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === "Process" || e.key === "229") return
|
||||
if (
|
||||
e.key === "Enter" &&
|
||||
!e.shiftKey &&
|
||||
!isSending &&
|
||||
sendWhenEnter &&
|
||||
!e.isComposing
|
||||
) {
|
||||
e.preventDefault()
|
||||
form.onSubmit(async (value) => {
|
||||
if (value.message.trim().length === 0) {
|
||||
return
|
||||
}
|
||||
if (!selectedModel || selectedModel.length === 0) {
|
||||
form.setFieldError("message", "Please select a model")
|
||||
return
|
||||
}
|
||||
if (webSearch) {
|
||||
const defaultEM = await defaultEmbeddingModelForRag()
|
||||
if (!defaultEM) {
|
||||
form.setFieldError(
|
||||
"message",
|
||||
"Please set an embedding model on the Settings > Ollama page"
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
form.reset()
|
||||
textAreaFocus()
|
||||
await sendMessage({
|
||||
image: value.image,
|
||||
message: value.message.trim()
|
||||
})
|
||||
})()
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div className="px-3 pt-3 md:px-6 md:pt-6 md:bg-white dark:bg-[#262626] border rounded-t-xl border-black/10 dark:border-gray-600">
|
||||
<div
|
||||
@@ -140,7 +176,6 @@ export const PlaygroundForm = ({ dropedFile }: Props) => {
|
||||
image: value.image,
|
||||
message: value.message.trim()
|
||||
})
|
||||
|
||||
})}
|
||||
className="shrink-0 flex-grow flex flex-col items-center ">
|
||||
<input
|
||||
@@ -155,41 +190,7 @@ export const PlaygroundForm = ({ dropedFile }: Props) => {
|
||||
/>
|
||||
<div className="w-full border-x border-t flex flex-col dark:border-gray-600 rounded-t-xl p-2">
|
||||
<textarea
|
||||
onKeyDown={(e) => {
|
||||
if (
|
||||
e.key === "Enter" &&
|
||||
!e.shiftKey &&
|
||||
!isSending &&
|
||||
sendWhenEnter
|
||||
) {
|
||||
e.preventDefault()
|
||||
form.onSubmit(async (value) => {
|
||||
if (value.message.trim().length === 0) {
|
||||
return
|
||||
}
|
||||
if (!selectedModel || selectedModel.length === 0) {
|
||||
form.setFieldError("message", "Please select a model")
|
||||
return
|
||||
}
|
||||
if (webSearch) {
|
||||
const defaultEM = await defaultEmbeddingModelForRag()
|
||||
if (!defaultEM) {
|
||||
form.setFieldError(
|
||||
"message",
|
||||
"Please set an embedding model on the Settings > Ollama page"
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
form.reset()
|
||||
textAreaFocus()
|
||||
await sendMessage({
|
||||
image: value.image,
|
||||
message: value.message.trim()
|
||||
})
|
||||
})()
|
||||
}
|
||||
}}
|
||||
onKeyDown={(e) => handleKeyDown(e as unknown as KeyboardEvent)}
|
||||
ref={textareaRef}
|
||||
className="px-2 py-2 w-full resize-none bg-transparent focus-within:outline-none focus:ring-0 focus-visible:ring-0 ring-0 dark:ring-0 border-0 dark:text-gray-100"
|
||||
required
|
||||
|
||||
@@ -72,6 +72,44 @@ export const SidepanelForm = ({ dropedFile }: Props) => {
|
||||
}
|
||||
})
|
||||
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === "Process" || e.key === "229") return
|
||||
if (
|
||||
e.key === "Enter" &&
|
||||
!e.shiftKey &&
|
||||
!isSending &&
|
||||
sendWhenEnter &&
|
||||
!e.isComposing
|
||||
) {
|
||||
e.preventDefault()
|
||||
form.onSubmit(async (value) => {
|
||||
if (value.message.trim().length === 0) {
|
||||
return
|
||||
}
|
||||
if (!selectedModel || selectedModel.length === 0) {
|
||||
form.setFieldError("message", "Please select a model")
|
||||
return
|
||||
}
|
||||
if (chatMode === "rag") {
|
||||
const defaultEM = await defaultEmbeddingModelForRag()
|
||||
if (!defaultEM) {
|
||||
form.setFieldError(
|
||||
"message",
|
||||
"Please set an embedding model on the settings page"
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
form.reset()
|
||||
textAreaFocus()
|
||||
await sendMessage({
|
||||
image: value.image,
|
||||
message: value.message.trim()
|
||||
})
|
||||
})()
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="px-3 pt-3 md:px-6 md:pt-6 md:bg-white dark:bg-[#262626] border rounded-t-xl border-black/10 dark:border-gray-600">
|
||||
<div
|
||||
@@ -133,41 +171,7 @@ export const SidepanelForm = ({ dropedFile }: Props) => {
|
||||
/>
|
||||
<div className="w-full border-x border-t flex flex-col dark:border-gray-600 rounded-t-xl p-2">
|
||||
<textarea
|
||||
onKeyDown={(e) => {
|
||||
if (
|
||||
e.key === "Enter" &&
|
||||
!e.shiftKey &&
|
||||
!isSending &&
|
||||
sendWhenEnter
|
||||
) {
|
||||
e.preventDefault()
|
||||
form.onSubmit(async (value) => {
|
||||
if (value.message.trim().length === 0) {
|
||||
return
|
||||
}
|
||||
if (!selectedModel || selectedModel.length === 0) {
|
||||
form.setFieldError("message", "Please select a model")
|
||||
return
|
||||
}
|
||||
if (chatMode === "rag") {
|
||||
const defaultEM = await defaultEmbeddingModelForRag()
|
||||
if (!defaultEM) {
|
||||
form.setFieldError(
|
||||
"message",
|
||||
"Please set an embedding model on the settings page"
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
form.reset()
|
||||
textAreaFocus()
|
||||
await sendMessage({
|
||||
image: value.image,
|
||||
message: value.message.trim()
|
||||
})
|
||||
})()
|
||||
}
|
||||
}}
|
||||
onKeyDown={(e) => handleKeyDown(e as unknown as KeyboardEvent)}
|
||||
ref={textareaRef}
|
||||
className="px-2 py-2 w-full resize-none bg-transparent focus-within:outline-none focus:ring-0 focus-visible:ring-0 ring-0 dark:ring-0 border-0 dark:text-gray-100"
|
||||
required
|
||||
|
||||
@@ -250,7 +250,6 @@ export const useMessage = () => {
|
||||
|
||||
setIsProcessing(false)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
setIsProcessing(false)
|
||||
setStreaming(false)
|
||||
|
||||
@@ -388,7 +387,6 @@ ${e?.message}
|
||||
|
||||
setIsProcessing(false)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
setIsProcessing(false)
|
||||
setStreaming(false)
|
||||
|
||||
|
||||
@@ -310,7 +310,7 @@ export const useMessageOption = () => {
|
||||
setIsProcessing(false)
|
||||
setStreaming(false)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
(e)
|
||||
|
||||
if (e?.name === "AbortError") {
|
||||
newMessage[appendingIndex].message = newMessage[
|
||||
@@ -526,7 +526,6 @@ export const useMessageOption = () => {
|
||||
setIsProcessing(false)
|
||||
setStreaming(false)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
|
||||
if (e?.name === "AbortError") {
|
||||
newMessage[appendingIndex].message = newMessage[
|
||||
|
||||
@@ -1,176 +1,172 @@
|
||||
import { useRef, useEffect, useState, useCallback } from "react";
|
||||
import { useRef, useEffect, useState, useCallback } from "react"
|
||||
|
||||
type SpeechRecognitionEvent = {
|
||||
results: SpeechRecognitionResultList;
|
||||
resultIndex: number;
|
||||
};
|
||||
results: SpeechRecognitionResultList
|
||||
resultIndex: number
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface SpeechRecognitionErrorEvent extends Event {
|
||||
error: string;
|
||||
error: string
|
||||
}
|
||||
interface Window {
|
||||
SpeechRecognition: any;
|
||||
webkitSpeechRecognition: any;
|
||||
SpeechRecognition: any
|
||||
webkitSpeechRecognition: any
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
type SpeechRecognition = {
|
||||
lang: string;
|
||||
interimResults: boolean;
|
||||
continuous: boolean;
|
||||
maxAlternatives: number;
|
||||
grammars: any;
|
||||
onresult: (event: SpeechRecognitionEvent) => void;
|
||||
onerror: (event: Event) => void;
|
||||
onend: () => void;
|
||||
start: () => void;
|
||||
stop: () => void;
|
||||
};
|
||||
lang: string
|
||||
interimResults: boolean
|
||||
continuous: boolean
|
||||
maxAlternatives: number
|
||||
grammars: any
|
||||
onresult: (event: SpeechRecognitionEvent) => void
|
||||
onerror: (event: Event) => void
|
||||
onend: () => void
|
||||
start: () => void
|
||||
stop: () => void
|
||||
}
|
||||
|
||||
type SpeechRecognitionProps = {
|
||||
onEnd?: () => void;
|
||||
onResult?: (transcript: string) => void;
|
||||
onError?: (event: Event) => void;
|
||||
};
|
||||
onEnd?: () => void
|
||||
onResult?: (transcript: string) => void
|
||||
onError?: (event: Event) => void
|
||||
}
|
||||
|
||||
type ListenArgs = {
|
||||
lang?: string;
|
||||
interimResults?: boolean;
|
||||
continuous?: boolean;
|
||||
maxAlternatives?: number;
|
||||
grammars?: any;
|
||||
};
|
||||
lang?: string
|
||||
interimResults?: boolean
|
||||
continuous?: boolean
|
||||
maxAlternatives?: number
|
||||
grammars?: any
|
||||
}
|
||||
|
||||
type SpeechRecognitionHook = {
|
||||
start: (args?: ListenArgs) => void;
|
||||
isListening: boolean;
|
||||
stop: () => void;
|
||||
supported: boolean;
|
||||
transcript: string;
|
||||
};
|
||||
start: (args?: ListenArgs) => void
|
||||
isListening: boolean
|
||||
stop: () => void
|
||||
supported: boolean
|
||||
transcript: string
|
||||
}
|
||||
|
||||
const useEventCallback = <T extends (...args: any[]) => any>(
|
||||
fn: T,
|
||||
dependencies: any[]
|
||||
) => {
|
||||
const ref = useRef<T>();
|
||||
const ref = useRef<T>()
|
||||
|
||||
useEffect(() => {
|
||||
ref.current = fn;
|
||||
}, [fn, ...dependencies]);
|
||||
ref.current = fn
|
||||
}, [fn, ...dependencies])
|
||||
|
||||
return useCallback(
|
||||
(...args: Parameters<T>) => {
|
||||
const fn = ref.current;
|
||||
return fn!(...args);
|
||||
const fn = ref.current
|
||||
return fn!(...args)
|
||||
},
|
||||
[ref]
|
||||
);
|
||||
};
|
||||
)
|
||||
}
|
||||
|
||||
export const useSpeechRecognition = (
|
||||
props: SpeechRecognitionProps = {}
|
||||
): SpeechRecognitionHook => {
|
||||
const { onEnd = () => {}, onResult = () => {}, onError = () => {} } = props;
|
||||
const recognition = useRef<SpeechRecognition | null>(null);
|
||||
const [listening, setListening] = useState<boolean>(false);
|
||||
const [supported, setSupported] = useState<boolean>(false);
|
||||
const [liveTranscript, setLiveTranscript] = useState<string>("");
|
||||
const { onEnd = () => {}, onResult = () => {}, onError = () => {} } = props
|
||||
const recognition = useRef<SpeechRecognition | null>(null)
|
||||
const [listening, setListening] = useState<boolean>(false)
|
||||
const [supported, setSupported] = useState<boolean>(false)
|
||||
const [liveTranscript, setLiveTranscript] = useState<string>("")
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined") return;
|
||||
if (typeof window === "undefined") return
|
||||
window.SpeechRecognition =
|
||||
window.SpeechRecognition || window.webkitSpeechRecognition;
|
||||
console.log("window.SpeechRecognition", window.SpeechRecognition);
|
||||
window.SpeechRecognition || window.webkitSpeechRecognition
|
||||
if (window.SpeechRecognition) {
|
||||
setSupported(true);
|
||||
recognition.current = new window.SpeechRecognition();
|
||||
setSupported(true)
|
||||
recognition.current = new window.SpeechRecognition()
|
||||
}
|
||||
}, []);
|
||||
}, [])
|
||||
|
||||
const processResult = (event: SpeechRecognitionEvent) => {
|
||||
const transcript = Array.from(event.results)
|
||||
.map((result) => result[0])
|
||||
.map((result) => result.transcript)
|
||||
.join("");
|
||||
.join("")
|
||||
|
||||
onResult(transcript);
|
||||
};
|
||||
onResult(transcript)
|
||||
}
|
||||
|
||||
const handleError = (event: Event) => {
|
||||
if ((event as SpeechRecognitionErrorEvent).error === "not-allowed") {
|
||||
if (recognition.current) {
|
||||
recognition.current.onend = null;
|
||||
recognition.current.onend = null
|
||||
}
|
||||
setListening(false);
|
||||
setListening(false)
|
||||
}
|
||||
onError(event);
|
||||
};
|
||||
onError(event)
|
||||
}
|
||||
|
||||
const listen = useEventCallback(
|
||||
(args: ListenArgs = {}) => {
|
||||
if (listening || !supported) return;
|
||||
if (listening || !supported) return
|
||||
const {
|
||||
lang = "",
|
||||
interimResults = true,
|
||||
continuous = false,
|
||||
maxAlternatives = 1,
|
||||
grammars,
|
||||
} = args;
|
||||
setListening(true);
|
||||
setLiveTranscript("");
|
||||
grammars
|
||||
} = args
|
||||
setListening(true)
|
||||
setLiveTranscript("")
|
||||
if (recognition.current) {
|
||||
recognition.current.lang = lang;
|
||||
recognition.current.interimResults = interimResults;
|
||||
recognition.current.lang = lang
|
||||
recognition.current.interimResults = interimResults
|
||||
recognition.current.onresult = (event) => {
|
||||
processResult(event);
|
||||
processResult(event)
|
||||
const transcript = Array.from(event.results)
|
||||
.map((result) => result[0])
|
||||
.map((result) => result.transcript)
|
||||
.join("");
|
||||
setLiveTranscript(transcript);
|
||||
};
|
||||
recognition.current.onerror = handleError;
|
||||
recognition.current.continuous = continuous;
|
||||
recognition.current.maxAlternatives = maxAlternatives;
|
||||
.join("")
|
||||
setLiveTranscript(transcript)
|
||||
}
|
||||
recognition.current.onerror = handleError
|
||||
recognition.current.continuous = continuous
|
||||
recognition.current.maxAlternatives = maxAlternatives
|
||||
|
||||
if (grammars) {
|
||||
recognition.current.grammars = grammars;
|
||||
recognition.current.grammars = grammars
|
||||
}
|
||||
recognition.current.onend = () => {
|
||||
if (recognition.current) {
|
||||
recognition.current.start();
|
||||
recognition.current.start()
|
||||
}
|
||||
};
|
||||
}
|
||||
if (recognition.current) {
|
||||
recognition.current.start();
|
||||
recognition.current.start()
|
||||
}
|
||||
}
|
||||
},
|
||||
[listening, supported, recognition]
|
||||
);
|
||||
)
|
||||
|
||||
const stop = useEventCallback(() => {
|
||||
if (!listening || !supported) return;
|
||||
if (!listening || !supported) return
|
||||
if (recognition.current) {
|
||||
recognition.current.onresult = null;
|
||||
recognition.current.onend = null;
|
||||
recognition.current.onerror = null;
|
||||
setListening(false);
|
||||
recognition.current.stop();
|
||||
recognition.current.onresult = null
|
||||
recognition.current.onend = null
|
||||
recognition.current.onerror = null
|
||||
setListening(false)
|
||||
recognition.current.stop()
|
||||
}
|
||||
onEnd();
|
||||
}, [listening, supported, recognition, onEnd]);
|
||||
onEnd()
|
||||
}, [listening, supported, recognition, onEnd])
|
||||
|
||||
return {
|
||||
start: listen,
|
||||
isListening: listening,
|
||||
stop,
|
||||
supported,
|
||||
transcript: liveTranscript,
|
||||
};
|
||||
};
|
||||
transcript: liveTranscript
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user