-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* check Fabric Tenant * update check fabric setting * add missing import * fix style * clean up * clean unused import * fix typo * add doc link in error message * add doc link in error message
- Loading branch information
1 parent
b390fd4
commit ce5cc5c
Showing
2 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
core/src/main/scala/com/microsoft/azure/synapse/ml/fabric/OpenAIFabricSetting.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (C) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in project root for information. | ||
|
||
package com.microsoft.azure.synapse.ml.fabric | ||
|
||
import spray.json.{JsValue, JsString} | ||
|
||
trait OpenAIFabricSetting extends RESTUtils { | ||
|
||
private def getHeaders: Map[String, String] = { | ||
Map( | ||
"Authorization" -> s"Bearer ${TokenLibrary.getAccessToken}", | ||
"Content-Type" -> "application/json" | ||
) | ||
} | ||
|
||
def usagePost(url: String, body: String): JsValue = { | ||
usagePost(url, body, getHeaders); | ||
} | ||
|
||
def getModelStatus(modelName: String): Boolean = { | ||
|
||
val payload = | ||
s"""["${modelName}"]""" | ||
|
||
val mlWorkloadEndpointML = FabricClient.MLWorkloadEndpointML | ||
val url = mlWorkloadEndpointML + "cognitive/openai/tenantsetting" | ||
val modelStatus = usagePost(url, payload).asJsObject.fields.get(modelName.toLowerCase).get | ||
|
||
// Allowed, Disallowed, DisallowedForCrossGeo, ModelNotFound, InvalidResult | ||
val resultString: String = modelStatus match { | ||
case JsString(value) => value | ||
case _ => throw new RuntimeException("Unexpected result from type conversion " + | ||
"when checking the fabric tenant settings API.") | ||
} | ||
|
||
resultString match { | ||
case "Disallowed" => throw new RuntimeException(s"Default OpenAI model ${modelName} is Disallowed, " + | ||
s"please contact your admin if you want to use default fabric LLM model. " + | ||
s"Or you can set your Azure OpenAI credentials.") | ||
case "DisallowedForCrossGeo" => throw new RuntimeException(s"Default OpenAI model ${modelName} is Disallowed " + | ||
s"for Cross Geo, please contact your admin if you want to use default fabric LLM model. " + | ||
s"Or you can set your Azure OpenAI credentials." + | ||
s"Refer to https://learn.microsoft.com/en-us/fabric/data-science/ai-services/ai-services-overview " + | ||
s"for more detials") | ||
case "ModelNotFound" => throw new RuntimeException(s"Default OpenAI model ${modelName} not found, " + | ||
s"please check your deployment name. " + | ||
s"Refer to https://learn.microsoft.com/en-us/fabric/data-science/ai-services/ai-services-overview " + | ||
s"for the models available.") | ||
case "InvalidResult" => throw new RuntimeException("Cannot get tenant admin setting status correctly") | ||
case "Allowed" => true | ||
case _ => throw new RuntimeException("Unexpected result from checking the Fabric tenant settings API.") | ||
} | ||
} | ||
|
||
} |