You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, please allow me to introduce my problem. I hope someone can see it.
Problem Description
My requirement is for OpenAI to help translate Chinese into the corresponding language. Since there are multiple Chinese languages, each to be translated is a Task. I use List to add all Tasks, but I have SemaphoreSlim to control the number of concurrencies at a time. , I currently set it to 50. But after the network request, it was informed that Typically each socket address (protocol/network address/port) is only allowed to be used once. (127.0.0.1:9127)
code
privateasync Task StratTranslate(){List<Task>tasks=newList<Task>();varsemaphore=new SemaphoreSlim(int.Parse(Data.MaxTaskCount));// 50foreach(var diffExcel in diffExcelHandlerList)// need to translate{varlanguageStr= LanguageHelp.GetLangugeStrByEnum(diffExcel.languageType);foreach(var cellCls in diffExcel.translateCellCls_List){
tasks.Add(TranslateTextAsyncWithCell(cellCls, languageStr, semaphore));}}await Task.WhenAll(tasks);}privateasync Task TranslateTextAsyncWithCell(TranslateExcelCellClscellCls,stringtranslateLanguageType,SemaphoreSlimsemaphore){try{await semaphore.WaitAsync();stringtranslatedText=await openAIAPINetReq.TranslateTextNewChatAsync(cellCls.chineseText, translateLanguageType);
cellCls.openAI_translateStr =translatedText;//await Task.Delay(2000);}catch(Exceptione){stringerrorStr=$"Error {cellCls.chineseText} for cell at row {cellCls.row} and column {cellCls.chinese_Column}: {e.Message}";
Log.Error(errorStr);
cellCls.openAI_translateStr =string.Empty;}finally{
semaphore.Release();}}publicasyncTask<string>TranslateTextNewChatAsync(stringchineseStr,stringtranslateType){try{varresult=await api.Chat.CreateChatCompletionAsync(new ChatRequest(){Model= Model.GPT4_Turbo,Temperature=0.7,//MaxTokens = 50,Messages=new ChatMessage[]{new ChatMessage(ChatMessageRole.System, Configure.GetSystemPrompTranslateTextStr(translateType)),new ChatMessage(ChatMessageRole.User, chineseStr)}});varreply= result.Choices[0].Message;varresponse= reply.Content.Trim();
Log.Info($"{chineseStr} : {response}");returnresponse;}catch(Exceptione){
Log.Error($"Error translating {chineseStr}: {e.Message}");return"";}}
Error
[17:31:20] Error translating 2月{0}日: Typically each socket address (protocol/network address/port) is only allowed to be used once (api.openai.com:443)[17:31:20]Errortranslating 3月{0}日: Typically each socket address (protocol/network address/port) is only allowed to be used once (api.openai.com:443)[17:31:20]Errortranslating 4月{0}日: Typically each socket address (protocol/network address/port) is only allowed to be used once (api.openai.com:443)
The text was updated successfully, but these errors were encountered:
Hello, please allow me to introduce my problem. I hope someone can see it.
Problem Description
My requirement is for OpenAI to help translate Chinese into the corresponding language. Since there are multiple Chinese languages, each to be translated is a Task. I use List to add all Tasks, but I have SemaphoreSlim to control the number of concurrencies at a time. , I currently set it to 50. But after the network request, it was informed that
Typically each socket address (protocol/network address/port) is only allowed to be used once. (127.0.0.1:9127)
code
Error
The text was updated successfully, but these errors were encountered: