mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	Add new OpenAI models
This commit is contained in:
		| @@ -1442,10 +1442,16 @@ | ||||
|                                 <h4 data-i18n="OpenAI Model">OpenAI Model</h4> | ||||
|                                 <select id="model_openai_select"> | ||||
|                                     <option value="gpt-3.5-turbo">gpt-3.5-turbo</option> | ||||
|                                     <option value="gpt-3.5-turbo-16k">gpt-3.5-turbo-16k</option> | ||||
|                                     <option value="gpt-3.5-turbo-16k-0613">gpt-3.5-turbo-16k-0613</option> | ||||
|                                     <option value="gpt-3.5-turbo-0613">gpt-3.5-turbo-0613</option> | ||||
|                                     <option value="gpt-3.5-turbo-0301">gpt-3.5-turbo-0301</option> | ||||
|                                     <option value="gpt-4">gpt-4</option> | ||||
|                                     <option value="gpt-4-0613">gpt-4-0613</option> | ||||
|                                     <option value="gpt-4-0314">gpt-4-0314</option> | ||||
|                                     <option value="gpt-4-32k">gpt-4-32k</option> | ||||
|                                     <option value="gpt-4-32k-0301">gpt-4-32k-0301</option> | ||||
|                                     <option value="gpt-4-32k-0613">gpt-4-32k-0613</option> | ||||
|                                 </select> | ||||
|                             </div> | ||||
|                             <div> | ||||
|   | ||||
| @@ -80,6 +80,7 @@ const default_bias_presets = { | ||||
| }; | ||||
|  | ||||
| const gpt3_max = 4095; | ||||
| const gpt3_16k_max = 16383; | ||||
| const gpt4_max = 8191; | ||||
| const gpt_neox_max = 2048; | ||||
| const gpt4_32k_max = 32767; | ||||
| @@ -1540,18 +1541,22 @@ function onModelChange() { | ||||
|         if (oai_settings.max_context_unlocked) { | ||||
|             $('#openai_max_context').attr('max', unlocked_max); | ||||
|         } | ||||
|         else if (value == 'gpt-4' || value == 'gpt-4-0314') { | ||||
|         else if (value == 'gpt-4' || value == 'gpt-4-0314' || value == 'gpt-4-0613') { | ||||
|             $('#openai_max_context').attr('max', gpt4_max); | ||||
|         } | ||||
|         else if (value == 'gpt-4-32k') { | ||||
|         else if (value == 'gpt-4-32k' || value == 'gpt-4-32k-0314' || value == 'gpt-4-32k-0613') { | ||||
|             $('#openai_max_context').attr('max', gpt4_32k_max); | ||||
|         } | ||||
|         else if (value == 'gpt-3.5-turbo-16k' || value == 'gpt-3.5-turbo-16k-0613') { | ||||
|             $('#openai_max_context').attr('max', gpt3_16k_max); | ||||
|         } | ||||
|         else { | ||||
|             $('#openai_max_context').attr('max', gpt3_max); | ||||
|             oai_settings.openai_max_context = Math.max(oai_settings.openai_max_context, gpt3_max); | ||||
|             $('#openai_max_context').val(oai_settings.openai_max_context).trigger('input'); | ||||
|         } | ||||
|  | ||||
|         oai_settings.openai_max_context = Math.max(oai_settings.openai_max_context, Number($('#openai_max_context').attr('max'))); | ||||
|         $('#openai_max_context').val(oai_settings.openai_max_context).trigger('input'); | ||||
|  | ||||
|         $('#openai_reverse_proxy').attr('placeholder', 'https://api.openai.com/v1'); | ||||
|  | ||||
|         oai_settings.temp_openai = Math.min(oai_max_temp, oai_settings.temp_openai); | ||||
|   | ||||
							
								
								
									
										28
									
								
								server.js
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								server.js
									
									
									
									
									
								
							| @@ -158,6 +158,23 @@ async function countSentencepieceTokens(spp, text) { | ||||
|  | ||||
| const tokenizersCache = {}; | ||||
|  | ||||
| function getTokenizerModel(requestModel) { | ||||
|     if (requestModel.includes('gpt-4-32k')) { | ||||
|         return 'gpt-4-32k'; | ||||
|     } | ||||
|  | ||||
|     if (requestModel.includes('gpt-4')) { | ||||
|         return 'gpt-4'; | ||||
|     } | ||||
|  | ||||
|     if (requestModel.includes('gpt-3.5-turbo')) { | ||||
|         return 'gpt-3.5-turbo'; | ||||
|     } | ||||
|  | ||||
|     // default | ||||
|     return 'gpt-3.5-turbo'; | ||||
| } | ||||
|  | ||||
| function getTiktokenTokenizer(model) { | ||||
|     if (tokenizersCache[model]) { | ||||
|         return tokenizersCache[model]; | ||||
| @@ -2787,7 +2804,8 @@ app.post("/openai_bias", jsonParser, async function (request, response) { | ||||
|  | ||||
|     let result = {}; | ||||
|  | ||||
|     const tokenizer = getTiktokenTokenizer(request.query.model === 'gpt-4-0314' ? 'gpt-4' : request.query.model); | ||||
|     const model = getTokenizerModel(String(request.query.model || '')); | ||||
|     const tokenizer = getTiktokenTokenizer(model); | ||||
|  | ||||
|     for (const entry of request.body) { | ||||
|         if (!entry || !entry.text) { | ||||
| @@ -3083,11 +3101,13 @@ app.post("/generate_openai", jsonParser, function (request, response_generate_op | ||||
| app.post("/tokenize_openai", jsonParser, function (request, response_tokenize_openai = response) { | ||||
|     if (!request.body) return response_tokenize_openai.sendStatus(400); | ||||
|  | ||||
|     const tokensPerName = request.query.model.includes('gpt-4') ? 1 : -1; | ||||
|     const tokensPerMessage = request.query.model.includes('gpt-4') ? 3 : 4; | ||||
|     const model = getTokenizerModel(String(request.query.model || '')); | ||||
|  | ||||
|     const tokensPerName = model.includes('gpt-4') ? 1 : -1; | ||||
|     const tokensPerMessage = model.includes('gpt-4') ? 3 : 4; | ||||
|     const tokensPadding = 3; | ||||
|  | ||||
|     const tokenizer = getTiktokenTokenizer(request.query.model === 'gpt-4-0314' ? 'gpt-4' : request.query.model); | ||||
|     const tokenizer = getTiktokenTokenizer(model); | ||||
|  | ||||
|     let num_tokens = 0; | ||||
|     for (const msg of request.body) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user