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

OpenAIDefaults to enable global parameter setting with the OpenAI objects #2331

Closed
wants to merge 11 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -277,25 +277,22 @@ trait HasOpenAITextParams extends HasOpenAISharedParams {

def setBestOfCol(v: String): this.type = setVectorParam(bestOf, v)

// list of shared text parameters. In method getOptionalParams, we will iterate over these parameters
// to compute the optional parameters. Since this list never changes, we can create it once and reuse it.
private val sharedTextParams = Seq(
maxTokens,
temperature,
topP,
user,
n,
echo,
stop,
cacheLevel,
presencePenalty,
frequencyPenalty,
bestOf,
logProbs
)

private[ml] def getOptionalParams(r: Row): Map[String, Any] = {
sharedTextParams.flatMap { param =>
// list of shared text parameters. we iterate over these parameters to compute the optional parameters.
Seq(
maxTokens,
temperature,
topP,
user,
n,
echo,
stop,
cacheLevel,
presencePenalty,
frequencyPenalty,
bestOf,
logProbs
).flatMap { param =>
getValueOpt(r, param).map { value => param.payloadName -> value }
}.toMap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class OpenAIPrompt(override val uid: String) extends Transformer
}
// apply all parameters
extractParamMap().toSeq
.filter(p => !localParamNames.contains(p.param.name))
.filter(p => !localParamNames.contains(p.param.name) && completion.hasParam(p.param.name))
.foreach(p => completion.set(completion.getParam(p.param.name), p.value))

completion
Expand Down
Loading