Skip to content

Commit

Permalink
fix: fix prompt builder
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrump committed Nov 1, 2024
1 parent 4336533 commit c9b70e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/crllm/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def generate(self, prompt_template, prompt_args):
if config["rag"]["enabled"]:
self.add_rag_context(prompt_args, rag_config)

logging.debug(
prompt_template.format(
context=prompt_args["context"], code=prompt_args["code"]
logging.debug(
prompt_template.format(
context=prompt_args["context"], code=prompt_args["code"]
)
)
)

result = chain.invoke(prompt_args)

Expand Down
30 changes: 18 additions & 12 deletions src/crllm/prompt_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@ def build(self):

logging.debug(config["prompt"])

prompt = ChatPromptTemplate.from_messages(
[
("system", config["prompt"]["template"]),
(
"system",
"""
messages = [
("system", config["prompt"]["template"]),
("human", "Do code review for the following code changes: \n {code}"),
]

if config["rag"]["enabled"]:
self._insert_rag_message(messages)

return ChatPromptTemplate.from_messages(messages)

def _insert_rag_message(self, messages):
messages.insert(
1,
(
"system",
"""
This code could be relevant to understand the changes:
<context>
{context}
</context>
""",
),
("human", "Do code review for the following code changes: \n {code}"),
]
""",
),
)

return prompt

0 comments on commit c9b70e4

Please sign in to comment.