Skip to content

[2201.12.x] Fix issues in AI tool description generation #869

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -372,19 +372,23 @@ public JsonElement genTool(JsonElement node, String toolName, String connectionN
Property.CONNECTION_KEY, Property.CHECK_ERROR_KEY));
keys.removeAll(ignoredKeys);
List<String> paramList = new ArrayList<>();
for (String key : keys) {
Property property = properties.get(key);
for (String k : keys) {
Property property = properties.get(k);
if (property == null) {
continue;
}
PropertyCodedata codedata = property.codedata();
if (codedata != null) {
String kind = codedata.kind();
if (kind != null && kind.equals(ParameterData.Kind.DEFAULTABLE.name())) {
ignoredKeys.add(key);
ignoredKeys.add(k);
continue;
}
}
String key = k;
if (k.startsWith("$")) {
key = "'" + k.substring(1);
}
if (hasDescription) {
sourceBuilder.token().parameterDoc(key, property.metadata().description());
}
Expand Down Expand Up @@ -465,8 +469,8 @@ public JsonElement genTool(JsonElement node, String toolName, String connectionN
keys.removeAll(ignoredKeys);
List<String> paramList = new ArrayList<>();
Set<String> pathParams = new HashSet<>();
for (String key : keys) {
Property property = properties.get(key);
for (String k : keys) {
Property property = properties.get(k);
if (property == null) {
continue;
}
Expand All @@ -475,12 +479,16 @@ public JsonElement genTool(JsonElement node, String toolName, String connectionN
String kind = codedata.kind();
if (kind.equals(ParameterData.Kind.PATH_PARAM.name()) ||
kind.equals(ParameterData.Kind.PATH_REST_PARAM.name())) {
pathParams.add(key);
pathParams.add(k);
} else if (kind.equals(ParameterData.Kind.DEFAULTABLE.name())) {
ignoredKeys.add(key);
ignoredKeys.add(k);
continue;
}
}
String key = k;
if (k.startsWith("$")) {
key = "'" + k.substring(1);
}
if (hasDescription) {
sourceBuilder.token().parameterDoc(key, property.metadata().description());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,15 @@ public SourceBuilder functionParameters(FlowNode nodeTemplate, Set<String> ignor
if (firstParamAdded) {
tokenBuilder.keyword(SyntaxKind.COMMA_TOKEN);
}
tokenBuilder.expression(prop);
tokenBuilder.param(prop);
} else if (kind.equals(ParameterData.Kind.INCLUDED_RECORD.name())) {
if (isPropValueEmpty(prop)) {
continue;
}
if (firstParamAdded) {
tokenBuilder.keyword(SyntaxKind.COMMA_TOKEN);
}
tokenBuilder.expression(prop);
tokenBuilder.param(prop);
} else if (kind.equals(ParameterData.Kind.DEFAULTABLE.name())) {
if (isPropValueEmpty(prop)) {
missedDefaultValue = true;
Expand All @@ -470,7 +470,7 @@ public SourceBuilder functionParameters(FlowNode nodeTemplate, Set<String> ignor
tokenBuilder.name(prop.codedata().originalName()).whiteSpace()
.keyword(SyntaxKind.EQUAL_TOKEN).expression(prop);
} else {
tokenBuilder.expression(prop);
tokenBuilder.param(prop);
}
} else if (kind.equals(ParameterData.Kind.INCLUDED_FIELD.name())) {
if (isPropValueEmpty(prop)) {
Expand Down Expand Up @@ -679,6 +679,15 @@ public TokenBuilder expression(Property property) {
return this;
}

public TokenBuilder param(Property property) {
String source = property.toSourceCode();
if (source.startsWith("$")) {
source = "'" + source.substring(1);
}
sb.append(source);
return this;
}

public TokenBuilder expression(String exprAsStr) {
sb.append(exprAsStr);
return this;
Expand Down Expand Up @@ -748,8 +757,9 @@ public TokenBuilder skipFormatting() {

public TokenBuilder descriptionDoc(String description) {
sb.append(SyntaxKind.HASH_TOKEN.stringValue())
.append(WHITE_SPACE)
.append(description);
.append(WHITE_SPACE);

appendDescription(description.split(System.lineSeparator()));
if (!description.endsWith(System.lineSeparator())) {
sb.append(System.lineSeparator());
}
Expand All @@ -765,9 +775,12 @@ public TokenBuilder parameterDoc(String paramName, String description) {
.append(paramName)
.append(WHITE_SPACE)
.append("-")
.append(WHITE_SPACE)
.append(description)
.append(System.lineSeparator());
.append(WHITE_SPACE);

appendDescription(description.split(System.lineSeparator()));
if (!description.endsWith(System.lineSeparator())) {
sb.append(System.lineSeparator());
}
}
return this;
}
Expand All @@ -781,13 +794,26 @@ public TokenBuilder returnDoc(String returnDescription) {
.append(SyntaxKind.RETURN_KEYWORD.stringValue())
.append(WHITE_SPACE)
.append("-")
.append(WHITE_SPACE)
.append(returnDescription)
.append(System.lineSeparator());
.append(WHITE_SPACE);

appendDescription(returnDescription.split(System.lineSeparator()));
if (!returnDescription.endsWith(System.lineSeparator())) {
sb.append(System.lineSeparator());
}
}
return this;
}

private void appendDescription(String[] descLines) {
sb.append(descLines[0]);
for (int i = 1; i < descLines.length; i++) {
sb.append(System.lineSeparator());
sb.append(SyntaxKind.HASH_TOKEN.stringValue())
.append(WHITE_SPACE)
.append(descLines[i]);
}
}

public String build(SourceKind kind) {
String outputStr = sb.toString();
if (skipFormatting) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ protected Object[] getConfigsList() {
{Path.of("remote_action_tool3.json")},
{Path.of("remote_action_tool4.json")},
{Path.of("remote_action_tool5.json")},
{Path.of("remote_action_tool6.json")},
};
}

Expand Down
Loading
Loading