fix: add typechecking, linting

This commit is contained in:
Brad Olson
2023-07-17 22:35:46 -04:00
parent e75fabd7bc
commit 1f581d07db
2 changed files with 15 additions and 6 deletions
+13 -5
View File
@@ -15,9 +15,8 @@ type Combining struct {
// NewCombining creates a new combining parser.
func NewCombining(parsers []schema.OutputParser[any]) Combining {
p := make([]schema.OutputParser[any], len(parsers))
for i, parser := range parsers {
p[i] = parser
}
copy(p, parsers)
return Combining{
Parsers: p,
@@ -29,7 +28,8 @@ var _ schema.OutputParser[any] = Combining{}
// GetFormatInstructions returns the format instructions.
func (p Combining) GetFormatInstructions() string {
text := "Your response will be a map of strings combining the output of parsers\nusing text delimited by two successive newline characters, to the respective parser.\n\n"
text := "Your response will be a map of strings combining the output of parsers\n"
text += "using text delimited by two successive newline characters, to the respective parser.\n\n"
text += "The output parser instructions are:"
for _, parser := range p.Parsers {
@@ -66,7 +66,15 @@ func (p Combining) parse(text string) (map[string]any, error) {
return nil, err
}
for k, result := range parsed.(map[string]string) {
parsedMap, ok := parsed.(map[string]string)
if !ok {
return nil, ParseError{
Text: textChunk,
Reason: fmt.Sprintf("Parser %d does not return a map of strings", parsed),
}
}
for k, result := range parsedMap {
output[k] = result
}
}
+2 -1
View File
@@ -1,6 +1,7 @@
package outputparser
import (
"errors"
"reflect"
"testing"
@@ -80,7 +81,7 @@ func TestCombine(t *testing.T) {
for _, tc := range testCases {
actual, err := tc.parsers.Parse(tc.text)
if tc.err != nil && tc.err != err {
if tc.err != nil && !errors.Is(tc.err, err) {
t.Errorf("Expected error %v, got %v", err, tc.err)
}