@@ -34,29 +34,33 @@ export default class ChatHelper {
3434 const largeContentDeduction = 1500 ;
3535
3636 let returnValue = Math . floor ( ( 4 * 1024 - responseTokens ) * averageCharsPerToken ) ;
37- if ( / 4 o / i. test ( model ) || / 4 - ( 1 1 0 6 | t u r b o | v i s i o n ) / i. test ( model ) ) {
37+ if ( / 4 o / i. test ( model ) || / 4 - ( 1 1 0 6 | t u r b o | v i s i o n ) / i. test ( model ) || / o 1 - m i n i | o 1 - p r e v i e w / i . test ( model ) ) {
3838 returnValue = Math . floor ( ( 128 * 1024 - responseTokens ) * averageCharsPerToken ) - largeContentDeduction ;
3939 } else if ( / 3 2 k / i. test ( model ) ) {
4040 returnValue = Math . floor ( ( 32 * 1024 - responseTokens ) * averageCharsPerToken ) - largeContentDeduction ;
4141 } else if ( / 1 6 k | - 1 1 0 6 / i. test ( model ) ) {
4242 returnValue = Math . floor ( ( 16 * 1024 - responseTokens ) * averageCharsPerToken ) - largeContentDeduction ;
4343 } else if ( / 8 k / i. test ( model ) || / g p t - 4 / i. test ( model ) ) {
4444 returnValue = Math . floor ( ( 8 * 1024 - responseTokens ) * averageCharsPerToken ) - largeContentDeduction ;
45+ } else if ( / o \d / i. test ( model ) ) {
46+ returnValue = Math . floor ( ( 200 * 1024 - responseTokens ) * averageCharsPerToken ) - largeContentDeduction ;
4547 }
4648 return returnValue - 200 ; // 200 extra chars reserved for service needs (redundancy).
4749 }
4850
4951 public static maxRequestLength ( model : string , responseTokens : number , chatHistoryLength : number ) : number {
5052 // maxRequestLength = max allowed number of characters in the prompt.
51- let maxCharacters = 4000 ; // GPT-35-turbo, 4k
52- if ( / 4 o / i. test ( model ) || / 4 - ( 1 1 0 6 | t u r b o | v i s i o n ) / i. test ( model ) ) {
53- maxCharacters = 125000 ; // ~ (128 * 1024 * 3.6) / 3.75 long questions - answers.
53+ let maxCharacters = 4_000 ; // GPT-35-turbo, 4k
54+ if ( / 4 o / i. test ( model ) || / 4 - ( 1 1 0 6 | t u r b o | v i s i o n ) / i. test ( model ) || / o 1 - m i n i | o 1 - p r e v i e w / i . test ( model ) ) {
55+ maxCharacters = 125_000 ; // ~ (128 * 1024 * 3.6) / 3.75 long questions - answers.
5456 } else if ( / 3 2 k / i. test ( model ) ) {
55- maxCharacters = 30000 ; // ~ (32 * 1024 * 3.6) / 3.75 long questions - answers.
57+ maxCharacters = 30_000 ; // ~ (32 * 1024 * 3.6) / 3.75 long questions - answers.
5658 } else if ( / 1 6 k | - 1 1 0 6 / i. test ( model ) ) {
57- maxCharacters = 15000 ; // ~ (16 * 1024 * 3.6) / 3.75 long questions - answers.
59+ maxCharacters = 15_000 ; // ~ (16 * 1024 * 3.6) / 3.75 long questions - answers.
5860 } else if ( / 8 k / i. test ( model ) || / g p t - 4 / i. test ( model ) ) {
59- maxCharacters = 7500 ; // ~ (8 * 1024 * 3.6) / 3.75 long questions - answers.
61+ maxCharacters = 7_500 ; // ~ (8 * 1024 * 3.6) / 3.75 long questions - answers.
62+ } else if ( / o \d / i. test ( model ) ) {
63+ maxCharacters = 195_000 ; // ~ (200 * 1024 * 3.6) / 3.75 long questions - answers.
6064 }
6165 const maxLength = this . maxContentLength ( model , responseTokens ) ;
6266 const allowedLength = maxLength - chatHistoryLength ;
@@ -74,6 +78,12 @@ export default class ChatHelper {
7478 returnValue = defaultResponseTokens ;
7579 } else if ( / 8 k / i. test ( model ) || / g p t - 4 / i. test ( model ) ) {
7680 returnValue = defaultResponseTokens ;
81+ } else if ( / o \d - m i n i / i. test ( model ) ) {
82+ returnValue = 65_536 ;
83+ } else if ( / o 1 - p r e v i e w / i. test ( model ) ) {
84+ returnValue = 32_768 ;
85+ } else if ( / o \d / i. test ( model ) ) {
86+ returnValue = 100_000 ;
7787 }
7888 return returnValue ;
7989 }
@@ -137,6 +147,21 @@ export default class ChatHelper {
137147 }
138148 }
139149
150+ public static isStreamingSupported = ( model : string , props : IAzureOpenAiChatProps ) => {
151+ // As of February 2025, the model o1-mini of Azure OpenAI did not support streaming and function calling.
152+ // - At the same time, native OpenAI models o1-mini, o3-mini, o1-preview supported streaming, but did not support function calling.
153+ // - The full-scale native OpenAI models o1 and o1-2024-12-17 did not support streaming and function calling.
154+ // On attempts to use streaming outputs, they have thrown errors. Note that this behaviour might change later.
155+ if ( / ^ o \d $ | o \d - \d { 4 } - \d { 2 } - \d { 2 } / i. test ( model ?. toLocaleLowerCase ( ) ) ) return false ;
156+
157+ return (
158+ props . streaming &&
159+ ( ! / o \d / . test ( model ) ||
160+ props . apiService ?. isNative ( props . endpointBaseUrlForOpenAi ) ||
161+ props . apiService ?. isOpenAiNativeUrl ( props . endpointBaseUrlForOpenAi ) )
162+ ) ;
163+ } ;
164+
140165 public static formatDate ( date : string | Date , locale : string ) : string {
141166 if ( typeof date === 'string' ) date = new Date ( date ) ;
142167 return new Date ( ) . getFullYear ( ) !== date . getFullYear ( )
0 commit comments