-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minimal implementation of the code to generate completions. (#32)
* This is a pretty minimal implementation. * The entire response from the AI is added; i.e. we potentially add multiple blocks to the document. I'm not sure that's the best UX. * Implement some OpenAI utilities * Add a helper function to initiate OpenAI clients * Parse OpenAI errors for common cases like context length exceeded
- Loading branch information
Showing
12 changed files
with
385 additions
and
9 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,57 @@ | ||
package agent | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/jlewi/foyle/app/pkg/config" | ||
"github.com/jlewi/foyle/app/pkg/oai" | ||
"github.com/jlewi/foyle/protos/go/foyle/v1alpha1" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func Test_Generate(t *testing.T) { | ||
if os.Getenv("GITHUB_ACTIONS") != "" { | ||
t.Skipf("Test is skipped in GitHub actions") | ||
} | ||
|
||
if err := config.InitViper(nil); err != nil { | ||
t.Fatalf("Failed to initialize viper: %v", err) | ||
} | ||
cfg := config.GetConfig() | ||
|
||
// Setup logs | ||
c := zap.NewDevelopmentConfig() | ||
log, err := c.Build() | ||
if err != nil { | ||
t.Fatalf("Error creating logger; %v", err) | ||
} | ||
zap.ReplaceGlobals(log) | ||
|
||
client, err := oai.NewClient(*cfg) | ||
if err != nil { | ||
t.Fatalf("Error creating OpenAI client; %v", err) | ||
} | ||
agent, err := NewAgent(*cfg, client) | ||
|
||
if err != nil { | ||
t.Fatalf("Error creating agent; %v", err) | ||
} | ||
|
||
req := &v1alpha1.GenerateRequest{ | ||
Doc: &v1alpha1.Doc{ | ||
Blocks: []*v1alpha1.Block{ | ||
{ | ||
Contents: "Use gcloud to list all the cloud build jobs in project foyle", | ||
}, | ||
}, | ||
}, | ||
} | ||
resp, err := agent.Generate(context.Background(), req) | ||
if err != nil { | ||
t.Fatalf("Error generating; %v", err) | ||
} | ||
|
||
t.Logf("Response: %+v", resp) | ||
} |
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,30 @@ | ||
package agent | ||
|
||
import ( | ||
_ "embed" | ||
"text/template" | ||
) | ||
|
||
const ( | ||
systemPrompt = `You are a helpful AI assistant for software developers. You are helping software engineers write markdown documents to deploy | ||
and operate software. Your job is to help users reason about problems and tasks and come up with the appropriate | ||
commands to accomplish them. You should never try to execute commands. You should always tell the user | ||
to execute the commands themselves. To help the user place the commands inside a code block with the language set to | ||
bash. Users can then execute the commands inside VSCode notebooks. The output will then be appended to the document. | ||
You can then use that output to reason about the next steps. | ||
You are only helping users with tasks related to building, deploying, and operating software. You should interpret | ||
any questions or commands in that context. | ||
` | ||
) | ||
|
||
//go:embed prompt.tmpl | ||
var promptTemplateString string | ||
|
||
var ( | ||
promptTemplate = template.Must(template.New("prompt").Parse(promptTemplateString)) | ||
) | ||
|
||
type promptArgs struct { | ||
Document string | ||
} |
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,12 @@ | ||
Please continue writing this markdown document to deal with any tasks or issues listed | ||
in the document. The document is a markdown document. It will contain a description of the task | ||
or problem, I need your help with. It will then contain one or more code blocks containing commands | ||
to be executed to accomplish the task or obtain information needed to figure out the problem. | ||
If a command has already been executed the output of the command will be provided in a code block | ||
with the language `output`. Use the output to help you figure out the problem or complete the task. | ||
If you need me to execute a command please provide the command in a code block and I will execute it | ||
and then add the output to the document. | ||
|
||
Here's the document: | ||
|
||
{{.Document}} |
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
Oops, something went wrong.