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: Make setCustomHeaders compatible with Pyspark #2247

Merged
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 @@ -198,6 +198,12 @@ trait HasCustomHeaders extends HasServiceParams {
setScalarParam(customHeaders, v)
}

// For Pyspark compatability accept Java HashMap as input to parameter
// py4J only natively supports conversions from Python Dict to Java HashMap
def setCustomHeaders(v: java.util.HashMap[String,String]): this.type = {
setCustomHeaders(v.asScala.toMap)
}

def getCustomHeaders: Map[String, String] = getScalarParam(customHeaders)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class OpenAIChatCompletionSuite extends TransformerFuzzing[OpenAIChatCompletion]
ignore("Custom EndPoint") {
lazy val accessToken: String = sys.env.getOrElse("CUSTOM_ACCESS_TOKEN", "")
lazy val customRootUrlValue: String = sys.env.getOrElse("CUSTOM_ROOT_URL", "")
lazy val customHeadersValues: Map[String, String] = Map("X-ModelType" -> "gpt-4-turbo-chat-completions")

val customEndpointCompletion = new OpenAIChatCompletion()
.setCustomUrlRoot(customRootUrlValue)
Expand All @@ -167,8 +168,7 @@ class OpenAIChatCompletionSuite extends TransformerFuzzing[OpenAIChatCompletion]
.setCustomServiceName(openAIServiceName)
} else {
customEndpointCompletion.setAADToken(accessToken)
.setCustomHeaders(Map("X-ModelType" -> "gpt-4-turbo-chat-completions",
"X-ScenarioGUID" -> "7687c733-45b0-425b-82b3-05eb4eb70247"))
.setCustomHeaders(customHeadersValues)
}

testCompletion(customEndpointCompletion, goodDf)
Expand Down