-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hof/chat: mvp for chatgpt & llm features (#201)
🎉
- Loading branch information
Showing
33 changed files
with
1,114 additions
and
17 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,95 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/hofstadter-io/hof/cmd/hof/flags" | ||
|
||
"github.com/hofstadter-io/hof/cmd/hof/ga" | ||
) | ||
|
||
var chatLong = `Use chat to work with hof features or from modules you import. | ||
Module authors can provide custom prompts for their schemas. | ||
Currently, only ChatGPT is supported. You can use any of the | ||
gpt-3.5 or gpt-4 models. The flag should match OpenAI API options. | ||
Set OPENAI_API_KEY` | ||
|
||
func init() { | ||
|
||
ChatCmd.Flags().StringVarP(&(flags.ChatFlags.Model), "model", "M", "gpt-3.5-turbo", "LLM model to use [gpt-3.5-turbo,gpt-4]") | ||
ChatCmd.Flags().StringVarP(&(flags.ChatFlags.Prompt), "prompt", "P", "", "path to the system prompt, the first message in the chat") | ||
ChatCmd.Flags().StringVarP(&(flags.ChatFlags.Outfile), "outfile", "O", "", "path to write the output to") | ||
} | ||
|
||
func ChatRun(args []string) (err error) { | ||
|
||
// you can safely comment this print out | ||
fmt.Println("not implemented") | ||
|
||
return err | ||
} | ||
|
||
var ChatCmd = &cobra.Command{ | ||
|
||
Use: "chat [args]", | ||
|
||
Short: "Co-design with AI (alpha)", | ||
|
||
Long: chatLong, | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
ga.SendCommandPath(cmd.CommandPath()) | ||
|
||
var err error | ||
|
||
// Argument Parsing | ||
|
||
err = ChatRun(args) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
extra := func(cmd *cobra.Command) bool { | ||
|
||
return false | ||
} | ||
|
||
ohelp := ChatCmd.HelpFunc() | ||
ousage := ChatCmd.UsageFunc() | ||
|
||
help := func(cmd *cobra.Command, args []string) { | ||
|
||
ga.SendCommandPath(cmd.CommandPath() + " help") | ||
|
||
if extra(cmd) { | ||
return | ||
} | ||
ohelp(cmd, args) | ||
} | ||
usage := func(cmd *cobra.Command) error { | ||
if extra(cmd) { | ||
return nil | ||
} | ||
return ousage(cmd) | ||
} | ||
|
||
thelp := func(cmd *cobra.Command, args []string) { | ||
help(cmd, args) | ||
} | ||
tusage := func(cmd *cobra.Command) error { | ||
return usage(cmd) | ||
} | ||
ChatCmd.SetHelpFunc(thelp) | ||
ChatCmd.SetUsageFunc(tusage) | ||
|
||
} |
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,9 @@ | ||
package flags | ||
|
||
type ChatFlagpole struct { | ||
Model string | ||
Prompt string | ||
Outfile string | ||
} | ||
|
||
var ChatFlags ChatFlagpole |
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,99 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/hofstadter-io/hof/cmd/hof/flags" | ||
|
||
"github.com/hofstadter-io/hof/cmd/hof/ga" | ||
|
||
"github.com/hofstadter-io/hof/lib/chat/cmd" | ||
) | ||
|
||
var chatLong = `Use chat to work with hof features or from modules you import. | ||
Module authors can provide custom prompts for their schemas. | ||
Currently, only ChatGPT is supported. You can use any of the | ||
gpt-3.5 or gpt-4 models. The flag should match OpenAI API options. | ||
Set OPENAI_API_KEY` | ||
|
||
func init() { | ||
|
||
ChatCmd.Flags().StringVarP(&(flags.ChatFlags.Model), "model", "M", "gpt-3.5-turbo", "LLM model to use [gpt-3.5-turbo,gpt-4]") | ||
ChatCmd.Flags().StringVarP(&(flags.ChatFlags.Prompt), "prompt", "P", "", "path to the system prompt, the first message in the chat") | ||
ChatCmd.Flags().StringVarP(&(flags.ChatFlags.Outfile), "outfile", "O", "", "path to write the output to") | ||
} | ||
|
||
func ChatRun(args []string) (err error) { | ||
|
||
// you can safely comment this print out | ||
// fmt.Println("not implemented") | ||
|
||
err = cmd.Run(args, flags.RootPflags, flags.ChatFlags) | ||
|
||
return err | ||
} | ||
|
||
var ChatCmd = &cobra.Command{ | ||
|
||
Use: "chat [args]", | ||
|
||
Short: "Co-design with AI (alpha)", | ||
|
||
Long: chatLong, | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
ga.SendCommandPath(cmd.CommandPath()) | ||
|
||
var err error | ||
|
||
// Argument Parsing | ||
|
||
err = ChatRun(args) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
extra := func(cmd *cobra.Command) bool { | ||
|
||
return false | ||
} | ||
|
||
ohelp := ChatCmd.HelpFunc() | ||
ousage := ChatCmd.UsageFunc() | ||
|
||
help := func(cmd *cobra.Command, args []string) { | ||
|
||
ga.SendCommandPath(cmd.CommandPath() + " help") | ||
|
||
if extra(cmd) { | ||
return | ||
} | ||
ohelp(cmd, args) | ||
} | ||
usage := func(cmd *cobra.Command) error { | ||
if extra(cmd) { | ||
return nil | ||
} | ||
return ousage(cmd) | ||
} | ||
|
||
thelp := func(cmd *cobra.Command, args []string) { | ||
help(cmd, args) | ||
} | ||
tusage := func(cmd *cobra.Command) error { | ||
return usage(cmd) | ||
} | ||
ChatCmd.SetHelpFunc(thelp) | ||
ChatCmd.SetUsageFunc(tusage) | ||
|
||
} |
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,9 @@ | ||
package flags | ||
|
||
type ChatFlagpole struct { | ||
Model string | ||
Prompt string | ||
Outfile string | ||
} | ||
|
||
var ChatFlags ChatFlagpole |
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,48 @@ | ||
package cmds | ||
|
||
import ( | ||
"github.com/hofstadter-io/hofmod-cli/schema" | ||
) | ||
|
||
#ChatCommand: schema.#Command & { | ||
Name: "chat" | ||
Usage: "chat [args]" | ||
Short: "Co-design with AI (alpha)" | ||
Long: #ChatRootHelp | ||
|
||
Flags: [...schema.#Flag] & [ { | ||
Name: "model" | ||
Type: "string" | ||
Default: "\"gpt-3.5-turbo\"" | ||
Help: "LLM model to use [gpt-3.5-turbo,gpt-4]" | ||
Long: "model" | ||
Short: "M" | ||
}, | ||
{ | ||
Name: "prompt" | ||
Type: "string" | ||
Default: "\"\"" | ||
Help: "path to the system prompt, the first message in the chat" | ||
Long: "prompt" | ||
Short: "P" | ||
}, | ||
{ | ||
Name: "outfile" | ||
Type: "string" | ||
Default: "\"\"" | ||
Help: "path to write the output to" | ||
Long: "outfile" | ||
Short: "O" | ||
}, | ||
] | ||
} | ||
|
||
#ChatRootHelp: #""" | ||
Use chat to work with hof features or from modules you import. | ||
Module authors can provide custom prompts for their schemas. | ||
Currently, only ChatGPT is supported. You can use any of the | ||
gpt-3.5 or gpt-4 models. The flag should match OpenAI API options. | ||
Set OPENAI_API_KEY | ||
"""# |
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,61 @@ | ||
package sql | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/hofstadter-io/hof/schema/dm/fields" | ||
) | ||
|
||
ChatETL: { | ||
// input models model fields value nested map (relns) | ||
Original: Models: [string]: [string]: string | {[string]: string} | ||
Datamodel: Models: { | ||
for m, M in Original.Models { | ||
(m): { | ||
Name: m | ||
Fields: { | ||
for f, F in M { | ||
// regular field | ||
if !strings.HasPrefix(f, "$") { | ||
(f): { | ||
Name: f | ||
[ | ||
if F == "string" {Varchar}, | ||
if F == "int" {fields.Int}, | ||
if F == "bool" {fields.Bool}, | ||
if F == "float" {fields.Float}, | ||
if F == "uuid" {fields.UUID}, | ||
if F == "datetime" {fields.Datetime}, | ||
if F == "email" {fields.Email}, | ||
if F == "password" {fields.Password}, | ||
if F == "url" {Varchar}, | ||
"UNKNOWN TYPE: \(F)" & false, | ||
][0] | ||
} | ||
} | ||
|
||
// $relations | ||
if f == "$relations" { | ||
for f2, F2 in F { | ||
(f2): { | ||
fields.UUID | ||
Name: f2 | ||
Relation: { | ||
Name: F2.name | ||
Type: F2.type | ||
Other: F2.model | ||
} | ||
} | ||
} | ||
} | ||
|
||
// special fields | ||
if f == "id" { | ||
(f): SQL: PrimaryKey: true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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.