Skip to content

Commit

Permalink
Merge pull request #27 from kris-hansen/serve_config
Browse files Browse the repository at this point in the history
refactor: server config
  • Loading branch information
kris-hansen authored Dec 11, 2024
2 parents c2c7e3f + bb07df2 commit 1264242
Show file tree
Hide file tree
Showing 4 changed files with 332 additions and 98 deletions.
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ To encrypt your configuration:
comanda configure --encrypt
```

You'll be prompted to enter and confirm an encryption password. Once encrypted, all commands that need to access the configuration (process, serve, configure) will prompt for the password.
You'll be prompted to enter and confirm an encryption password. Once encrypted, all commands that need to access the configuration (process, server, configure) will prompt for the password.

Example workflow:
```bash
Expand Down Expand Up @@ -231,17 +231,21 @@ openai:
### Server Configuration
COMandA can run as an HTTP server, allowing you to process chains of models and actions defined in YAML files via HTTP requests. To configure the server:
COMandA can run as an HTTP server, allowing you to process chains of models and actions defined in YAML files via HTTP requests. The server is managed using the `server` command:

```bash
comanda configure --server
```
# Start the server
comanda server
This will prompt you to:
1. Set the server port (default: 8080)
2. Set the data directory path (default: data)
3. Generate a bearer token for authentication
4. Enable/disable authentication
# Configure server settings
comanda server configure # Interactive configuration
comanda server show # Show current configuration
comanda server port 8080 # Set server port
comanda server datadir ./data # Set data directory
comanda server auth on # Enable authentication
comanda server auth off # Disable authentication
comanda server newtoken # Generate new bearer token
```

The server configuration is stored in your `.env` file alongside provider and model settings:

Expand All @@ -256,7 +260,7 @@ server:
To start the server:

```bash
comanda serve
comanda server
```

The server provides the following endpoints:
Expand Down
57 changes: 0 additions & 57 deletions cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

var (
listFlag bool
serverFlag bool
encryptFlag bool
decryptFlag bool
removeFlag string
Expand Down Expand Up @@ -198,55 +197,6 @@ func configureDatabase(reader *bufio.Reader, envConfig *config.EnvConfig) error
return nil
}

func configureServer(reader *bufio.Reader, envConfig *config.EnvConfig) error {
serverConfig := envConfig.GetServerConfig()

// Prompt for port
fmt.Printf("Enter server port (default: %d): ", serverConfig.Port)
portStr, _ := reader.ReadString('\n')
portStr = strings.TrimSpace(portStr)
if portStr != "" {
port, err := strconv.Atoi(portStr)
if err != nil {
return fmt.Errorf("invalid port number: %v", err)
}
serverConfig.Port = port
}

// Prompt for data directory
fmt.Printf("Enter data directory path (default: %s): ", serverConfig.DataDir)
dataDir, _ := reader.ReadString('\n')
dataDir = strings.TrimSpace(dataDir)
if dataDir != "" {
serverConfig.DataDir = dataDir
}

// Create data directory if it doesn't exist
if err := os.MkdirAll(serverConfig.DataDir, 0755); err != nil {
return fmt.Errorf("error creating data directory: %v", err)
}

// Prompt for bearer token generation
fmt.Print("Generate new bearer token? (y/n): ")
genToken, _ := reader.ReadString('\n')
if strings.TrimSpace(strings.ToLower(genToken)) == "y" {
token, err := config.GenerateBearerToken()
if err != nil {
return fmt.Errorf("error generating bearer token: %v", err)
}
serverConfig.BearerToken = token
fmt.Printf("Generated bearer token: %s\n", token)
}

// Prompt for server enable/disable
fmt.Print("Enable server authentication? (y/n): ")
enableStr, _ := reader.ReadString('\n')
serverConfig.Enabled = strings.TrimSpace(strings.ToLower(enableStr)) == "y"

envConfig.UpdateServerConfig(*serverConfig)
return nil
}

func removeModel(envConfig *config.EnvConfig, modelName string) error {
removed := false
for providerName, provider := range envConfig.Providers {
Expand Down Expand Up @@ -527,12 +477,6 @@ var configureCmd = &cobra.Command{
fmt.Printf("Error: %v\n", err)
return
}
} else if serverFlag {
reader := bufio.NewReader(os.Stdin)
if err := configureServer(reader, envConfig); err != nil {
fmt.Printf("Error configuring server: %v\n", err)
return
}
} else if databaseFlag {
reader := bufio.NewReader(os.Stdin)
if err := configureDatabase(reader, envConfig); err != nil {
Expand Down Expand Up @@ -775,7 +719,6 @@ func listConfiguration() {

func init() {
configureCmd.Flags().BoolVar(&listFlag, "list", false, "List all configured providers and models")
configureCmd.Flags().BoolVar(&serverFlag, "server", false, "Configure server settings")
configureCmd.Flags().BoolVar(&encryptFlag, "encrypt", false, "Encrypt the configuration file")
configureCmd.Flags().BoolVar(&decryptFlag, "decrypt", false, "Decrypt the configuration file")
configureCmd.Flags().StringVar(&removeFlag, "remove", "", "Remove a model by name")
Expand Down
31 changes: 0 additions & 31 deletions cmd/serve.go

This file was deleted.

Loading

0 comments on commit 1264242

Please sign in to comment.