-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
650 additions
and
12 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
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,45 @@ | ||
package v1alpha1 | ||
|
||
import "k8s.io/apimachinery/pkg/runtime/schema" | ||
|
||
var ( | ||
CommunityBuilderKind = "CommunityBuilder" | ||
CommunityBuilderGVK = schema.FromAPIVersionAndKind(Group+"/"+Version, CommunityBuilderKind) | ||
) | ||
|
||
// TODO(jeremy): I think the name should be a noun not a verb. | ||
|
||
type CommunityBuilder struct { | ||
APIVersion string `json:"apiVersion" yaml:"apiVersion"` | ||
Kind string `json:"kind" yaml:"kind"` | ||
Metadata Metadata `json:"metadata" yaml:"metadata"` | ||
|
||
// Definition is the definition of the community. It parameterizes the LLM prompt to classifiy accounts | ||
Definition CommunityDefinition `json:"definition" yaml:"definition"` | ||
// Seeds is a list of accounts to seed the graph with | ||
Seeds []Account `json:"seeds" yaml:"seeds"` | ||
|
||
// OutputFile is the file to write the AccountList to | ||
OutputFile string `json:"outputFile" yaml:"outputFile"` | ||
} | ||
|
||
type CommunityDefinition struct { | ||
// Name is the name of the community | ||
Name string `json:"name" yaml:"name"` | ||
|
||
// Criterion is a list of criterion for including accounts in the community | ||
Criterion []string `json:"criterion" yaml:"criterion"` | ||
|
||
// Example is a list of examples to help classify accounts | ||
Examples []ProfileExample `json:"examples" yaml:"examples"` | ||
} | ||
|
||
type ProfileExample struct { | ||
// Profile is the example profile | ||
Profile string `json:"profile" yaml:"profile"` | ||
// Member is true or false depending on whether the profile is a member of the community | ||
Member bool `json:"member" yaml:"member"` | ||
|
||
// Explanation is the explanation of why the profile is a member or not | ||
Explanation string `json:"explanation" yaml:"explanation"` | ||
} |
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,81 @@ | ||
package e2etests | ||
|
||
import ( | ||
"context" | ||
"github.com/jlewi/bsctl/pkg/api/v1alpha1" | ||
"github.com/jlewi/bsctl/pkg/lists" | ||
"github.com/jlewi/bsctl/pkg/testutil" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func Test_Walker(t *testing.T) { | ||
if os.Getenv("GITHUB_ACTIONS") != "" { | ||
t.Skipf("Test_AccountsListApply is a manual test that is skipped in CICD") | ||
} | ||
|
||
stuff, err := testutil.New() | ||
if err != nil { | ||
t.Fatalf("testSetup() = %v, wanted nil", err) | ||
} | ||
|
||
app := stuff.App | ||
client, err := app.GetOAIClient(context.Background()) | ||
if err != nil { | ||
t.Fatalf("Failed to create OAI client; error %+v", err) | ||
} | ||
w, err := lists.NewWalker(stuff.Client, client) | ||
if err != nil { | ||
t.Fatalf("Failed to create walker; %+v", err) | ||
} | ||
|
||
f, err := os.CreateTemp("", "accounts.yaml") | ||
if err != nil { | ||
t.Fatalf("Failed to create temp file; %+v", err) | ||
} | ||
|
||
if err := f.Close(); err != nil { | ||
t.Fatalf("Failed to close file; %+v", err) | ||
} | ||
|
||
oFile := f.Name() | ||
|
||
t.Logf("Output file: %s", oFile) | ||
|
||
buildSpec := &v1alpha1.CommunityBuilder{ | ||
OutputFile: oFile, | ||
Seeds: []v1alpha1.Account{ | ||
{ | ||
Handle: "jeremy.lewi.us", | ||
}, | ||
}, | ||
Definition: v1alpha1.CommunityDefinition{ | ||
Name: "Platform Engineer", | ||
Examples: []v1alpha1.ProfileExample{ | ||
{ | ||
Profile: "I'm a platform engineer at acme.co", | ||
Member: true, | ||
}, | ||
}, | ||
Criterion: []string{ | ||
"They are working on an internal developer platform", | ||
"They describe their job role as platform engineer, ml platform engineer, devops, infrastructure engineer or SRE", | ||
"They work with technologies used to build platforms; eg. kubernetes, cloud, argo", | ||
"They describe practices central to platform engineering; e.g. IAC, configuration, containers, gitops, cicd", | ||
}, | ||
}, | ||
} | ||
|
||
//b, err := yaml.Marshal(buildSpec) | ||
//if err != nil { | ||
// t.Fatalf("Failed to marshal buildSpec; %+v", err) | ||
//} | ||
//if err := os.WriteFile("/tmp/platform_community_builder.yaml", b, 0644); err != nil { | ||
// t.Fatalf("Failed to write buildSpec; %+v", err) | ||
//} | ||
//return | ||
|
||
if err := w.Reconcile(context.Background(), buildSpec); err != nil { | ||
t.Fatalf("Reconcile() = %v, wanted nil", 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
You will be given a short description of a person taken from their social media account. | ||
Decide whether the person belongs to the {{.Definition.Name}} community. | ||
|
||
Use the following criterion to decide if someone belongs to the community | ||
{{range .Definition.Criterion}} | ||
* {{.}}{{end}} | ||
|
||
Emit the result as a json dictionary with field member which is a boolean | ||
which should be true if the profile belongs and false otherwise. | ||
Also include a field explanation with a short explanation of your classification. | ||
{{if .Definition.Examples}} | ||
Here are a bunch of examples of input documents along with the expected output. | ||
{{range .Definition.Examples}} | ||
<example> | ||
<input> | ||
{{.Profile}} | ||
</input> | ||
<output> | ||
{ "member": {{.Member}}, "explanation": "{{.Explanation}}" } | ||
</output> | ||
</example>{{end}}{{end}} | ||
Here's the profile you need to classify: | ||
{{.Profile}} |
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,33 @@ | ||
package lists | ||
|
||
import ( | ||
_ "embed" | ||
"github.com/jlewi/bsctl/pkg/api/v1alpha1" | ||
"github.com/pkg/errors" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
//go:embed profile_prompt.tmpl | ||
var promptTemplateString string | ||
|
||
var ( | ||
promptTemplate = template.Must(template.New("prompt").Parse(promptTemplateString)) | ||
) | ||
|
||
type PromptInput struct { | ||
Definition v1alpha1.CommunityDefinition | ||
Profile string | ||
} | ||
|
||
func buildPrompt(definition v1alpha1.CommunityDefinition, profile string) (string, error) { | ||
var sb strings.Builder | ||
input := PromptInput{ | ||
Definition: definition, | ||
Profile: profile, | ||
} | ||
if err := promptTemplate.Execute(&sb, input); err != nil { | ||
return "", errors.Wrapf(err, "Failed to execute prompt template") | ||
} | ||
return sb.String(), nil | ||
} |
Oops, something went wrong.