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
privateasyncTaskStratTranslate(){List<Task>tasks=newList<Task>();varsemaphore=newSemaphoreSlim(int.Parse(Data.MaxTaskCount));// 50foreach(vardiffExcelindiffExcelHandlerList)// need to translate{varlanguageStr=LanguageHelp.GetLangugeStrByEnum(diffExcel.languageType);foreach(varcellClsindiffExcel.translateCellCls_List){tasks.Add(TranslateTextAsyncWithCell(cellCls,languageStr,semaphore));}}awaitTask.WhenAll(tasks);}privateasyncTaskTranslateTextAsyncWithCell(TranslateExcelCellClscellCls,stringtranslateLanguageType,SemaphoreSlimsemaphore){try{awaitsemaphore.WaitAsync();stringtranslatedText=awaitopenAIAPINetReq.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=awaitapi.Chat.CreateChatCompletionAsync(newChatRequest(){Model=Model.GPT4_Turbo,Temperature=0.7,//MaxTokens = 50,Messages=newChatMessage[]{newChatMessage(ChatMessageRole.System,Configure.GetSystemPrompTranslateTextStr(translateType)),newChatMessage(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}日:Typicallyeach socket address (protocol/network address/port)isonlyallowed to be used once (api.openai.com:443)[17:31:20]Errortranslating3月{0}日:Typicallyeach socket address (protocol/network address/port)isonlyallowed to be used once (api.openai.com:443)[17:31:20]Errortranslating4月{0}日:Typicallyeach socket address (protocol/network address/port)isonlyallowed 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: