Thanks to visit codestin.com
Credit goes to github.com

Skip to content

No public description #5076

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 10 additions & 5 deletions vertexai/evaluation/prompt_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ def assemble(self, **kwargs) -> "PromptTemplate":
Returns:
A new PromptTemplate instance with the updated template string.
"""
replaced_values = {
key: kwargs.get(key, "{" + key + "}") for key in self.variables
}
new_template = self.template.format(**replaced_values)
return PromptTemplate(new_template)
assembled_string = self.template
for variable_name, value in kwargs.items():
if variable_name not in self.variables:
raise ValueError(
f"Invalid variable name '{variable_name}'. "
f"Valid variables are: {self.variables}"
)
placeholder = "{" + variable_name + "}"
assembled_string = assembled_string.replace(placeholder, str(value))
return PromptTemplate(assembled_string)

def __str__(self) -> str:
"""Returns the template string."""
Expand Down
15 changes: 10 additions & 5 deletions vertexai/preview/evaluation/prompt_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ def assemble(self, **kwargs) -> "PromptTemplate":
Returns:
A new PromptTemplate instance with the updated template string.
"""
replaced_values = {
key: kwargs.get(key, "{" + key + "}") for key in self.variables
}
new_template = self.template.format(**replaced_values)
return PromptTemplate(new_template)
assembled_string = self.template
for variable_name, value in kwargs.items():
if variable_name not in self.variables:
raise ValueError(
f"Invalid variable name '{variable_name}'. "
f"Valid variables are: {self.variables}"
)
placeholder = "{" + variable_name + "}"
assembled_string = assembled_string.replace(placeholder, str(value))
return PromptTemplate(assembled_string)

def __str__(self) -> str:
"""Returns the template string."""
Expand Down