Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 Refactor for new parsed layers #33

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ release:
GOPROXY=proxy.golang.org go list -m github.com/go-go-golems/geppetto@${VERSION}

bump-glazed:
go get github.com/go-go-golems/glazed@main
go get github.com/go-go-golems/clay@main
go get github.com/go-go-golems/glazed@latest
go get github.com/go-go-golems/clay@latest
go get github.com/go-go-golems/parka@latest
go mod tidy

PINOCCHIO_BINARY=$(shell which pinocchio)
install:
Expand Down
Empty file added cmd/lucignolo/doc/.create
Empty file.
133 changes: 133 additions & 0 deletions cmd/lucignolo/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package main

import (
"embed"
"fmt"
clay "github.com/go-go-golems/clay/pkg"
"github.com/go-go-golems/geppetto/pkg/cmds"
glazed_cmds "github.com/go-go-golems/glazed/pkg/cmds"
"github.com/go-go-golems/glazed/pkg/help"
parka "github.com/go-go-golems/parka/pkg"
"github.com/spf13/cobra"
"os"
)

//go:embed doc/*
var docFS embed.FS

//go:embed prompts/*
var promptsFS embed.FS

var rootCmd = &cobra.Command{
Use: "pinocchio",
Short: "pinocchio is a tool to run LLM applications",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// reinitialize the logger because we can now parse --log-level and co
// from the command line flag
err := clay.InitLogger()
cobra.CheckErr(err)
},
}

func main() {
helpSystem := help.NewHelpSystem()
err := helpSystem.LoadSectionsFromFS(docFS, ".")
if err != nil {
panic(err)
}

helpFunc, usageFunc := help.GetCobraHelpUsageFuncs(helpSystem)
helpTemplate, usageTemplate := help.GetCobraHelpUsageTemplates(helpSystem)

_ = usageFunc
_ = usageTemplate

//sections, err := openai.LoadModelsHelpFiles()
//if err != nil {
// log.Error().Err(err).Msg("Error loading models help files")
//}
//for _, section := range sections {
// helpSystem.AddSection(section)
//}
//
rootCmd.SetHelpFunc(helpFunc)
rootCmd.SetUsageFunc(usageFunc)
rootCmd.SetHelpTemplate(helpTemplate)
rootCmd.SetUsageTemplate(usageTemplate)

helpCmd := help.NewCobraHelpCommand(helpSystem)
rootCmd.SetHelpCommand(helpCmd)

err = clay.InitViper("lucignolo", rootCmd)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Error initializing config: %s\n", err)
os.Exit(1)
}
err = clay.InitLogger()
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Error initializing logger: %s\n", err)
os.Exit(1)
}

locations := clay.CommandLocations{
Embedded: []clay.EmbeddedCommandLocation{
{
FS: promptsFS,
Name: "embed",
Root: ".",
DocRoot: "prompts/doc",
},
},
}

yamlLoader := glazed_cmds.NewYAMLFSCommandLoader(
&cmds.GeppettoCommandLoader{}, "", "")
commands, aliases, err := locations.LoadCommands(
yamlLoader, helpSystem, rootCmd)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Error initializing commands: %s\n", err)
os.Exit(1)
}
_ = commands
_ = aliases

var ServeCmd = &cobra.Command{
Use: "serve",
Short: "Starts lucignolo",
Run: func(cmd *cobra.Command, args []string) {
_, err := cmd.Flags().GetUint16("port")
cobra.CheckErr(err)

serverOptions := []parka.ServerOption{}

templateDir, err := cmd.Flags().GetString("template-dir")
cobra.CheckErr(err)
if templateDir != "" {
serverOptions = append(
serverOptions,
parka.WithTemplateLookups(parka.LookupTemplateFromDirectory(templateDir)),
)
}

var parkaCommands []parka.ParkaCommand
for _, command := range commands {
parkaCommands = append(parkaCommands, parka.NewSimpleParkaCommand(command))
}
for _, alias := range aliases {
parkaCommands = append(parkaCommands, parka.NewSimpleParkaCommand(alias))
}
serverOptions = append(serverOptions, parka.WithCommands(parkaCommands...))

s, _ := parka.NewServer(serverOptions...)

err = s.Run()
cobra.CheckErr(err)
},
}

