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

add check fabric setting #2163

Closed

Conversation

JessicaXYWang
Copy link
Contributor

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

@JessicaXYWang JessicaXYWang marked this pull request as draft February 5, 2024 16:37
Comment on lines +1 to +9
// 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

Copy link
Collaborator

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

Comment on lines +25 to +36
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
}
}
}
Copy link
Collaborator

@mhamilton723 mhamilton723 Feb 5, 2024

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder to remove comment

Comment on lines +46 to +49
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")
Copy link
Collaborator

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]] = {
Copy link
Collaborator

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

Comment on lines +39 to +42
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"
Copy link
Collaborator

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 = {
Copy link
Collaborator

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 {
Copy link
Collaborator

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

Comment on lines +144 to +151
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()
Copy link
Collaborator

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

Comment on lines +159 to +164
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"))
Copy link
Collaborator

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

Comment on lines +187 to +195
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use utility function

Comment on lines +199 to +203
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
Copy link
Collaborator

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 = {
Copy link
Collaborator

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")

@JessicaXYWang
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@JessicaXYWang JessicaXYWang deleted the checkFabricTenantSetting branch March 19, 2024 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants