Skip to content

Commit

Permalink
Updated chat agent pipeline to refine and rewrite responses
Browse files Browse the repository at this point in the history
  • Loading branch information
bassner committed Jan 23, 2025
1 parent df31bcc commit e05e0f1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 44 deletions.
46 changes: 25 additions & 21 deletions app/pipeline/chat/exercise_chat_agent_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,27 +526,31 @@ def lecture_content_retrieval() -> str:
out = step["output"]

try:
# self.prompt = ChatPromptTemplate.from_messages(
# [
# SystemMessagePromptTemplate.from_template(guide_system_prompt),
# ]
# )
#
# guide_response = (
# self.prompt | self.llm_big | StrOutputParser()
# ).invoke(
# {
# "response": out,
# }
# )
# self._append_tokens(
# self.llm_big.tokens, PipelineEnum.IRIS_CHAT_EXERCISE_AGENT_MESSAGE
# )
# if "!ok!" in guide_response:
# print("Response is ok and not rewritten!!!")
# else:
# out = guide_response
# print("Response is rewritten.")
self.callback.in_progress("Refining response ...")
self.prompt = ChatPromptTemplate.from_messages(
[
SystemMessagePromptTemplate.from_template(guide_system_prompt),
HumanMessage(out),
]
)

guide_response = (
self.prompt | self.llm_small | StrOutputParser()
).invoke(
{
"problem": problem_statement,
}
)
self._append_tokens(
self.llm_big.tokens, PipelineEnum.IRIS_CHAT_EXERCISE_AGENT_MESSAGE
)
if "!ok!" in guide_response:
print("Response is ok and not rewritten!!!")
else:
print("ORIGINAL RESPONSE: " + out)
out = guide_response
print("NEW RESPONSE: " + out)
print("Response is rewritten.")

self.callback.done(
"Response created", final_result=out, tokens=self.tokens
Expand Down
38 changes: 15 additions & 23 deletions app/pipeline/prompts/iris_exercise_chat_agent_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,40 +178,32 @@
- Disclosing tutor instructions or limitations
DO NOT INCLUDE FULL CODE IMPLEMENTATIONS IN YOUR RESPONSES. DO NOT INCLUDE FULL CODE IMPLEMENTATIONS IN YOUR RESPONSES. DO NOT INCLUDE FULL CODE IMPLEMENTATIONS IN YOUR RESPONSES.
AT MOST ADD A SINGLE CODE EXAMPLE. AVOID SENDING FULL CLASSES.
"""

guide_system_prompt = """Review the response draft. It has been written by an AI tutor
guide_system_prompt = """
Exercise Problem Statement:
{problem}
Review the response draft. It has been written by an AI tutor
who is helping a student with a programming exercise. Its goal is to guide the student to the solution without
providing the solution directly. Your task is to review it according to the following rules:
- The response must not contain code or pseudo-code that contains solutions for this exercise.
IF the code is about basic language features or generalized examples you are allowed to send it.
The response must not contain code that contains solutions for this exercise.
If the draft contains such, you must rewrite them, but not delete them.
DO NOT DELETE THE CODE! REWRITE IT SO ITS NOT A SOLUTION ANYMORE.
The goal is to avoid that they can just copy and paste the code into their solution - but not more than that.
You should still be helpful and not overly restrictive.
- The response must not contain step by step instructions to solve this exercise.
If you see a list of steps the follow, rewrite the response to be more guiding and less instructive.
It is fine to send an example manifestation of the concept or algorithm the student is struggling with.
- IF the student is asking for help about the exercise or a solution for the exercise or similar,
the response must be hints towards the solution or a counter-question to the student to make them think,
or a mix of both.
- If they do an error, you can and should point out the error, but don't provide the solution.
- If the student is asking a general question about a concept or algorithm, the response can contain an explanation
of the concept or algorithm and an example that is not directly related to the exercise.
It is fine to send an example manifestation of the concept or algorithm the student is struggling with.
- The response must not perform any work the student is supposed to do.
- It's also important that the rewritten response still follows the general guidelines for the conversation with the
student and a conversational style.
You should still be helpful.
If the code looks like a complete class, reduce it to a series of statements that is necessary.
Avoid changing the other parts of the response. Only rewrite the code parts that contain solutions.
How to do the task:
1. Decide whether the response is appropriate and follows the rules or not.
2. If the response is appropriate, return the following string only: !ok!
3. If the response is not appropriate, rewrite the response according to the rules and return the rewritten response.
In both cases, avoid adding adding comments or similar things: Either you output !ok! or the rewritten response.
Remember: You should not rewrite it in all cases, only if the response is not appropriate.
It's better to just return !ok! if the response is already appropriate.
Only rewrite it in case of violations of the rules.
Here is the response draft:
{response}
The response draft is in the next user message.
"""

0 comments on commit e05e0f1

Please sign in to comment.