Migrate from template to prompt arg while keeping backward compatibility (#1066)

This commit is contained in:
Sidharth Mohanty
2023-12-28 23:36:33 +05:30
committed by GitHub
parent 12e6eaf802
commit d9d529987e
9 changed files with 56 additions and 42 deletions

View File

@@ -76,4 +76,4 @@ class TestJsonSerializable(unittest.TestCase):
config = BaseLlmConfig(template=Template("My custom template with $query, $context and $history."))
s = config.serialize()
new_config: BaseLlmConfig = BaseLlmConfig.deserialize(s)
self.assertEqual(config.template.template, new_config.template.template)
self.assertEqual(config.prompt.template, new_config.prompt.template)

View File

@@ -25,7 +25,7 @@ def test_is_stream_bool():
def test_template_string_gets_converted_to_Template_instance():
config = BaseLlmConfig(template="test value $query $context")
llm = BaseLlm(config=config)
assert isinstance(llm.config.template, Template)
assert isinstance(llm.config.prompt, Template)
def test_is_get_llm_model_answer_implemented():

View File

@@ -53,7 +53,7 @@ class TestGeneratePrompt(unittest.TestCase):
result = self.app.llm.generate_prompt(input_query, contexts)
# Assert
expected_result = config.template.substitute(context="Context 1 | Context 2 | Context 3", query=input_query)
expected_result = config.prompt.substitute(context="Context 1 | Context 2 | Context 3", query=input_query)
self.assertEqual(result, expected_result)
def test_generate_prompt_with_history(self):
@@ -61,7 +61,7 @@ class TestGeneratePrompt(unittest.TestCase):
Test the 'generate_prompt' method with BaseLlmConfig containing a history attribute.
"""
config = BaseLlmConfig()
config.template = Template("Context: $context | Query: $query | History: $history")
config.prompt = Template("Context: $context | Query: $query | History: $history")
self.app.llm.config = config
self.app.llm.set_history(["Past context 1", "Past context 2"])
prompt = self.app.llm.generate_prompt("Test query", ["Test context"])