Skip to content

Commit

Permalink
Addressed single quote json key problems.
Browse files Browse the repository at this point in the history
  • Loading branch information
yghokim committed Mar 14, 2024
1 parent 36cb8c4 commit 74cbca8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 44 deletions.
9 changes: 4 additions & 5 deletions libs/py_core/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 9 additions & 14 deletions libs/py_core/py_core/system/task/card_recommendation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,22 @@ def __init__(self):

@staticmethod
def __prompt_generator(input: Dialogue, params: ChildCardRecommendationParams) -> str:
prompt = f"""
prompt = """
- You are a helpful assistant that serves as an Alternative Augmented Communication tool.
- Suppose that you are helping a communication with a child and parents in Korean. The autistic child has the language proficiency of a 6 to 8-year-old in Korean, so recommendations should consider their cognitive level.
- Given the last message of the parents, suggest a list of keywords that can help the child pick to create a sentence as an answer.
- Use honorific form of Korean for actions and emotions, such as "~해요" or "~어요", if possible.
Proceed in the following order.
1. [nouns] : Provide nouns that reflect detailed context based on your parents' questions.
2. [actions] : Provide words for the action that can be matched with the nouns suggested in [nouns].
3. [emotions] : Suggest emotions that the child might want to express in the situation, including both positive and negative emotions and needs.
Return a JSON object organizing the keywords as in the following:
{
"nouns": Array<string> // Nouns that reflect detailed context based on your parents' questions.
"actions": Array<string> // Actions that can be matched with the nouns suggested in [nouns].
"emotions": Array<string> // Emotions that the child might want to express in the situation, including both positive and negative emotions and needs.
}"""f"""
{"" if params.prev_recommendation is None else "- The child had previous recommendation: " + params.prev_recommendation.json() + ". Try to generate phrases that are distinct to this previous recommendation."}
{"" if params.interim_cards is None else "- The child had selected the following cards: " + ', '.join([card.simple_str() for card in params.interim_cards]) + ". The generated recommendation should be relevant to these selections."}
Note that the output must be JSON, formatted like the following:
"nouns": Array<string>
"actions: Array<string>
"emotions": Array<string>
The result should be in Korean and please provide up to four options for each element.
{"" if params.interim_cards is None else "- The child had selected the following cards: " + ', '.join([card.text for card in params.interim_cards]) + ". The generated recommendation should be relevant to these selections."}
- Provide up to five options for each category.
"""
return prompt

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __prompt_generator(input: Dialogue, params: ParentGuideRecommendationParams)
Return a JSON object in the following format:
{
recommendations: Array<{
"recommendations": Array<{
"example": Provide response or question that parents can make to the child's message.
"guide": Provide guide for parents of autistic children to consider when responding to the child's answer. Keep the guide short and concise so parents can read it quickly and move on.
}>
Expand Down
2 changes: 1 addition & 1 deletion libs/py_core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ readme = 'README.md'
[tool.poetry.dependencies]
python = ">=3.11.8,<3.12"
pendulum = "^3.0.0"
chatlib = {git = "https://github.com/yghokim/chatlib.git", tag="0.7.2"}
chatlib = {git = "https://github.com/yghokim/chatlib.git", tag="0.7.3"}
pydantic = "^2.6.4"
questionary = "^2.0.1"

Expand Down
23 changes: 0 additions & 23 deletions libs/py_core/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,6 @@

from py_core.system.task.parent_guide_recommendation import ParentGuideRecommendationGenerator


async def test_processor():
child_card_recommender = ChildCardRecommendationGenerator()

card_recommendation_result = await child_card_recommender.generate(
[DialogueMessage(speaker=DialogueRole.Parent, content="할머니 댁 가는 거 알지? 할머니네 가면 뭐 하고 싶니?")],
[CardInfo(text="물놀이", category="noun"), CardInfo(text="가고싶어요", category="noun")], None)

print("==Child card recommendation=========")
print(card_recommendation_result.model_dump_json(indent=2))

parent_guide_recommender = ParentGuideRecommendationGenerator()

parent_guide_recommendation = await parent_guide_recommender.generate([
DialogueMessage(speaker=DialogueRole.Parent, content="할머니 댁 가는 거 알지? 할머니네 가면 뭐 하고 싶니?"),
DialogueMessage(speaker=DialogueRole.Child,
content=[CardInfo(text="수영", category="noun"), CardInfo(text="할아버지", category="noun")])
], )

print("==Parent guide recommendation=========")
print(parent_guide_recommendation.model_dump_json(indent=2))


async def test_session_loop(session: ModeratorSession):
current_card_recommendation_result: ChildCardRecommendationResult | None = None
current_parent_guide_recommendation_result: ParentGuideRecommendationResult | None = None
Expand Down

0 comments on commit 74cbca8

Please sign in to comment.