ServeCmd.Flags().Uint16P("port", "p", 8080, "Port to listen on")
ServeCmd.Flags().StringP("template-dir", "t", "", "Directory containing the templates")

rootCmd.AddCommand(ServeCmd)
_ = rootCmd.Execute()
}
55 changes: 55 additions & 0 deletions cmd/lucignolo/prompts/rewrite.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: rewrite
short: Rewrite text
factories:
openai:
client:
timeout: 120
completion:
engine: text-davinci-003
temperature: 0.8
max_response_tokens: 1024
# stream: true
flags:
- name: author
type: stringList
help: Inspired by authors
default:
- L. Ron Hubbard
- Isaac Asimov
- Richard Bandler
- Robert Anton Wilson
- name: adjective
type: stringList
help: Style adjectives
default:
- esoteric
- retro
- technical
- seventies hip
- science fiction
- name: style
type: string
help: Style
default: in a style reminiscent of seventies and eighties computer manuals
- name: instructions
type: string
help: Additional instructions
arguments:
- name: body
type: stringFromFile
help: Paragraph to rewrite
required: true
prompt: |
Rewrite the following paragraph,
{{ if .style }}in the style of {{ .style }},{{ end }}
{{ if .adjective }}so that it sounds {{ .adjective | join ", " }}, {{ end }}
{{ if .author }}in the style of {{ .author | join ", " }}. {{ end }}
Don't mention any authors names.

---
{{ .body -}}
---

{{ if .instructions }} {{ .instructions }} {{ end }}

---
8 changes: 7 additions & 1 deletion cmd/pinocchio/cmds/openai/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/go-go-golems/geppetto/pkg/steps/openai"
"github.com/go-go-golems/glazed/pkg/cli"
"github.com/go-go-golems/glazed/pkg/cmds"
"github.com/go-go-golems/glazed/pkg/cmds/layers"
"github.com/go-go-golems/glazed/pkg/cmds/parameters"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -67,7 +68,12 @@ func NewCompletionCommand() (*CompletionCommand, error) {
}, nil
}

func (j *CompletionCommand) Run(ctx context.Context, ps map[string]interface{}, gp *cmds.GlazeProcessor) error {
func (j *CompletionCommand) Run(
ctx context.Context,
parsedLayers map[string]*layers.ParsedParameterLayer,
ps map[string]interface{},
gp *cmds.GlazeProcessor,
) error {
prompts := []string{}

inputFiles, ok := ps["input-files"].([]string)
Expand Down
37 changes: 29 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ require (
github.com/charmbracelet/bubbles v0.15.0
github.com/charmbracelet/bubbletea v0.23.1
github.com/charmbracelet/lipgloss v0.6.0
github.com/go-go-golems/clay v0.0.6-0.20230222151015-3d0fba6da4ce
github.com/go-go-golems/glazed v0.2.14
github.com/go-go-golems/clay v0.0.6
github.com/go-go-golems/glazed v0.2.18
github.com/go-go-golems/parka v0.2.3
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.29.0
github.com/spf13/cobra v1.6.1
Expand All @@ -26,32 +27,46 @@ require (
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/adrg/frontmatter v0.2.0 // indirect
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/alecthomas/chroma/v2 v2.2.0 // indirect
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52 v1.0.3 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/bytedance/sonic v1.8.0 // indirect
github.com/charmbracelet/glamour v0.6.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/kopoli/go-terminal-size v0.0.0-20170219200355-5c97524c8b54 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/microcosm-cc/bluemonday v1.0.21 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
Expand All @@ -67,13 +82,19 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tj/go-naturaldate v1.3.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
github.com/wesen/filepathx v1.0.1-0.20230227021146-d1c2e34eff6e // indirect
github.com/yuin/goldmark v1.5.4 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20220924101305-151362477c87 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/term v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading