diff --git a/src/App.svelte b/src/App.svelte index caf9ca8..1e772f4 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -7,15 +7,17 @@ import Home from './lib/Home.svelte' import Chat from './lib/Chat.svelte' import NewChat from './lib/NewChat.svelte' - import { chatsStorage, apiKeyStorage } from './lib/Storage.svelte' + import { chatsStorage } from './lib/Storage.svelte' import { Modals, closeModal } from 'svelte-modals' import { dispatchModalEsc, checkModalEsc } from './lib/Util.svelte' + import { set as setOpenAI } from './lib/providers/openai/util.svelte' + import { hasActiveModels } from './lib/Models.svelte' // Check if the API key is passed in as a "key" query parameter - if so, save it // Example: https://niek.github.io/chatgpt-web/#/?key=sk-... const urlParams: URLSearchParams = new URLSearchParams($querystring) if (urlParams.has('key')) { - apiKeyStorage.set(urlParams.get('key') as string) + setOpenAI({ apiKey: urlParams.get('key') as string }) } // The definition of the routes with some conditions @@ -25,7 +27,7 @@ '/chat/new': wrap({ component: NewChat, conditions: () => { - return !!$apiKeyStorage + return hasActiveModels() } }), diff --git a/src/lib/ApiUtil.svelte b/src/lib/ApiUtil.svelte index afd2f7f..74b15e5 100644 --- a/src/lib/ApiUtil.svelte +++ b/src/lib/ApiUtil.svelte @@ -5,12 +5,14 @@ const endpointGenerations = import.meta.env.VITE_ENDPOINT_GENERATIONS || '/v1/images/generations' const endpointModels = import.meta.env.VITE_ENDPOINT_MODELS || '/v1/models' const endpointEmbeddings = import.meta.env.VITE_ENDPOINT_EMBEDDINGS || '/v1/embeddings' - const endpointPetals = import.meta.env.VITE_PEDALS_WEBSOCKET || 'wss://chat.petals.dev/api/v2/generate' + const petalsBase = import.meta.env.VITE_PEDALS_WEBSOCKET || 'wss://chat.petals.dev' + const endpointPetals = import.meta.env.VITE_PEDALS_WEBSOCKET || '/api/v2/generate' export const getApiBase = ():string => apiBase export const getEndpointCompletions = ():string => endpointCompletions export const getEndpointGenerations = ():string => endpointGenerations export const getEndpointModels = ():string => endpointModels export const getEndpointEmbeddings = ():string => endpointEmbeddings - export const getPetals = ():string => endpointPetals + export const getPetalsBase = ():string => petalsBase + export const getPetalsWebsocket = ():string => endpointPetals \ No newline at end of file diff --git a/src/lib/Chat.svelte b/src/lib/Chat.svelte index db0d065..786e831 100644 --- a/src/lib/Chat.svelte +++ b/src/lib/Chat.svelte @@ -230,7 +230,8 @@ // Compose the input message const inputMessage: Message = { role: 'user', content: input.value, uuid: uuidv4() } addMessage(chatId, inputMessage) - } else if (!fillMessage && $currentChatMessages.length && $currentChatMessages[$currentChatMessages.length - 1].finish_reason === 'length') { + } else if (!fillMessage && $currentChatMessages.length && + $currentChatMessages[$currentChatMessages.length - 1].role === 'assistant') { fillMessage = $currentChatMessages[$currentChatMessages.length - 1] } diff --git a/src/lib/ChatCompletionResponse.svelte b/src/lib/ChatCompletionResponse.svelte index 72fd4e0..ac0adef 100644 --- a/src/lib/ChatCompletionResponse.svelte +++ b/src/lib/ChatCompletionResponse.svelte @@ -1,9 +1,9 @@ @@ -64,11 +65,12 @@ const setPetalsEnabled = (event: Event) => {