Add OpenAI o1
| @@ -46,7 +46,7 @@ | |||
| 46 | "sanitize-filename": "^1.6.3", | 46 | "sanitize-filename": "^1.6.3", |
| 47 | "sillytavern-transformers": "2.14.6", | 47 | "sillytavern-transformers": "2.14.6", |
| 48 | "simple-git": "^3.19.1", | 48 | "simple-git": "^3.19.1", |
| 49 | "tiktoken": "^1.0.15", | 49 | "tiktoken": "^1.0.16", |
| 50 | "vectra": "^0.2.2", | 50 | "vectra": "^0.2.2", |
| 51 | "wavefile": "^11.0.0", | 51 | "wavefile": "^11.0.0", |
| 52 | "write-file-atomic": "^5.0.1", | 52 | "write-file-atomic": "^5.0.1", |
| @@ -5751,9 +5751,10 @@ | |||
| 5751 | "license": "MIT" | 5751 | "license": "MIT" |
| 5752 | }, | 5752 | }, |
| 5753 | "node_modules/tiktoken": { | 5753 | "node_modules/tiktoken": { |
| 5754 | "version": "1.0.15", | 5754 | "version": "1.0.16", |
| 5755 | "resolved": "https://registry.npmjs.org/tiktoken/-/tiktoken-1.0.15.tgz", | 5755 | "resolved": "https://registry.npmjs.org/tiktoken/-/tiktoken-1.0.16.tgz", |
| 5756 | "integrity": "sha512-sCsrq/vMWUSEW29CJLNmPvWxlVp7yh2tlkAjpJltIKqp5CKf98ZNpdeHRmAlPVFlGEbswDc6SmI8vz64W/qErw==" | 5756 | "integrity": "sha512-hRcORIGF2YlAgWx3nzrGJOrKSJwLoc81HpXmMQk89632XAgURc7IeV2FgQ2iXo9z/J96fCvpsHg2kWoHcbj9fg==", |
| 5757 | "license": "MIT" | ||
| 5757 | }, | 5758 | }, |
| 5758 | "node_modules/timm": { | 5759 | "node_modules/timm": { |
| 5759 | "version": "1.7.1", | 5760 | "version": "1.7.1", |
| @@ -36,7 +36,7 @@ | |||
| 36 | "sanitize-filename": "^1.6.3", | 36 | "sanitize-filename": "^1.6.3", |
| 37 | "sillytavern-transformers": "2.14.6", | 37 | "sillytavern-transformers": "2.14.6", |
| 38 | "simple-git": "^3.19.1", | 38 | "simple-git": "^3.19.1", |
| 39 | "tiktoken": "^1.0.15", | 39 | "tiktoken": "^1.0.16", |
| 40 | "vectra": "^0.2.2", | 40 | "vectra": "^0.2.2", |
| 41 | "wavefile": "^11.0.0", | 41 | "wavefile": "^11.0.0", |
| 42 | "write-file-atomic": "^5.0.1", | 42 | "write-file-atomic": "^5.0.1", |
| @@ -383,7 +383,7 @@ | |||
| 383 | Max Response Length (tokens) | 383 | Max Response Length (tokens) |
| 384 | </div> | 384 | </div> |
| 385 | <div class="wide100p"> | 385 | <div class="wide100p"> |
| 386 | <input type="number" id="openai_max_tokens" name="openai_max_tokens" class="text_pole" min="1" max="16384"> | 386 | <input type="number" id="openai_max_tokens" name="openai_max_tokens" class="text_pole" min="1" max="65536 "> |
| 387 | </div> | 387 | </div> |
| 388 | </div> | 388 | </div> |
| 389 | <div class="range-block" data-source="openai,custom"> | 389 | <div class="range-block" data-source="openai,custom"> |
| @@ -2611,6 +2611,10 @@ | |||
| 2611 | <option value="gpt-4-0125-preview">gpt-4-0125-preview (2024)</option> | 2611 | <option value="gpt-4-0125-preview">gpt-4-0125-preview (2024)</option> |
| 2612 | <option value="gpt-4-1106-preview">gpt-4-1106-preview (2023)</option> | 2612 | <option value="gpt-4-1106-preview">gpt-4-1106-preview (2023)</option> |
| 2613 | </optgroup> | 2613 | </optgroup> |
| 2614 | <optgroup label="o1"> | ||
| 2615 | <option value="o1-preview">o1-preview</option> | ||
| 2616 | <option value="o1-mini">o1-mini</option> | ||
| 2617 | </optgroup> | ||
| 2614 | <optgroup label="Other"> | 2618 | <optgroup label="Other"> |
| 2615 | <option value="text-davinci-003">text-davinci-003</option> | 2619 | <option value="text-davinci-003">text-davinci-003</option> |
| 2616 | <option value="text-davinci-002">text-davinci-002</option> | 2620 | <option value="text-davinci-002">text-davinci-002</option> |
| @@ -2862,7 +2862,12 @@ export function getCharacterCardFields() { | |||
| 2862 | 2862 | ||
| 2863 | export function isStreamingEnabled() { | 2863 | export function isStreamingEnabled() { |
| 2864 | const noStreamSources = [chat_completion_sources.SCALE]; | 2864 | const noStreamSources = [chat_completion_sources.SCALE]; |
| 2865 | return ((main_api == 'openai' && oai_settings.stream_openai && !noStreamSources.includes(oai_settings.chat_completion_source) && !(oai_settings.chat_completion_source == chat_completion_sources.MAKERSUITE && oai_settings.google_model.includes('bison'))) | 2865 | return ( |
| 2866 | (main_api == 'openai' && | ||
| 2867 | oai_settings.stream_openai && | ||
| 2868 | !noStreamSources.includes(oai_settings.chat_completion_source) && | ||
| 2869 | !(oai_settings.chat_completion_source == chat_completion_sources.OPENAI && oai_settings.openai_model.startsWith('o1-')) && | ||
| 2870 | !(oai_settings.chat_completion_source == chat_completion_sources.MAKERSUITE && oai_settings.google_model.includes('bison'))) | ||
| 2866 | || (main_api == 'kobold' && kai_settings.streaming_kobold && kai_flags.can_use_streaming) | 2871 | || (main_api == 'kobold' && kai_settings.streaming_kobold && kai_flags.can_use_streaming) |
| 2867 | || (main_api == 'novel' && nai_settings.streaming_novel) | 2872 | || (main_api == 'novel' && nai_settings.streaming_novel) |
| 2868 | || (main_api == 'textgenerationwebui' && textgen_settings.streaming)); | 2873 | || (main_api == 'textgenerationwebui' && textgen_settings.streaming)); |
| @@ -1797,7 +1797,7 @@ async function sendOpenAIRequest(type, messages, signal) { | |||
| 1797 | const isQuiet = type === 'quiet'; | 1797 | const isQuiet = type === 'quiet'; |
| 1798 | const isImpersonate = type === 'impersonate'; | 1798 | const isImpersonate = type === 'impersonate'; |
| 1799 | const isContinue = type === 'continue'; | 1799 | const isContinue = type === 'continue'; |
| 1800 | const stream = oai_settings.stream_openai && !isQuiet && !isScale && !(isGoogle && oai_settings.google_model.includes('bison')); | 1800 | const stream = oai_settings.stream_openai && !isQuiet && !isScale && !(isGoogle && oai_settings.google_model.includes('bison')) && !(isOAI && oai_settings.openai_model.startsWith('o1-')); |
| 1801 | const useLogprobs = !!power_user.request_token_probabilities; | 1801 | const useLogprobs = !!power_user.request_token_probabilities; |
| 1802 | const canMultiSwipe = oai_settings.n > 1 && !isContinue && !isImpersonate && !isQuiet && (isOAI || isCustom); | 1802 | const canMultiSwipe = oai_settings.n > 1 && !isContinue && !isImpersonate && !isQuiet && (isOAI || isCustom); |
| 1803 | 1803 | ||
| @@ -1960,12 +1960,33 @@ async function sendOpenAIRequest(type, messages, signal) { | |||
| 1960 | generate_data['seed'] = oai_settings.seed; | 1960 | generate_data['seed'] = oai_settings.seed; |
| 1961 | } | 1961 | } |
| 1962 | 1962 | ||
| 1963 | await eventSource.emit(event_types.CHAT_COMPLETION_SETTINGS_READY, generate_data); | ||
| 1964 | |||
| 1965 | if (isFunctionCallingSupported() && !stream) { | 1963 | if (isFunctionCallingSupported() && !stream) { |
| 1966 | await registerFunctionTools(type, generate_data); | 1964 | await registerFunctionTools(type, generate_data); |
| 1967 | } | 1965 | } |
| 1968 | 1966 | ||
| 1967 | if (isOAI && oai_settings.openai_model.startsWith('o1-')) { | ||
| 1968 | generate_data.messages.forEach((msg) => { | ||
| 1969 | if (msg.role === 'system') { | ||
| 1970 | msg.role = 'user'; | ||
| 1971 | } | ||
| 1972 | }); | ||
| 1973 | delete generate_data.stream; | ||
| 1974 | delete generate_data.logprobs; | ||
| 1975 | delete generate_data.top_logprobs; | ||
| 1976 | delete generate_data.n; | ||
| 1977 | delete generate_data.temperature; | ||
| 1978 | delete generate_data.top_p; | ||
| 1979 | delete generate_data.frequency_penalty; | ||
| 1980 | delete generate_data.presence_penalty; | ||
| 1981 | delete generate_data.tools; | ||
| 1982 | delete generate_data.tool_choice; | ||
| 1983 | // IDK if it supports it and I have no way to test it | ||
| 1984 | // delete generate_data.logit_bias; | ||
| 1985 | // delete generate_data.stop; | ||
| 1986 | } | ||
| 1987 | |||
| 1988 | await eventSource.emit(event_types.CHAT_COMPLETION_SETTINGS_READY, generate_data); | ||
| 1989 | |||
| 1969 | const generate_url = '/api/backends/chat-completions/generate'; | 1990 | const generate_url = '/api/backends/chat-completions/generate'; |
| 1970 | const response = await fetch(generate_url, { | 1991 | const response = await fetch(generate_url, { |
| 1971 | method: 'POST', | 1992 | method: 'POST', |
| @@ -3905,6 +3926,9 @@ function getMaxContextOpenAI(value) { | |||
| 3905 | if (oai_settings.max_context_unlocked) { | 3926 | if (oai_settings.max_context_unlocked) { |
| 3906 | return unlocked_max; | 3927 | return unlocked_max; |
| 3907 | } | 3928 | } |
| 3929 | else if (value.startsWith('o1-')) { | ||
| 3930 | return max_128k; | ||
| 3931 | } | ||
| 3908 | else if (value.includes('chatgpt-4o-latest') || value.includes('gpt-4-turbo') || value.includes('gpt-4o') || value.includes('gpt-4-1106') || value.includes('gpt-4-0125') || value.includes('gpt-4-vision')) { | 3932 | else if (value.includes('chatgpt-4o-latest') || value.includes('gpt-4-turbo') || value.includes('gpt-4o') || value.includes('gpt-4-1106') || value.includes('gpt-4-0125') || value.includes('gpt-4-vision')) { |
| 3909 | return max_128k; | 3933 | return max_128k; |
| 3910 | } | 3934 | } |
| @@ -350,6 +350,10 @@ function getWebTokenizersChunks(tokenizer, ids) { | |||
| 350 | * @returns {string} Tokenizer model to use | 350 | * @returns {string} Tokenizer model to use |
| 351 | */ | 351 | */ |
| 352 | function getTokenizerModel(requestModel) { | 352 | function getTokenizerModel(requestModel) { |
| 353 | if (requestModel.includes('o1-preview') || requestModel.includes('o1-mini')) { | ||
| 354 | return 'gpt-4o'; | ||
| 355 | } | ||
| 356 | |||
| 353 | if (requestModel.includes('gpt-4o')) { | 357 | if (requestModel.includes('gpt-4o')) { |
| 354 | return 'gpt-4o'; | 358 | return 'gpt-4o'; |
| 355 | } | 359 | } |