-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fix DialogFlow tests and update to canonical sample format. #1210
Conversation
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.
We won't be accepting changes to ML API docs samples which remove the output response information, it's critical to the user's docs experience.
We can't accept this change.
More context on @Beccca 's response: The issue is with deleting the The issue I wanted to resolve in this change was making the functions actually return something other than void, for 2 reasons:
|
dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentKnowledge.java
Outdated
Show resolved
Hide resolved
ffc98db
to
259c6c3
Compare
Updated to return the |
*/ | ||
public static void listContexts(String sessionId, String projectId) throws Exception { | ||
public static List<Context> listContexts(String sessionId, String projectId) throws Exception { | ||
List<Context> contexts = Lists.newArrayList(); |
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 think if we are aiming for the new format, the context tags need to be moved inside of the function and examples of the arguments need to be provided in comments to give the user additional context:
public static List<Context> listContexts(String sessionId, String projectId) throws Exception {
// [START dialogflow_list_contexts]
// String sessionId = "my-session-id"
// String projectId = "my-project-id"
List<Context> contexts = Lists.newArrayList();
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.
What's your take on the return statement being inside vs outside the tags?
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'd say leave the return outside.
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 think that sounds reasonable.
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.
From the perspective of having these regions be copy-pastable by developers, though, I would think the function tag and return statement would be useful so that they could just plop the function into their code directly. They would basically have to write a function wrapper around the code anyway regardless
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 see what you are saying, but I think the presumption is that they can copy paste the code into an existing code and get it working. Even if they copy the function as a whole they still have to create a class around it, so I don't think including the function signature really make's a significant impact.
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.
hey every keystroke counts :)
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 feel we should make sure this gets decided in the new rubric. (To have a solid answer going forward)
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.
Agreed. I'd prefer to leave it as-is for now though for consistency.
@@ -104,48 +101,14 @@ public static void detectIntentKnowledge( | |||
System.out.format(" - Answer: '%s'\n", answer.getAnswer()); | |||
System.out.format(" - Confidence: '%s'\n", answer.getMatchConfidence()); | |||
} | |||
|
|||
allKnowledgeAnswers.add(Tuple.of(text, sessionsClient |
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.
Another suggestion on the new sample guidelines is to explicitly define variables ahead of time, and avoid multiple nesting in function calls.
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.
Updated to break out nested calls.
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 had submitted a Request changes
– after chatting & agreeing that the println statements would return, I'm 'Approving' to remove the request!
Thanks for all of the thought that went into these changes to improve our code sample experience for developers 🙏
=> @nnegrey for full approval from our end
a440107
to
a588ef6
Compare
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.
Mostly nit to match the naming to the API naming
dialogflow/cloud-client/src/test/java/com/example/dialogflow/KnowledgeBaseManagementIT.java
Outdated
Show resolved
Hide resolved
dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentKnowledge.java
Outdated
Show resolved
Hide resolved
dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentKnowledge.java
Outdated
Show resolved
Hide resolved
dialogflow/cloud-client/src/main/java/com/example/dialogflow/DocumentManagement.java
Outdated
Show resolved
Hide resolved
dialogflow/cloud-client/src/main/java/com/example/dialogflow/DocumentManagement.java
Outdated
Show resolved
Hide resolved
dialogflow/cloud-client/src/main/java/com/example/dialogflow/DocumentManagement.java
Outdated
Show resolved
Hide resolved
dialogflow/cloud-client/src/main/java/com/example/dialogflow/DocumentManagement.java
Outdated
Show resolved
Hide resolved
dialogflow/cloud-client/src/main/java/com/example/dialogflow/KnowledgeBaseManagement.java
Outdated
Show resolved
Hide resolved
dialogflow/cloud-client/src/main/java/com/example/dialogflow/KnowledgeBaseManagement.java
Outdated
Show resolved
Hide resolved
dialogflow/cloud-client/src/test/java/com/example/dialogflow/KnowledgeBaseManagementIT.java
Outdated
Show resolved
Hide resolved
Hi all, I'm having an issue with this that I'm not sure I should report to the DialogFlow team directly as an actual bug found by the Unit Tests. For the tests in KnowledgeBaseManagementIT, particularly the testIntentKnowledge, it creates a KnowledgeBase based on the Storage Docs FAQ. The test question used to be "Where is my data stored?", which is the second question in the Storage section. Half the time, it was interpreting that as "Is my data redundant?", the first question in that section. When I changed the test text to "Is my data redundant?", it always succeeded locally, but now it's having the same problem run with kokoro where it thinks the question is the other one half the time. This seems like a potential API problem though, since the input text is an exact match for one of the questions. Should I file a bug with the team, or just make the test more forgiving? |
I'd start by reaching out to DF team and see if something changed on the backend, this sounds like an API bug. |
Created bug b/115888589, but there was no automatic assignee so I'll forward it to the dialogflow team to make sure they see it. |
dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentKnowledge.java
Outdated
Show resolved
Hide resolved
assertThat(answer.getAnswer()).contains("Cloud Storage"); | ||
} | ||
} |
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 cleanup the resources (remove the knowledge base) after the test.
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.
This is done in the @After tearDown()
method above, line 77.
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.
LGTM
Thanks Dane!
ping ~ what's the status of this? looks like we've got LGTMs :) |
Ah, thanks for the ping, I missed the LGTM. I will update the branch and submit. |
DialogFlow tests are failing, and while fixing them I ran into many issues with the tests simply parsing the
stdout
content to verify things were working as intended.With canonical samples, we are no longer formatting the samples as commandline executables, and instead of writing to
stdout
, we are returning the requested information directly, as that is more likely to be what users are looking for anyway. So I updated the DF samples to do so, and the tests to match.