-
Notifications
You must be signed in to change notification settings - Fork 45
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
Conversation
@@ -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)})) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@@ -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)})) |
There was a problem hiding this comment.
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.
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.