@@ -25,14 +25,15 @@ public static readonly Dictionary<string, Func<string, CancellationToken, Task<s
2525 { "OpenAI" , OpenAI } ,
2626 { "DeepL" , DeepL } ,
2727 { "OpenRouter" , OpenRouter } ,
28+ { "IOIntelligence" , IOIntelligence } ,
2829 { "Youdao" , Youdao } ,
2930 { "MTranServer" , MTranServer } ,
3031 { "Baidu" , Baidu } ,
3132 { "LibreTranslate" , LibreTranslate } ,
3233 } ;
3334 public static readonly List < string > LLM_BASED_APIS = new ( )
3435 {
35- "Ollama" , "OpenAI" , "OpenRouter"
36+ "Ollama" , "OpenAI" , "OpenRouter" , "IOIntelligence"
3637 } ;
3738 public static readonly List < string > NO_CONFIG_APIS = new ( )
3839 {
@@ -258,6 +259,73 @@ public static async Task<string> OpenRouter(string text, CancellationToken token
258259 return $ "[ERROR] Translation Failed: HTTP Error - { response . StatusCode } ";
259260 }
260261
262+ public static async Task < string > IOIntelligence ( string text , CancellationToken token = default )
263+ {
264+ var config = Translator . Setting [ "IOIntelligence" ] as IOIntelligenceConfig ;
265+ string language = IOIntelligenceConfig . SupportedLanguages . TryGetValue (
266+ Translator . Setting . TargetLanguage , out var langValue ) ? langValue : Translator . Setting . TargetLanguage ;
267+ string apiUrl = "https://api.intelligence.io.solutions/api/v1/chat/completions" ;
268+
269+ var messages = new List < BaseLLMConfig . Message >
270+ {
271+ new BaseLLMConfig . Message { role = "system" , content = string . Format ( Prompt , language ) } ,
272+ new BaseLLMConfig . Message { role = "user" , content = $ "🔤 { text } 🔤" }
273+ } ;
274+
275+ if ( Translator . Setting . ContextAware )
276+ {
277+ foreach ( var entry in Translator . Caption . AwareContexts )
278+ {
279+ string translatedText = entry . TranslatedText ;
280+ if ( translatedText . Contains ( "[ERROR]" ) || translatedText . Contains ( "[WARNING]" ) )
281+ continue ;
282+ translatedText = RegexPatterns . NoticePrefix ( ) . Replace ( translatedText , "" ) ;
283+
284+ messages . InsertRange ( 1 , [
285+ new BaseLLMConfig . Message { role = "user" , content = $ "🔤 { entry . SourceText } 🔤" } ,
286+ new BaseLLMConfig . Message { role = "assistant" , content = $ "{ translatedText } " }
287+ ] ) ;
288+ }
289+ }
290+
291+ var requestData = LLMRequestDataFactory . Create ( "IOIntelligence" , config . ModelName , messages , config . Temperature ) ;
292+
293+ string jsonContent = JsonSerializer . Serialize ( requestData , requestData . GetType ( ) ) ;
294+ var content = new StringContent ( jsonContent , Encoding . UTF8 , "application/json" ) ;
295+ client . DefaultRequestHeaders . Clear ( ) ;
296+ client . DefaultRequestHeaders . Add ( "Authorization" , $ "Bearer { config ? . ApiKey } ") ;
297+
298+ HttpResponseMessage response ;
299+ try
300+ {
301+ response = await client . PostAsync ( apiUrl , content , token ) ;
302+ }
303+ catch ( OperationCanceledException ex )
304+ {
305+ if ( ex . Message . StartsWith ( "The request" ) )
306+ return $ "[ERROR] Translation Failed: The request was canceled due to timeout (> 8 seconds), " +
307+ $ "please use a faster API or check network connection.";
308+ throw ;
309+ }
310+ catch ( Exception ex )
311+ {
312+ return $ "[ERROR] Translation Failed: { ex . Message } ";
313+ }
314+
315+ if ( response . IsSuccessStatusCode )
316+ {
317+ var responseContent = await response . Content . ReadAsStringAsync ( ) ;
318+ var jsonResponse = JsonSerializer . Deserialize < JsonElement > ( responseContent ) ;
319+ var output = jsonResponse . GetProperty ( "choices" ) [ 0 ]
320+ . GetProperty ( "message" )
321+ . GetProperty ( "content" )
322+ . GetString ( ) ?? string . Empty ;
323+ return RegexPatterns . ModelThinking ( ) . Replace ( output , "" ) ;
324+ }
325+ else
326+ return $ "[ERROR] Translation Failed: HTTP Error - { response . StatusCode } ";
327+ }
328+
261329 public static async Task < string > Google ( string text , CancellationToken token = default )
262330 {
263331 var language = Translator . Setting ? . TargetLanguage ;
0 commit comments