-
Notifications
You must be signed in to change notification settings - Fork 837
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
add check fabric setting #2163
add check fabric setting #2163
Conversation
// Tenant setting status check by model name ("GPT-4", "gpt-35-turbo") | ||
// eg: FabricTenant.getModelStatus("GPT-4") | ||
// returnType: Boolean | ||
|
||
// Part of the code are scala implementation of | ||
// synapse.ml.internal_utils.session_utils | ||
// synapse.ml.fabric.token_utils | ||
// synapse.ml.mlflow.synapse_mlflow_utils | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this docstring in the class, use the official header to pass the stylecheck
object StringifiedJsonProtocol extends DefaultJsonProtocol { | ||
implicit object StringifiedMapFormat extends RootJsonFormat[Map[String, String]] { | ||
def write(map: Map[String, String]): JsValue = { | ||
JsObject(map.mapValues(JsString(_))) | ||
} | ||
|
||
def read(value: JsValue): Map[String, String] = value.asJsObject.fields.map { | ||
case (key, JsString(str)) => key -> str | ||
case (key, other) => key -> other.toString | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import spray.json.DefaultProtocol._
def readJsonFileAsMap(filePath: String): Try[Map[String, String]] = { | ||
Try { | ||
val fileContent = Source.fromFile(filePath).getLines.mkString | ||
fileContent.parseJson.convertTo[Map[String, String]]//.asJsObject.fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reminder to remove comment
val pbiEnv = sc.getConf.get("spark.trident.pbienv").toLowerCase | ||
val tokenServiceEndpoint = sc.hadoopConfiguration.get("trident.lakehouse.tokenservice.endpoint") | ||
val capacityId = sc.hadoopConfiguration.get("trident.capacity.id") | ||
val workspaceId = sc.hadoopConfiguration.get("trident.artifact.workspace.id") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make these lazy vals instead of vals
|
||
class FabricToken { | ||
|
||
def readJsonFileAsMap(filePath: String): Try[Map[String, String]] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make everytthing private or private[ml] unless you want people to call it
final val CONTEXT_FILE_PATH = "/home/trusted-service-user/.trident-context" | ||
final val TOKEN_PATH = "/opt/token-service/tokenservice.config.json" | ||
final val TRIDENT_LAKEHOUSE_TOKEN_SERVICE_ENDPOINT = "trident.lakehouse.tokenservice.endpoint" | ||
final val TRIDENT_SESSION_TOKEN = "trident.session.token" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit on Style: no camelcase in scala, you can just use the regular naming case (with a capital first letter because its an object
val host = TargetUrl.map(_.getHost).get | ||
val path = TargetUrl.map(_.getPath).get | ||
|
||
def getAADToekn(): String = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: typo here Token
} | ||
} | ||
|
||
object FabricTenant extends FabricToken { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Factor out common code shared by this and logging infra
httpGet.setHeader("Authorization", s"Bearer ${aadToken}") | ||
val client = HttpClients.createDefault() | ||
val response = client.execute(httpGet) | ||
val entity = response.getEntity | ||
val content = EntityUtils.toString(entity) | ||
val jsonData = content.parseJson.convertTo[Map[String, String]] | ||
response.close() | ||
client.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace with the safe HTTP calls like in other code
val httpPost = new HttpPost(url) | ||
httpPost.setHeader("Content-type", "application/json") | ||
httpPost.setHeader("Authorization", s"Bearer ${aadToken}") | ||
|
||
val payload = s"""{"capacityObjectId": "${Configs.capacityId}", "workspaceObjectId": "${Configs.workspaceId}", "workloadType": "${MWC_WORKLOAD_TYPE_ML}"}"""" | ||
httpPost.setEntity(new StringEntity(payload, "UTF-8")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anytime you make a post you can use existing utility function
val client = HttpClients.createDefault() | ||
val url = getMLFlowWorkloadEndpoint + "cognitive/openai/tenantsetting" | ||
val httpPost = new HttpPost(url) | ||
httpPost.setHeader("Content-type", "application/json") | ||
httpPost.setHeader("Authorization", s"Bearer ${aadToken}") | ||
httpPost.setEntity(new StringEntity(jsonString)) | ||
|
||
val response = client.execute(httpPost) | ||
val responseString = EntityUtils.toString(response.getEntity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use utility function
val responseField = responseString.parseJson.asJsObject.fields.get(modelName.toLowerCase).get | ||
val resultString: String = responseField match { | ||
case JsString(value) => value // Directly extract the string value | ||
} | ||
// Allowed, Disallowed, DisallowedForCrossGeo, ModelNotFound, InvalidResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think theres a simpler 1-liner for this
mlflowWorkloadEndpoint | ||
} | ||
|
||
def getModelStatus(modelName: String): Boolean = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
def assertModelReady(modelName): Unit = {
.....
throw new IllegalArgumentException("Useful error message about the status and a link to the URL on how to set up the model endpoint stuff")
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Tenant setting status check by model name ("GPT-4", "gpt-35-turbo")
eg: FabricTenant.getModelStatus("GPT-4")
returnType: Boolean
Part of the code are scala implementation of
synapse.ml.internal_utils.session_utils
synapse.ml.fabric.token_utils
synapse.ml.mlflow.synapse_mlflow_utils