Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update ContentComposer to work well with json #42

Merged
merged 3 commits into from
Oct 18, 2023

Conversation

keerthanvasist
Copy link
Member

Description of changes:
update ContentComposer to work well with json

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@@ -37,7 +37,7 @@ def compose(self, prompt: str) -> Dict:
# prompts: ['["John",40]']
# result: '{"data":["John",40],"names":["Name","Age"]}'
try:
return json.loads(Composer.compose(self, prompt))
return json.loads(self.vanilla_template.substitute(**{self.keyword: json.dumps(prompt)}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do Composer.compose(self, json.dumps(prompt)) instead? that keeps the substitution logic at one place.

Copy link
Contributor

@malhotra18 malhotra18 Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment too, with example, or update example in docstring, it's not that intuitive looking at the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prompt template does not require this update - prompt doesn't have to escape. Only content composer has to escape. I will add some comments.

Copy link
Contributor

@malhotra18 malhotra18 Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i did not understand your point. Below is what happens in Composer.compose:
self.vanilla_template.substitute(**{self.keyword: prompt})

Earlier code in JSONContentComposer:
json.loads(Composer.compose(self, prompt))

Your code is basically just using json.dumps(prompt) instead of prompt, which can be solved by below instead:
return json.loads(Composer.compose(self, json.dumps(prompt))) in compose method here. Why not do it this way? Keeps the core substitution logic common. Am i missing anything here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a unit test of the specific case that was failing earlier? i don't see any update in UT suite.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay updated. Unit tests were updated but probably it's not clear because python allow use of single quotes too. Maybe now it is more clear.

@malhotra18 malhotra18 self-requested a review October 18, 2023 06:38
@@ -37,7 +37,7 @@ def compose(self, prompt: str) -> Dict:
# prompts: ['["John",40]']
# result: '{"data":["John",40],"names":["Name","Age"]}'
try:
return json.loads(Composer.compose(self, prompt))
return json.loads(self.vanilla_template.substitute(**{self.keyword: json.dumps(prompt)}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a unit test of the specific case that was failing earlier? i don't see any update in UT suite.

@keerthanvasist keerthanvasist merged commit 2270e97 into aws:main Oct 18, 2023
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants