-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic markdown stripping and yaml linting
- Loading branch information
Showing
8 changed files
with
96 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package markdown | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
|
||
//gomarkdown "github.com/gomarkdown/markdown" | ||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/openshift/wisdom/pkg/api" | ||
) | ||
|
||
var ( | ||
markdownRegex = regexp.MustCompile("(?s)`{3}.*?\n(.*)`{3}") | ||
) | ||
|
||
func MarkdownStripper(response *api.ModelResponse) (*api.ModelResponse, error) { | ||
|
||
if response.Output == "" { | ||
return response, fmt.Errorf("response output is empty") | ||
} | ||
log.Debugf("Stripping markdown from response:\n %s\n", response.Output) | ||
|
||
//response.Output = markdownRegex.ReplaceAllString(response.Output, "") | ||
matches := markdownRegex.FindStringSubmatch(response.Output) | ||
response.Output = matches[1] | ||
/* | ||
node := gomarkdown.Parse([]byte(response.Output), nil) | ||
fmt.Printf("%#v\n", node.GetChildren()[0].GetChildren()[0]) | ||
//fmt.Printf("%#v\n", node.GetChildren()[0].GetChildren()[1]) | ||
//fmt.Printf("%s\n", node.GetChildren()[0].GetChildren()[1].AsLeaf().Literal) | ||
response.Output = string(node.GetChildren()[0].GetChildren()[0].AsLeaf().Literal) | ||
*/ | ||
|
||
//response.Output = stripmd.Strip(response.Output) | ||
|
||
log.Debugf("Stripped markdown from response:\n %s\n", response.Output) | ||
return response, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package yaml | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gopkg.in/yaml.v2" | ||
|
||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/openshift/wisdom/pkg/api" | ||
) | ||
|
||
func YamlLinter(response *api.ModelResponse) (*api.ModelResponse, error) { | ||
if err := isValidYAML(response.Output); err != nil { | ||
return response, fmt.Errorf("response output is not valid YAML: %s", err) | ||
} | ||
return response, nil | ||
} | ||
|
||
func isValidYAML(yamlString string) error { | ||
var data interface{} | ||
|
||
log.Debugf("Validating YAML:\n%s\n", yamlString) | ||
err := yaml.Unmarshal([]byte(yamlString), &data) | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters