Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix translator endpoint and update all endpoints for gov regions #1623

Merged
merged 3 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ trait HasSetLinkedServiceUsingLocation extends HasSetLinkedService with HasSetLo
}
}

trait HasSetLocation extends Wrappable with HasURL with HasUrlPath {
trait HasSetLocation extends Wrappable with HasURL with HasUrlPath with DomainHelper {
override def pyAdditionalMethods: String = super.pyAdditionalMethods + {
"""
|def setLocation(self, value):
Expand All @@ -298,8 +298,24 @@ trait HasSetLocation extends Wrappable with HasURL with HasUrlPath {
|""".stripMargin
}


def setLocation(v: String): this.type = {
setUrl(s"https://$v.api.cognitive.microsoft.com/" + urlPath)
val domain = getLocationDomain(v)
setUrl(s"https://$v.api.cognitive.microsoft.$domain/" + urlPath)
}
}

trait DomainHelper {

protected def getLocationDomain(location: String): String = {
val usGovRegions = Array("usgovarizona", "usgovvirginia")
val cnVianet = Array("chinaeast2", "chinanorth")
val domain = location match {
case v if usGovRegions.contains(v) => "us"
case v if cnVianet.contains(v) => "cn"
case _ => "com"
}
domain
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ object DocumentTranslator extends ComplexParamsReadable[DocumentTranslator]

class DocumentTranslator(override val uid: String) extends CognitiveServicesBaseNoHandler(uid)
with HasInternalJsonOutputParser with HasCognitiveServiceInput with HasServiceName
with Wrappable with DocumentTranslatorAsyncReply with BasicLogging with HasSetLinkedService {
with Wrappable with DocumentTranslatorAsyncReply with BasicLogging with HasSetLinkedService
with DomainHelper {

import TranslatorJsonProtocol._

Expand Down Expand Up @@ -151,7 +152,8 @@ class DocumentTranslator(override val uid: String) extends CognitiveServicesBase

override def setServiceName(v: String): this.type = {
super.setServiceName(v)
setUrl(s"https://$getServiceName.cognitiveservices.azure.com/" + urlPath)
val domain = getLocationDomain(v)
setUrl(s"https://$getServiceName.cognitiveservices.azure.$domain/" + urlPath)
}

def urlPath: String = "/translator/text/batch/v1.0/batches"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ class SpeechToText(override val uid: String) extends CognitiveServicesBase(uid)

def this() = this(Identifiable.randomUID("SpeechToText"))

override def setLocation(v: String): this.type =
setUrl(s"https://$v.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1")
override def setLocation(v: String): this.type = {
val domain = getLocationDomain(v)
setUrl(s"https://$v.stt.speech.microsoft.$domain/speech/recognition/conversation/cognitiveservices/v1")
}

def urlPath: String = "/speech/recognition/conversation/cognitiveservices/v1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ abstract class TextTranslatorBase(override val uid: String) extends CognitiveSer

override def setLocation(v: String): this.type = {
setSubscriptionRegion(v)
setUrl("https://api.cognitive.microsofttranslator.com/" + urlPath)
val domain = getLocationDomain(v)
setUrl(s"https://api.cognitive.microsofttranslator.$domain/" + urlPath)
}

}
Expand Down