fixed merge conflicts

This commit is contained in:
w1gs 2024-10-15 12:24:26 -04:00
parent b3fd408cf7
commit 6c2ca794f5
2 changed files with 16 additions and 54 deletions

View file

@ -151,9 +151,7 @@ const sendOpenAIMsg: SendLLMMessageFnTypeInternal = ({
}) => {
const { apikey, model } = apiConfig.openAI;
if (!apikey) {
return handleMissingApiKey('OpenAI', onError);
}
let didAbort = false;
let fullText = '';
@ -167,6 +165,9 @@ const sendOpenAIMsg: SendLLMMessageFnTypeInternal = ({
if (apiConfig.whichApi === 'openAI') {
if (!apikey) {
return handleMissingApiKey('OpenAI', onError);
}
openai = new OpenAI({ apiKey: apiConfig.openAI.apikey, dangerouslyAllowBrowser: true });
options = { model: apiConfig.openAI.model, messages: messages, stream: true, }
}
@ -185,7 +186,7 @@ const sendOpenAIMsg: SendLLMMessageFnTypeInternal = ({
options = { model: apiConfig.openAICompatible.model, messages: messages, stream: true, }
}
else {
console.error(`sendOpenAIMsg: invalid whichApi: ${apiConfig.whichApi}`)
onError(`Invalid API: ${apiConfig.whichApi}`)
throw new Error(`apiConfig.whichAPI was invalid: ${apiConfig.whichApi}`)
}
@ -207,7 +208,7 @@ const sendOpenAIMsg: SendLLMMessageFnTypeInternal = ({
onFinalMessage(fullText);
}
} catch (error) {
onError(`Error in OpenAI stream: ${error}`);
onError(`Error in stream: ${error}`);
console.error('Error in OpenAI stream:', error);
if (!didAbort) {
onFinalMessage(fullText);
@ -216,9 +217,9 @@ const sendOpenAIMsg: SendLLMMessageFnTypeInternal = ({
})
.catch((responseError) => {
if (responseError.status === 401) {
onError('Unauthorized: Invalid OpenAI API key');
onError('Unauthorized: Invalid API key');
} else if (responseError.status === 400 && responseError.param === 'stream') {
onError(`The OpenAI model '${model}' does not support streamed responses.`);
onError(`The model '${model}' does not support streamed responses.`);
} else {
onError(responseError.message);
}

View file

@ -119,10 +119,9 @@ const Sidebar = () => {
// state of chat
const [messageStream, setMessageStream] = useState('')
const [isLoading, setIsLoading] = useState(false)
const [isThreadSelectorOpen, setIsThreadSelectorOpen] = useState(false)
const [requestFailed, setRequestFailed] = useState(false)
const [requestFailedReason, setRequestFailedReason] = useState('')
const [isThreadSelectorOpen, setIsThreadSelectorOpen] = useState(false)
const abortFnRef = useRef<(() => void) | null>(null)
@ -201,7 +200,7 @@ const Sidebar = () => {
const newHistoryElt: ChatMessage = { role: 'user', content, displayContent: instructions, selection, files }
addMessageToHistory(newHistoryElt)
// send message to LLM
// send message to claude
let { abort } = sendLLMMessage({
messages: [...(currentThread?.messages ?? []).map(m => ({ role: m.role, content: m.content })), { role: 'user', content }],
onText: (newText, fullText) => setMessageStream(fullText),
@ -278,6 +277,12 @@ const Sidebar = () => {
)} />
)}
</div>}
{/* error message */}
{requestFailed && (
<div className="bg-gray-800 text-red-500 text-center p-4 mb-4 rounded-md shadow-md">
<div className="text-lg">{`${requestFailedReason}`}</div>
</div>
)}
<form
ref={formRef}
className="flex flex-row items-center rounded-md p-2"
@ -319,50 +324,6 @@ const Sidebar = () => {
</div>
</div>
</div>
{/* error message */}
{requestFailed && (
<div className="bg-gray-800 text-red-500 text-center p-4 mb-4 rounded-md shadow-md">
<div className="text-lg">{`${requestFailedReason}`}</div>
</div>
)}
<form
ref={formRef}
className="flex flex-row items-center rounded-md p-2 input"
onKeyDown={(e) => { if (e.key === 'Enter' && !e.shiftKey) onSubmit(e) }}
onSubmit={(e) => {
console.log('submit!')
e.preventDefault();
onSubmit(e)
}}>
{/* input */}
<textarea
onChange={(e) => { setInstructions(e.target.value) }}
className="w-full p-2 leading-tight resize-none max-h-[50vh] overflow-hidden bg-transparent border-none !outline-none"
placeholder="Ctrl+L to select"
rows={1}
onInput={e => { e.currentTarget.style.height = 'auto'; e.currentTarget.style.height = e.currentTarget.scrollHeight + 'px' }} // Adjust height dynamically
/>
{/* submit button */}
{isLoading ?
<button
onClick={onStop}
className="btn btn-primary rounded-r-lg max-h-10 p-2"
type='button'
>Stop</button>
: <button
className="btn btn-primary font-bold size-8 flex justify-center items-center rounded-full p-2 max-h-10"
disabled={!instructions}
type='submit'
>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<line x1="12" y1="19" x2="12" y2="5"></line>
<polyline points="5 12 12 5 19 12"></polyline>
</svg>
</button>
}
</form>
</div>
</div>