From ca19a1dfc5b4d3c5623b80c4480f551533bc125d Mon Sep 17 00:00:00 2001 From: JessicaXYWang <108437381+JessicaXYWang@users.noreply.github.com> Date: Tue, 28 Nov 2023 11:31:55 -0800 Subject: [PATCH 1/7] update openai completion, testing --- .../openai/OpenAIChatCompletionSuite.scala | 93 ++++++++++++++++++- .../openai/OpenAICompletionSuite.scala | 6 +- .../synapse/ml/io/http/HTTPTransformer.scala | 2 +- .../microsoft/azure/synapse/ml/Secrets.scala | 2 +- 4 files changed, 97 insertions(+), 6 deletions(-) diff --git a/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletionSuite.scala b/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletionSuite.scala index dc5e679819..e1739ceff8 100644 --- a/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletionSuite.scala +++ b/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletionSuite.scala @@ -16,9 +16,11 @@ class OpenAIChatCompletionSuite extends TransformerFuzzing[OpenAIChatCompletion] lazy val completion: OpenAIChatCompletion = new OpenAIChatCompletion() .setDeploymentName(deploymentName) .setCustomServiceName(openAIServiceName) - .setMaxTokens(200) + .setApiVersion("2023-05-15") + .setMaxTokens(5000) .setOutputCol("out") .setMessagesCol("messages") + .setTemperature(0) .setSubscriptionKey(openAIAPIKey) @@ -48,8 +50,97 @@ class OpenAIChatCompletionSuite extends TransformerFuzzing[OpenAIChatCompletion] null //scalastyle:ignore null ).toDF("messages") + lazy val slowDf: DataFrame = Seq( + Seq( + OpenAIMessage("system", "You help summarize content"), + OpenAIMessage("user", + """ + Given the following list of Article and their descriptions: + Article ID: 13d98f40-517a-4c95-bd84-27df6ea6a2a1 + Article Description: Pride and Prejudice + Article ID: 6a8a8c95-ef38-4e7b-99b4-81756f602c36 + Article Description: Romeo and Juliet + Article ID: 4b7b3c82-6c3e-45cf-9f6b-982a45f1dbad + Article Description: Calculus Made Easy + Article ID: 8f9d1f15-1aef-4a35-8301-ec8aa869f7b3 + Article Description: Moby Dick; Or, The Whale + Article ID: 2d8a6e74-7b58-4a63-bc8d-3f5e90ab5b19 + Article Description: The Scarlet Letter + Article ID: f8c0cfea-42e6-49e2-9f67-dc5ea20197c5 + Article Description: A Christmas Carol in Prose + Article ID: 1a743f5b-98b3-43b5-b27e-9f631e7c625e + Article Description: Alice's Adventures in Wonderland + Article ID: 649da1a1-4df4-41e8-b4c2-943d8d1c47b7 + Article Description: The Eyes Have It + Article ID: d35b7e0b-6fc5-4bf5-9d27-96d4894950b9 + Article Description: Dracula + Article ID: a32faffd-d3f3-4f79-b9a6-47c1f6f8e299 + Article Description: The Great Gatsby + Article ID: 9ea09862-0e44-4a58-81c1-c3449c7644c0 + Article Description: A Doll's House : a play + Article ID: 3a6f64b8-3aa4-4f6e-bc6c-7df16ff0ce28 + Article Description: The Picture of Dorian Gray + Article ID: 815b62c6-4c5f-43a1-844c-65d73a32162a + Article Description: A Modest Proposal + Article ID: d8e51b1a-1ea8-4a71-8ea3-ff4a2b2a00cf + Article Description: The Importance of Being Earnest: A Trivial Comedy for Serious People + Article ID: 682cfd7c-4a6e-4c87-88ae-9a2e7a61bf6b + Article Description: Metamorphosis + Article ID: 9a26b5c7-7438-45f3-b9da-8fc7ef3dd84c + Article Description: The Complete Works of William Shakespeare + Article ID: 6b2e7e26-2540-4a3a-810c-7d72fc4ec2cf + Article Description: The Strange Case of Dr. Jekyll and Mr. Hyde + Article ID: f7112843-719d-4a20-81a2-8767d7a18f15 + Article Description: Middlemarch + Article ID: b25e40b0-5634-48da-b4fc-15dbbb3a20db + Article Description: A Room with a View + Article ID: a13b5f45-8cf2-4f16-8edf-751b3b4b29b8 + Article Description: A Tale of Two Cities + Article ID: c8c34f96-b2c4-4dab-8d6d-b042e8c9031f + Article Description: The Yellow Wallpaper + Article ID: 45d8d855-e129-4c10-8690-34d5fbcff2d9 + Article Description: Little Women; Or, Meg, Jo, Beth, and Amy + Article ID: 9a887890-1c48-4be0-b796-c542bfb7f3db + Article Description: The Adventures of Sherlock Holmes + Article ID: f26c78da-1e57-4d5e-a7dd-42e64d90f804 + Article Description: Jane Eyre: An Autobiography + Article ID: b1d14760-1c6d-4b91-b58c-48a907f891b3 + Article Description: Great Expectations + Article ID: 57396190-8a5d-4a2b-90ab-9c3bc02e7fb6 + Article Description: The Enchanted April + Article ID: 704132cb-0bf4-46de-8b04-2d8c2ad4a409 + Article Description: Adventures of Huckleberry Finn + Article ID: bcf666b2-803b-45a2-a36b-38a8f5641e20 + Article Description: The Blue Castle: a novel + Article ID: 0c13bf68-7d10-4a02-8d1a-24290b623db4 + Article Description: The Prince + Article ID: e13d8a92-7152-4c0c-8e45-1ff6485e3f92 + Article Description: Cranford + Classify the articles into one of the article classes listed below: + Fantasy, Historical Fiction, Thriller, Romance, Science Fiction, + Mystery, Poetry, Drama, Classics, Humor, Religion, Philosophy, Psychology, Business, Other + For each article, please ensure that you do the following: + Ignore the numbers in the description. + Provide a rating between 0 and 10 of how confident you are with the classification + as well as a short justification. + Please provide your response in pure JSON syntax for all articles in the list as shown below + [ + {"article_id": value, + "article_name": value, + "article_class": value, + "article_description": value, + "confidence": value, + "justification": value + } + ] + Please do not include any other contextual words + other than proper JSON object for each article.""".stripMargin) + ) + ).toDF("messages") + test("Basic Usage") { testCompletion(completion, goodDf) + testCompletion(completion, slowDf) } test("Robustness to bad inputs") { diff --git a/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletionSuite.scala b/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletionSuite.scala index 9d33d0c124..11282b2f8b 100644 --- a/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletionSuite.scala +++ b/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletionSuite.scala @@ -13,9 +13,9 @@ import org.scalactic.Equality trait OpenAIAPIKey { lazy val openAIAPIKey: String = sys.env.getOrElse("OPENAI_API_KEY", Secrets.OpenAIApiKey) - lazy val openAIServiceName: String = "synapseml-openai" - lazy val deploymentName: String = "gpt-35-turbo" - lazy val modelName: String = "gpt-35-turbo" + lazy val openAIServiceName: String = "synapseml-openai-2" + lazy val deploymentName: String = "gpt-4" + lazy val modelName: String = "gpt-4" } class OpenAICompletionSuite extends TransformerFuzzing[OpenAICompletion] with OpenAIAPIKey with Flaky { diff --git a/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala b/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala index 40dc67dc54..374adef166 100644 --- a/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala +++ b/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala @@ -74,7 +74,7 @@ trait ConcurrencyParams extends Wrappable { case None => clear(concurrentTimeout) } - setDefault(concurrency -> 1, timeout -> 60.0) + setDefault(concurrency -> 1, timeout -> 360.0) } diff --git a/core/src/test/scala/com/microsoft/azure/synapse/ml/Secrets.scala b/core/src/test/scala/com/microsoft/azure/synapse/ml/Secrets.scala index 9ede008c58..e011cee40d 100644 --- a/core/src/test/scala/com/microsoft/azure/synapse/ml/Secrets.scala +++ b/core/src/test/scala/com/microsoft/azure/synapse/ml/Secrets.scala @@ -48,7 +48,7 @@ object Secrets { } lazy val CognitiveApiKey: String = getSecret("cognitive-api-key") - lazy val OpenAIApiKey: String = getSecret("openai-api-key") + lazy val OpenAIApiKey: String = getSecret("openai-api-key-2") lazy val CustomSpeechApiKey: String = getSecret("custom-speech-api-key") lazy val ConversationTranscriptionUrl: String = getSecret("conversation-transcription-url") From 6bafe02f80c736d87dd4e16d8f0bf131c206fe00 Mon Sep 17 00:00:00 2001 From: JessicaXYWang <108437381+JessicaXYWang@users.noreply.github.com> Date: Tue, 28 Nov 2023 13:54:42 -0800 Subject: [PATCH 2/7] update auth --- .../ml/services/openai/OpenAIChatCompletionSuite.scala | 6 +++--- .../ml/services/openai/OpenAICompletionSuite.scala | 10 +++++++--- .../scala/com/microsoft/azure/synapse/ml/Secrets.scala | 3 ++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletionSuite.scala b/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletionSuite.scala index e1739ceff8..4516ebcbea 100644 --- a/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletionSuite.scala +++ b/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletionSuite.scala @@ -14,14 +14,14 @@ class OpenAIChatCompletionSuite extends TransformerFuzzing[OpenAIChatCompletion] import spark.implicits._ lazy val completion: OpenAIChatCompletion = new OpenAIChatCompletion() - .setDeploymentName(deploymentName) - .setCustomServiceName(openAIServiceName) + .setDeploymentName(deploymentNameGpt4) + .setCustomServiceName(openAIServiceNameGpt4) .setApiVersion("2023-05-15") .setMaxTokens(5000) .setOutputCol("out") .setMessagesCol("messages") .setTemperature(0) - .setSubscriptionKey(openAIAPIKey) + .setSubscriptionKey(openAIAPIKeyGpt4) lazy val goodDf: DataFrame = Seq( diff --git a/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletionSuite.scala b/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletionSuite.scala index 11282b2f8b..b0ac7a0857 100644 --- a/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletionSuite.scala +++ b/cognitive/src/test/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletionSuite.scala @@ -13,9 +13,13 @@ import org.scalactic.Equality trait OpenAIAPIKey { lazy val openAIAPIKey: String = sys.env.getOrElse("OPENAI_API_KEY", Secrets.OpenAIApiKey) - lazy val openAIServiceName: String = "synapseml-openai-2" - lazy val deploymentName: String = "gpt-4" - lazy val modelName: String = "gpt-4" + lazy val openAIServiceName: String = "synapseml-openai" + lazy val deploymentName: String = "gpt-35-turbo" + lazy val modelName: String = "gpt-35-turbo" + lazy val openAIAPIKeyGpt4: String = sys.env.getOrElse("OPENAI_API_KEY_2", Secrets.OpenAIApiKeyGpt4) + lazy val openAIServiceNameGpt4: String = "synapseml-openai-2" + lazy val deploymentNameGpt4: String = "gpt-4" + lazy val modelNameGpt4: String = "gpt-4" } class OpenAICompletionSuite extends TransformerFuzzing[OpenAICompletion] with OpenAIAPIKey with Flaky { diff --git a/core/src/test/scala/com/microsoft/azure/synapse/ml/Secrets.scala b/core/src/test/scala/com/microsoft/azure/synapse/ml/Secrets.scala index e011cee40d..3c36e2233c 100644 --- a/core/src/test/scala/com/microsoft/azure/synapse/ml/Secrets.scala +++ b/core/src/test/scala/com/microsoft/azure/synapse/ml/Secrets.scala @@ -48,7 +48,8 @@ object Secrets { } lazy val CognitiveApiKey: String = getSecret("cognitive-api-key") - lazy val OpenAIApiKey: String = getSecret("openai-api-key-2") + lazy val OpenAIApiKey: String = getSecret("openai-api-key") + lazy val OpenAIApiKeyGpt4: String = getSecret("openai-api-key-2") lazy val CustomSpeechApiKey: String = getSecret("custom-speech-api-key") lazy val ConversationTranscriptionUrl: String = getSecret("conversation-transcription-url") From d339da62481764ba54aac647b09c062d6ddfd949 Mon Sep 17 00:00:00 2001 From: JessicaXYWang <108437381+JessicaXYWang@users.noreply.github.com> Date: Tue, 28 Nov 2023 15:06:53 -0800 Subject: [PATCH 3/7] false positive synapse e2e --- docs/Explore Algorithms/OpenAI/OpenAI.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/Explore Algorithms/OpenAI/OpenAI.ipynb b/docs/Explore Algorithms/OpenAI/OpenAI.ipynb index c51b3c912a..98041351d5 100644 --- a/docs/Explore Algorithms/OpenAI/OpenAI.ipynb +++ b/docs/Explore Algorithms/OpenAI/OpenAI.ipynb @@ -76,6 +76,7 @@ "outputs": [], "source": [ "from synapse.ml.core.platform import find_secret\n", + "from synapse.ml.core.platform import materializing_display as display # please remove this line to run on your own notebook\n", "\n", "# Fill in the following lines with your service information\n", "# Learn more about selecting which embedding model to choose: https://openai.com/blog/new-and-improved-embedding-model\n", From 5d13792b22605c08a612e685fa4d0eaadf62a429 Mon Sep 17 00:00:00 2001 From: JessicaXYWang <108437381+JessicaXYWang@users.noreply.github.com> Date: Mon, 4 Dec 2023 14:43:44 -0800 Subject: [PATCH 4/7] fix setTimeout --- .../azure/synapse/ml/services/CognitiveServiceBase.scala | 1 + .../synapse/ml/services/openai/OpenAIChatCompletion.scala | 2 ++ .../microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala | 4 +--- .../azure/synapse/ml/io/http/SimpleHTTPTransformer.scala | 1 + docs/Explore Algorithms/OpenAI/OpenAI.ipynb | 1 - 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/CognitiveServiceBase.scala b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/CognitiveServiceBase.scala index 6d286ce023..d297a7d75e 100644 --- a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/CognitiveServiceBase.scala +++ b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/CognitiveServiceBase.scala @@ -537,6 +537,7 @@ abstract class CognitiveServicesBaseNoHandler(val uid: String) extends Transform .setHandler(handlingFunc _) .setConcurrency(getConcurrency) .setConcurrentTimeout(get(concurrentTimeout)) + .setTimeout(getTimeout) .setErrorCol(getErrorCol), new DropColumns().setCol(dynamicParamColName) ) diff --git a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletion.scala b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletion.scala index 5957ffab5c..44cd742bfb 100644 --- a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletion.scala +++ b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletion.scala @@ -25,6 +25,8 @@ class OpenAIChatCompletion(override val uid: String) extends CognitiveServicesBa with HasInternalJsonOutputParser with SynapseMLLogging { logClass(FeatureNames.AiServices.OpenAI) + setDefault(timeout -> 360.0) + val messagesCol: Param[String] = new Param[String]( this, "messagesCol", "The column messages to generate chat completions for," + " in the chat format. This column should have type Array(Struct(role: String, content: String)).") diff --git a/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala b/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala index 374adef166..8d942e34b1 100644 --- a/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala +++ b/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala @@ -73,9 +73,7 @@ trait ConcurrencyParams extends Wrappable { case Some(v) => setConcurrentTimeout(v) case None => clear(concurrentTimeout) } - - setDefault(concurrency -> 1, timeout -> 360.0) - + setDefault(concurrency -> 1, timeout -> 60.0) } trait HasURL extends Params { diff --git a/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/SimpleHTTPTransformer.scala b/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/SimpleHTTPTransformer.scala index 2e2d7472eb..c7248a73fd 100644 --- a/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/SimpleHTTPTransformer.scala +++ b/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/SimpleHTTPTransformer.scala @@ -128,6 +128,7 @@ class SimpleHTTPTransformer(val uid: String) .setHandler(getHandler) .setConcurrency(getConcurrency) .setConcurrentTimeout(get(concurrentTimeout)) + .setTimeout(getTimeout) .setInputCol(parsedInputCol) .setOutputCol(unparsedOutputCol)) diff --git a/docs/Explore Algorithms/OpenAI/OpenAI.ipynb b/docs/Explore Algorithms/OpenAI/OpenAI.ipynb index 98041351d5..c51b3c912a 100644 --- a/docs/Explore Algorithms/OpenAI/OpenAI.ipynb +++ b/docs/Explore Algorithms/OpenAI/OpenAI.ipynb @@ -76,7 +76,6 @@ "outputs": [], "source": [ "from synapse.ml.core.platform import find_secret\n", - "from synapse.ml.core.platform import materializing_display as display # please remove this line to run on your own notebook\n", "\n", "# Fill in the following lines with your service information\n", "# Learn more about selecting which embedding model to choose: https://openai.com/blog/new-and-improved-embedding-model\n", From a86c03f507d1018ade7b10a7f72267a970c7b6bc Mon Sep 17 00:00:00 2001 From: JessicaXYWang <108437381+JessicaXYWang@users.noreply.github.com> Date: Mon, 4 Dec 2023 16:18:24 -0800 Subject: [PATCH 5/7] update OpenAI endpoints' default timeout --- .../azure/synapse/ml/services/openai/OpenAICompletion.scala | 2 ++ .../azure/synapse/ml/services/openai/OpenAIEmbedding.scala | 2 ++ .../azure/synapse/ml/services/openai/OpenAIPrompt.scala | 2 ++ 3 files changed, 6 insertions(+) diff --git a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletion.scala b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletion.scala index bcf8ab7e4d..8205afcb91 100644 --- a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletion.scala +++ b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletion.scala @@ -24,6 +24,8 @@ class OpenAICompletion(override val uid: String) extends CognitiveServicesBase(u with HasInternalJsonOutputParser with SynapseMLLogging { logClass(FeatureNames.AiServices.OpenAI) + setDefault(timeout -> 360.0) + def this() = this(Identifiable.randomUID("OpenAICompletion")) def urlPath: String = "" diff --git a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIEmbedding.scala b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIEmbedding.scala index 6da890843d..2d79c6a5b5 100644 --- a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIEmbedding.scala +++ b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIEmbedding.scala @@ -26,6 +26,8 @@ class OpenAIEmbedding (override val uid: String) extends CognitiveServicesBase(u with HasOpenAISharedParams with HasCognitiveServiceInput with SynapseMLLogging { logClass(FeatureNames.AiServices.OpenAI) + setDefault(timeout -> 360.0) + def this() = this(Identifiable.randomUID("OpenAIEmbedding")) def urlPath: String = "" diff --git a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIPrompt.scala b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIPrompt.scala index 5fafa6e554..39374badd0 100644 --- a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIPrompt.scala +++ b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIPrompt.scala @@ -26,6 +26,8 @@ class OpenAIPrompt(override val uid: String) extends Transformer with HasSubscriptionKey with HasAADToken with HasCustomAuthHeader with ComplexParamsWritable with SynapseMLLogging { + setDefault(timeout -> 360.0) + logClass(FeatureNames.AiServices.OpenAI) def this() = this(Identifiable.randomUID("OpenAIPrompt")) From 9d2a813c84e0ff866b18a0d8d154c5ddc758f6bd Mon Sep 17 00:00:00 2001 From: JessicaXYWang <108437381+JessicaXYWang@users.noreply.github.com> Date: Mon, 4 Dec 2023 16:47:11 -0800 Subject: [PATCH 6/7] update openai setTimeout --- .../microsoft/azure/synapse/ml/services/openai/OpenAI.scala | 5 ++++- .../synapse/ml/services/openai/OpenAIChatCompletion.scala | 4 +--- .../azure/synapse/ml/services/openai/OpenAICompletion.scala | 4 +--- .../azure/synapse/ml/services/openai/OpenAIEmbedding.scala | 4 +--- .../azure/synapse/ml/services/openai/OpenAIPrompt.scala | 5 ++--- .../microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala | 2 ++ 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAI.scala b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAI.scala index 2319f7b7d0..32c146ff9c 100644 --- a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAI.scala +++ b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAI.scala @@ -4,7 +4,7 @@ package com.microsoft.azure.synapse.ml.services.openai import com.microsoft.azure.synapse.ml.codegen.GenerationUtils -import com.microsoft.azure.synapse.ml.services.{HasAPIVersion, HasServiceParams} +import com.microsoft.azure.synapse.ml.services.{CognitiveServicesBase, HasAPIVersion, HasServiceParams} import com.microsoft.azure.synapse.ml.param.ServiceParam import org.apache.spark.sql.Row import spray.json.DefaultJsonProtocol._ @@ -244,3 +244,6 @@ trait HasOpenAITextParams extends HasOpenAISharedParams { } } +abstract class OpenAIServicesBase(override val uid: String) extends CognitiveServicesBase(uid: String) { + setDefault(timeout -> 360.0) +} \ No newline at end of file diff --git a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletion.scala b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletion.scala index 44cd742bfb..0b9fbd275c 100644 --- a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletion.scala +++ b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIChatCompletion.scala @@ -20,13 +20,11 @@ import scala.language.existentials object OpenAIChatCompletion extends ComplexParamsReadable[OpenAIChatCompletion] -class OpenAIChatCompletion(override val uid: String) extends CognitiveServicesBase(uid) +class OpenAIChatCompletion(override val uid: String) extends OpenAIServicesBase(uid) with HasOpenAITextParams with HasCognitiveServiceInput with HasInternalJsonOutputParser with SynapseMLLogging { logClass(FeatureNames.AiServices.OpenAI) - setDefault(timeout -> 360.0) - val messagesCol: Param[String] = new Param[String]( this, "messagesCol", "The column messages to generate chat completions for," + " in the chat format. This column should have type Array(Struct(role: String, content: String)).") diff --git a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletion.scala b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletion.scala index 8205afcb91..c44a950a80 100644 --- a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletion.scala +++ b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAICompletion.scala @@ -19,13 +19,11 @@ import scala.language.existentials object OpenAICompletion extends ComplexParamsReadable[OpenAICompletion] -class OpenAICompletion(override val uid: String) extends CognitiveServicesBase(uid) +class OpenAICompletion(override val uid: String) extends OpenAIServicesBase(uid) with HasOpenAITextParams with HasPromptInputs with HasCognitiveServiceInput with HasInternalJsonOutputParser with SynapseMLLogging { logClass(FeatureNames.AiServices.OpenAI) - setDefault(timeout -> 360.0) - def this() = this(Identifiable.randomUID("OpenAICompletion")) def urlPath: String = "" diff --git a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIEmbedding.scala b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIEmbedding.scala index 2d79c6a5b5..baab35a151 100644 --- a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIEmbedding.scala +++ b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIEmbedding.scala @@ -22,12 +22,10 @@ import scala.language.existentials object OpenAIEmbedding extends ComplexParamsReadable[OpenAIEmbedding] -class OpenAIEmbedding (override val uid: String) extends CognitiveServicesBase(uid) +class OpenAIEmbedding (override val uid: String) extends OpenAIServicesBase(uid) with HasOpenAISharedParams with HasCognitiveServiceInput with SynapseMLLogging { logClass(FeatureNames.AiServices.OpenAI) - setDefault(timeout -> 360.0) - def this() = this(Identifiable.randomUID("OpenAIEmbedding")) def urlPath: String = "" diff --git a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIPrompt.scala b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIPrompt.scala index 39374badd0..52661a4e70 100644 --- a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIPrompt.scala +++ b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAIPrompt.scala @@ -26,8 +26,6 @@ class OpenAIPrompt(override val uid: String) extends Transformer with HasSubscriptionKey with HasAADToken with HasCustomAuthHeader with ComplexParamsWritable with SynapseMLLogging { - setDefault(timeout -> 360.0) - logClass(FeatureNames.AiServices.OpenAI) def this() = this(Identifiable.randomUID("OpenAIPrompt")) @@ -75,7 +73,8 @@ class OpenAIPrompt(override val uid: String) extends Transformer postProcessingOptions -> Map.empty, outputCol -> (this.uid + "_output"), errorCol -> (this.uid + "_error"), - dropPrompt -> true + dropPrompt -> true, + timeout -> 360.0 ) override def setCustomServiceName(v: String): this.type = { diff --git a/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala b/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala index 8d942e34b1..60699c4287 100644 --- a/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala +++ b/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala @@ -73,7 +73,9 @@ trait ConcurrencyParams extends Wrappable { case Some(v) => setConcurrentTimeout(v) case None => clear(concurrentTimeout) } + setDefault(concurrency -> 1, timeout -> 60.0) + } trait HasURL extends Params { From 7c095fb75f157566dfe402c3aab52152c6b3a637 Mon Sep 17 00:00:00 2001 From: JessicaXYWang <108437381+JessicaXYWang@users.noreply.github.com> Date: Mon, 4 Dec 2023 17:03:50 -0800 Subject: [PATCH 7/7] fix style --- .../com/microsoft/azure/synapse/ml/services/openai/OpenAI.scala | 2 +- .../microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAI.scala b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAI.scala index 32c146ff9c..ac0e08beaf 100644 --- a/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAI.scala +++ b/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/services/openai/OpenAI.scala @@ -246,4 +246,4 @@ trait HasOpenAITextParams extends HasOpenAISharedParams { abstract class OpenAIServicesBase(override val uid: String) extends CognitiveServicesBase(uid: String) { setDefault(timeout -> 360.0) -} \ No newline at end of file +} diff --git a/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala b/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala index 60699c4287..8d942e34b1 100644 --- a/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala +++ b/core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPTransformer.scala @@ -73,9 +73,7 @@ trait ConcurrencyParams extends Wrappable { case Some(v) => setConcurrentTimeout(v) case None => clear(concurrentTimeout) } - setDefault(concurrency -> 1, timeout -> 60.0) - } trait HasURL extends Params {