-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the learner to not include the full notebook in the example.
- Loading branch information
Showing
7 changed files
with
140 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package docs | ||
|
||
import ( | ||
"context" | ||
"github.com/jlewi/foyle/protos/go/foyle/v1alpha1" | ||
) | ||
|
||
// CreateQuery creates a query from a GenerateRequest | ||
// It returns the blocks that should be used to query for similar documents | ||
func CreateQuery(ctx context.Context, req *v1alpha1.GenerateRequest) ([]*v1alpha1.Block, error) { | ||
// Use a simple algorithm. | ||
// 1. Always select at least the current block | ||
// 2. Select additional blocks if they are markup blocks. | ||
startIndex := req.GetSelectedIndex() - 1 | ||
|
||
for ; startIndex >= 0; startIndex-- { | ||
if req.GetDoc().GetBlocks()[startIndex].Kind != v1alpha1.BlockKind_MARKUP { | ||
break | ||
} | ||
} | ||
|
||
blocks := req.GetDoc().GetBlocks()[startIndex+1 : req.GetSelectedIndex()+1] | ||
return blocks, 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,85 @@ | ||
package docs | ||
|
||
import ( | ||
"github.com/google/go-cmp/cmp" | ||
"github.com/jlewi/foyle/app/pkg/testutil" | ||
"github.com/jlewi/foyle/protos/go/foyle/v1alpha1" | ||
"testing" | ||
) | ||
|
||
func Test_CreateQuery(t *testing.T) { | ||
doc1 := &v1alpha1.Doc{ | ||
Blocks: []*v1alpha1.Block{ | ||
{ | ||
Kind: v1alpha1.BlockKind_MARKUP, | ||
Contents: "cell 0", | ||
}, | ||
{ | ||
Kind: v1alpha1.BlockKind_MARKUP, | ||
Contents: "cell 1", | ||
}, | ||
{ | ||
Kind: v1alpha1.BlockKind_CODE, | ||
Contents: "cell 2", | ||
}, | ||
{ | ||
Kind: v1alpha1.BlockKind_MARKUP, | ||
Contents: "cell 3", | ||
}, | ||
{ | ||
Kind: v1alpha1.BlockKind_MARKUP, | ||
Contents: "cell 4", | ||
}, | ||
}, | ||
} | ||
|
||
type testCase struct { | ||
name string | ||
input *v1alpha1.GenerateRequest | ||
expected []*v1alpha1.Block | ||
} | ||
|
||
cases := []testCase{ | ||
{ | ||
name: "stop-at-start", | ||
input: &v1alpha1.GenerateRequest{ | ||
Doc: doc1, | ||
SelectedIndex: 1, | ||
}, | ||
expected: doc1.Blocks[0:2], | ||
}, | ||
{ | ||
name: "start-on-codeblock", | ||
input: &v1alpha1.GenerateRequest{ | ||
Doc: doc1, | ||
SelectedIndex: 2, | ||
}, | ||
expected: doc1.Blocks[0:3], | ||
}, | ||
{ | ||
name: "stop-on-code", | ||
input: &v1alpha1.GenerateRequest{ | ||
Doc: doc1, | ||
SelectedIndex: 4, | ||
}, | ||
expected: doc1.Blocks[3:5], | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
blocks, err := CreateQuery(nil, tc.input) | ||
if err != nil { | ||
t.Fatalf("CreateQuery failed: %v", err) | ||
} | ||
if len(blocks) != len(tc.expected) { | ||
t.Errorf("CreateQuery returned %d blocks; want %d", len(blocks), len(tc.expected)) | ||
} | ||
|
||
if d := cmp.Diff(tc.expected, blocks, testutil.DocComparer, testutil.BlockComparer); d != "" { | ||
t.Errorf("CreateQuery returned unexpected blocks:\n%v", d) | ||
} | ||
|
||
}) | ||
} | ||
} |
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,2 @@ | ||
package llms | ||
|
||
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