Skip to content

Commit

Permalink
remove supports_function_calling and add format instructions in that …
Browse files Browse the repository at this point in the history
…case
  • Loading branch information
FelixTJDietrich committed Oct 11, 2024
1 parent 75ea90f commit 31c6e4a
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions llm_core/llm_core/utils/llm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,6 @@ def check_prompt_length_and_omit_features_if_necessary(prompt: ChatPromptTemplat
return prompt_input, False


def supports_function_calling(model: BaseLanguageModel):
"""Returns True if the model supports function calling, False otherwise
Args:
model (BaseLanguageModel): The model to check
Returns:
boolean: True if the model supports function calling, False otherwise
"""
return isinstance(model, ChatOpenAI)


def get_chat_prompt_with_formatting_instructions(
model: BaseLanguageModel,
system_message: str,
Expand All @@ -97,14 +85,9 @@ def get_chat_prompt_with_formatting_instructions(
Returns:
ChatPromptTemplate: ChatPromptTemplate with formatting instructions (if necessary)
"""
if supports_function_calling(model):
system_message_prompt = SystemMessagePromptTemplate.from_template(system_message)
human_message_prompt = HumanMessagePromptTemplate.from_template(human_message)
return ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])

output_parser = PydanticOutputParser(pydantic_object=pydantic_object)
system_message_prompt = SystemMessagePromptTemplate.from_template(system_message + "\n{format_instructions}")
system_message_prompt = SystemMessagePromptTemplate.from_template(system_message + "\n\n{format_instructions}")
system_message_prompt.prompt.partial_variables = {"format_instructions": output_parser.get_format_instructions()}
system_message_prompt.prompt.input_variables.remove("format_instructions")
human_message_prompt = HumanMessagePromptTemplate.from_template(human_message + "\n\nJSON response following the provided schema:")
human_message_prompt = HumanMessagePromptTemplate.from_template(human_message)
return ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])

0 comments on commit 31c6e4a

Please sign in to comment.