Compare commits
2 Commits
1840b449d5
...
9f75be615e
Author | SHA1 | Date | |
---|---|---|---|
9f75be615e | |||
16454a0bbd |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
venv/
|
venv/
|
||||||
lmcli
|
|
||||||
**/*.env
|
**/*.env
|
||||||
|
134
main.go
134
main.go
@ -3,139 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
"github.com/spf13/cobra"
|
"git.mlow.ca/mlow/lmcli/pkg/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
var config = LoadConfig()
|
|
||||||
var store, storeError = InitializeStore()
|
|
||||||
|
|
||||||
func checkStore() {
|
|
||||||
if storeError != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "Error establishing connection to store: %v\n", storeError)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
|
||||||
Use: "lm",
|
|
||||||
Short: "Interact with Large Language Models",
|
|
||||||
Long: `lm is a CLI tool to interact with OpenAI's GPT 3.5 and GPT 4.`,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
checkStore()
|
|
||||||
// execute `lm ls` by default
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var lsCmd = &cobra.Command{
|
|
||||||
Use: "ls",
|
|
||||||
Short: "List existing conversations",
|
|
||||||
Long: `List all existing conversations in descending order of recent activity.`,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
fmt.Println("Listing conversations...")
|
|
||||||
// Example output, asterisk to indicate current converation
|
|
||||||
|
|
||||||
// $ lm ls
|
|
||||||
// last hour:
|
|
||||||
// 98sg - 12 minutes ago - Project discussion
|
|
||||||
// last day:
|
|
||||||
// tj3l - 10 hours ago - Deep learning concepts
|
|
||||||
// last week:
|
|
||||||
// bwfm - 2 days ago - Machine learning study
|
|
||||||
// * 8n3h - 3 days ago - Weekend plans
|
|
||||||
// f3n7 - 6 days ago - CLI development
|
|
||||||
// last month:
|
|
||||||
// 5hn2 - 8 days ago - Book club discussion
|
|
||||||
// b7ze - 20 days ago - Gardening tips and tricks
|
|
||||||
// last 6 months:
|
|
||||||
// 3jn2 - 30 days ago - Web development best practices
|
|
||||||
// 43jk - 2 months ago - Longboard maintenance
|
|
||||||
// g8d9 - 3 months ago - History book club
|
|
||||||
// 4lk3 - 4 months ago - Local events and meetups
|
|
||||||
// 43jn - 6 months ago - Mobile photography techniques
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var msgCmd = &cobra.Command{
|
|
||||||
Use: "msg",
|
|
||||||
Short: "Send a message to active conversation",
|
|
||||||
Long: `Send a message to the active conversation and receive a message from the LLM in return.`,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
fmt.Println("Sending message to active conversation...")
|
|
||||||
// If no messsage provided via args, we should open an editor ala `git commit`
|
|
||||||
// After submitting the message, the
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var viewCmd = &cobra.Command{
|
|
||||||
Use: "view",
|
|
||||||
Short: "View messages in a conversation",
|
|
||||||
Long: `Displays all the messages in a coversation.`,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
fmt.Println("Displaying conversation messages...")
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var newCmd = &cobra.Command{
|
|
||||||
Use: "new",
|
|
||||||
Short: "Start a new conversation",
|
|
||||||
Long: `Start a new conversation with the Large Language Model.`,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
messageContents, err := InputFromEditor("# What would you like to say?", "message.*.md")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "Error receiving message input: %v\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if messageContents == "" {
|
|
||||||
fmt.Fprintf(os.Stderr, "No message was provided.\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("> %s\n", messageContents)
|
|
||||||
|
|
||||||
messages := []Message{
|
|
||||||
{
|
|
||||||
OriginalContent: messageContents,
|
|
||||||
Role: "user",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
err = CreateChatCompletionStream("You are a helpful assistant.", messages, os.Stdout)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "An error occured: %v\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println()
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var promptCmd = &cobra.Command{
|
|
||||||
Use: "prompt",
|
|
||||||
Short: "Do a one-shot prompt",
|
|
||||||
Long: `Prompt the Large Language Model and get a response.`,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
messages := []Message{
|
|
||||||
{
|
|
||||||
OriginalContent: strings.Join(args, " "),
|
|
||||||
Role: "user",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
err := CreateChatCompletionStream("You are a helpful assistant.", messages, os.Stdout)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "An error occured: %v\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println()
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rootCmd.AddCommand(newCmd, promptCmd)
|
cmd := cli.NewRootCmd()
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := cmd.Execute(); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
139
pkg/cli/cmd.go
Normal file
139
pkg/cli/cmd.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var config = LoadConfig()
|
||||||
|
var store, storeError = InitializeStore()
|
||||||
|
|
||||||
|
func checkStore() {
|
||||||
|
if storeError != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error establishing connection to store: %v\n", storeError)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var rootCmd = &cobra.Command{
|
||||||
|
Use: "lm",
|
||||||
|
Short: "Interact with Large Language Models",
|
||||||
|
Long: `lm is a CLI tool to interact with OpenAI's GPT 3.5 and GPT 4.`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
checkStore()
|
||||||
|
// execute `lm ls` by default
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var lsCmd = &cobra.Command{
|
||||||
|
Use: "ls",
|
||||||
|
Short: "List existing conversations",
|
||||||
|
Long: `List all existing conversations in descending order of recent activity.`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Println("Listing conversations...")
|
||||||
|
// Example output, asterisk to indicate current converation
|
||||||
|
|
||||||
|
// $ lm ls
|
||||||
|
// last hour:
|
||||||
|
// 98sg - 12 minutes ago - Project discussion
|
||||||
|
// last day:
|
||||||
|
// tj3l - 10 hours ago - Deep learning concepts
|
||||||
|
// last week:
|
||||||
|
// bwfm - 2 days ago - Machine learning study
|
||||||
|
// * 8n3h - 3 days ago - Weekend plans
|
||||||
|
// f3n7 - 6 days ago - CLI development
|
||||||
|
// last month:
|
||||||
|
// 5hn2 - 8 days ago - Book club discussion
|
||||||
|
// b7ze - 20 days ago - Gardening tips and tricks
|
||||||
|
// last 6 months:
|
||||||
|
// 3jn2 - 30 days ago - Web development best practices
|
||||||
|
// 43jk - 2 months ago - Longboard maintenance
|
||||||
|
// g8d9 - 3 months ago - History book club
|
||||||
|
// 4lk3 - 4 months ago - Local events and meetups
|
||||||
|
// 43jn - 6 months ago - Mobile photography techniques
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var msgCmd = &cobra.Command{
|
||||||
|
Use: "msg",
|
||||||
|
Short: "Send a message to active conversation",
|
||||||
|
Long: `Send a message to the active conversation and receive a message from the LLM in return.`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Println("Sending message to active conversation...")
|
||||||
|
// If no messsage provided via args, we should open an editor ala `git commit`
|
||||||
|
// After submitting the message, the
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var viewCmd = &cobra.Command{
|
||||||
|
Use: "view",
|
||||||
|
Short: "View messages in a conversation",
|
||||||
|
Long: `Displays all the messages in a coversation.`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Println("Displaying conversation messages...")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var newCmd = &cobra.Command{
|
||||||
|
Use: "new",
|
||||||
|
Short: "Start a new conversation",
|
||||||
|
Long: `Start a new conversation with the Large Language Model.`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
messageContents, err := InputFromEditor("# What would you like to say?", "message.*.md")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error receiving message input: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if messageContents == "" {
|
||||||
|
fmt.Fprintf(os.Stderr, "No message was provided.\n")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("> %s\n", messageContents)
|
||||||
|
|
||||||
|
messages := []Message{
|
||||||
|
{
|
||||||
|
OriginalContent: messageContents,
|
||||||
|
Role: "user",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err = CreateChatCompletionStream("You are a helpful assistant.", messages, os.Stdout)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "An error occured: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var promptCmd = &cobra.Command{
|
||||||
|
Use: "prompt",
|
||||||
|
Short: "Do a one-shot prompt",
|
||||||
|
Long: `Prompt the Large Language Model and get a response.`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
messages := []Message{
|
||||||
|
{
|
||||||
|
OriginalContent: strings.Join(args, " "),
|
||||||
|
Role: "user",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := CreateChatCompletionStream("You are a helpful assistant.", messages, os.Stdout)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "An error occured: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRootCmd() *cobra.Command {
|
||||||
|
rootCmd.AddCommand(newCmd, promptCmd)
|
||||||
|
return rootCmd;
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
@ -1,4 +1,4 @@
|
|||||||
package main
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
Loading…
Reference in New Issue
Block a user