From 51b4a4398146f8a9ac0e6ef0e8c5894d5e6223b0 Mon Sep 17 00:00:00 2001 From: Travis James Date: Sat, 21 Dec 2024 20:07:40 -0600 Subject: [PATCH] added azure openai --- app/components/chat/Chat.client.tsx | 52 ++++++- app/components/chat/Messages.client.tsx | 4 + app/components/chat/ModelSelector.tsx | 2 + .../chatExportAndImport/ImportButtons.tsx | 4 + .../settings/connections/ConnectionsTab.tsx | 12 +- app/components/sidebar/HistoryItem.tsx | 8 ++ app/lib/.server/llm/stream-text.ts | 104 +++++++------- app/lib/.server/llm/switchable-stream.ts | 37 ++++- app/lib/modules/llm/registry.ts | 2 + .../persistence/ChatDescription.client.tsx | 7 +- app/routes/api.chat.ts | 136 +++++++++++++----- package.json | 1 + pnpm-lock.yaml | 56 +++++++- worker-configuration.d.ts | 6 +- 14 files changed, 329 insertions(+), 102 deletions(-) diff --git a/app/components/chat/Chat.client.tsx b/app/components/chat/Chat.client.tsx index 1b830fd90..68dfa595a 100644 --- a/app/components/chat/Chat.client.tsx +++ b/app/components/chat/Chat.client.tsx @@ -50,7 +50,12 @@ export function Chat() { { return ( - ); @@ -139,19 +144,52 @@ export const ChatImpl = memo( promptId, }, sendExtraMessageFields: true, - onError: (error) => { + headers: { + Accept: 'text/event-stream', + }, + onError: async (error: Error & { response?: Response }) => { logger.error('Request failed\n\n', error); - toast.error( - 'There was an error processing your request: ' + (error.message ? error.message : 'No details were returned'), - ); + + let errorMessage = 'An unknown error occurred'; + + try { + if (error.response) { + const response = (await error.response.json()) as { + error?: string; + details?: string; + provider?: string; + model?: string; + }; + + if (response?.error) { + errorMessage = response.error; + + if (response.details) { + logger.error('Error details:', response.details); + } + + if (response.provider) { + logger.error('Provider:', response.provider); + } + + if (response.model) { + logger.error('Model:', response.model); + } + } + } + } catch (e) { + logger.error('Error parsing error response:', e); + errorMessage = error.message || 'An unknown error occurred'; + } + + toast.error(errorMessage); + stop(); }, onFinish: (message, response) => { const usage = response.usage; if (usage) { console.log('Token usage:', usage); - - // You can now use the usage data as needed } logger.debug('Finished streaming'); diff --git a/app/components/chat/Messages.client.tsx b/app/components/chat/Messages.client.tsx index 3b619180a..28076db1a 100644 --- a/app/components/chat/Messages.client.tsx +++ b/app/components/chat/Messages.client.tsx @@ -76,6 +76,8 @@ export const Messages = React.forwardRef((props: {messageId && (