Skip to content

Commit

Permalink
Use only kwargs in format_messages
Browse files Browse the repository at this point in the history
  • Loading branch information
desaxce committed Apr 26, 2024
1 parent f440ae1 commit ee2165c
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions literalai/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,14 @@ def from_dict(cls, api: "LiteralAPI", prompt_dict: PromptDict) -> "Prompt":
type=prompt_dict.get("type", GenerationType.CHAT),
version_desc=prompt_dict.get("versionDesc"),
template_messages=prompt_dict.get("templateMessages", []),
tools=prompt_dict.get("tools", []),
tools=prompt_dict.get("tools", []) or [],
provider=provider,
settings=settings,
variables=prompt_dict.get("variables", []),
variables_default_values=prompt_dict.get("variablesDefaultValues"),
)

def format_messages(
self, variables: Optional[Dict[str, Any]] = None, **kwargs: Any
) -> List[Any]:
def format_messages(self, **kwargs: Any) -> List[Any]:
"""
Formats the prompt's template messages with the given variables.
Variables may be passed as a dictionary or as keyword arguments.
Expand All @@ -137,8 +135,7 @@ def format_messages(
"""
variables_with_defaults = {
**(self.variables_default_values or {}),
**(variables or {}),
**kwargs,
**(kwargs or {}),
}
formatted_messages = []

Expand All @@ -162,10 +159,8 @@ def format_messages(
return formatted_messages

@deprecated('Please use "format_messages" instead')
def format(
self, variables: Optional[Dict[str, Any]] = None
) -> List[Any]:
return self.format_messages(variables)
def format(self, variables: Optional[Dict[str, Any]] = None) -> List[Any]:
return self.format_messages(**(variables or {}))

def to_langchain_chat_prompt_template(self):
try:
Expand Down

0 comments on commit ee2165c

Please sign in to comment.