Skip to content

Commit

Permalink
Merge pull request #24 from kris-hansen/server-post
Browse files Browse the repository at this point in the history
Server post
  • Loading branch information
kris-hansen authored Dec 2, 2024
2 parents 73d2cbb + 642e798 commit ee20a20
Show file tree
Hide file tree
Showing 8 changed files with 561 additions and 43 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Build and Release

on:
push:
branches: [ main ]
workflow_dispatch:

permissions:
contents: write

jobs:
test-and-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Run Tests
run: go test -v ./...

- name: Get latest tag
id: get_latest_tag
run: |
git fetch --tags
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1` 2>/dev/null || echo "v0.0.0")
echo "LATEST_TAG=$latest_tag" >> $GITHUB_ENV
- name: Bump version and push tag
id: tag_version
run: |
# Parse the latest version
version=${LATEST_TAG#v}
IFS='.' read -ra ADDR <<< "$version"
major="${ADDR[0]:-0}"
minor="${ADDR[1]:-0}"
patch="${ADDR[2]:-0}"
# Increment patch version
patch=$((patch + 1))
# Create new version
new_version="v$major.$minor.$patch"
# Create and push new tag
git tag $new_version
git push origin $new_version
echo "NEW_VERSION=$new_version" >> $GITHUB_ENV
- name: Build Release Binaries
run: |
platforms=("windows/amd64" "windows/386" "darwin/amd64" "darwin/arm64" "linux/amd64" "linux/386" "linux/arm64")
for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
output_name="comanda-$GOOS-$GOARCH"
if [ $GOOS = "windows" ]; then
output_name+=".exe"
fi
echo "Building for $GOOS/$GOARCH..."
GOOS=$GOOS GOARCH=$GOARCH go build -o "dist/$output_name" .
if [ $? -ne 0 ]; then
echo "Error building for $GOOS/$GOARCH"
exit 1
fi
done
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.NEW_VERSION }}
name: Release ${{ env.NEW_VERSION }}
draft: false
prerelease: false
files: |
dist/comanda-windows-amd64.exe
dist/comanda-windows-386.exe
dist/comanda-darwin-amd64
dist/comanda-darwin-arm64
dist/comanda-linux-amd64
dist/comanda-linux-386
dist/comanda-linux-arm64
51 changes: 44 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
![robot image](comanda-small.jpg)

# COMandA (Chain of Models and Actions)

COMandA is a command-line tool that enables the composition of Large Language Model (LLM) operations using a YAML-based Domain Specific Language (DSL). It simplifies the process of creating and managing agentic workflows composed of downloads, files, text, images, documents, multiple providers and multiple models.
Expand All @@ -19,19 +20,30 @@ COMandA allows you to use the best provider and model for each step and compose
- 🕷️ Advanced web scraping capabilities with configurable options
- 🛠️ Extensible DSL for defining complex workflows
- ⚡ Efficient processing of LLM chains
- 🔒 HTTP server mode with bearer token authentication
- 🔒 HTTP server mode: use it as a multi-LLM workflow wrapper
- 🔐 Secure configuration encryption for protecting API keys and secrets
- 📁 Multi-file input support with content consolidation
- 📝 Markdown file support for reusable actions (prompts)
- 🗄️ Database integration for read/write operations for inputs and outputs

## Installation

### Download Pre-built Binary

The easiest way to get started is to download a pre-built binary from the [GitHub Releases page](https://github.com/kris-hansen/comanda/releases). Binaries are available for:
- Windows (386, amd64)
- macOS (amd64, arm64)
- Linux (386, amd64, arm64)

Download the appropriate binary for your system, extract it if needed, and place it somewhere in your system's PATH.

### Install via Go

```bash
go install github.com/kris-hansen/comanda@latest
```

Or clone and build from source:
### Build from Source

```bash
git clone https://github.com/kris-hansen/comanda.git
Expand Down Expand Up @@ -251,8 +263,9 @@ The server provides the following endpoints:

### 1. Process Endpoint

`GET /process` processes a YAML file from the configured data directory:
`GET /process` processes a YAML file from the configured data directory. For YAML files that use STDIN as their first input, `POST /process` is also supported.

#### GET Request
```bash
# Without authentication
curl "http://localhost:8080/process?filename=openai-example.yaml"
Expand All @@ -261,6 +274,22 @@ curl "http://localhost:8080/process?filename=openai-example.yaml"
curl -H "Authorization: Bearer your-token" "http://localhost:8080/process?filename=openai-example.yaml"
```

#### POST Request (for YAML files with STDIN input)
You can provide input either through a query parameter or JSON body:

```bash
# Using query parameter
curl -X POST "http://localhost:8080/process?filename=stdin-example.yaml&input=your text here"

# Using JSON body
curl -X POST \
-H "Content-Type: application/json" \
-d '{"input":"your text here"}' \
"http://localhost:8080/process?filename=stdin-example.yaml"
```

Note: POST requests are only allowed for YAML files where the first step uses "STDIN" as input. The /list endpoint shows which methods (GET or GET,POST) are supported for each YAML file.

Response format:
```json
{
Expand All @@ -281,7 +310,7 @@ Error response:

### 2. List Endpoint

`GET /list` returns a list of YAML files in the configured data directory:
`GET /list` returns a list of YAML files in the configured data directory, along with their supported HTTP methods:

```bash
curl -H "Authorization: Bearer your-token" "http://localhost:8080/list"
Expand All @@ -292,12 +321,20 @@ Response format:
{
"success": true,
"files": [
"openai-example.yaml",
"image-example.yaml",
"screenshot-example.yaml"
{
"name": "openai-example.yaml",
"methods": "GET"
},
{
"name": "stdin-example.yaml",
"methods": "GET,POST"
}
]
}
```
The `methods` field indicates which HTTP methods are supported:
- `GET`: The YAML file can be processed normally
- `GET,POST`: The YAML file accepts STDIN string input via POST request

### 3. Health Check Endpoint

Expand Down
28 changes: 28 additions & 0 deletions cmd/process.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package cmd

import (
"bufio"
"fmt"
"io"
"log"
"os"
"strings"

"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -35,6 +38,26 @@ var processCmd = &cobra.Command{
fmt.Println("[DEBUG] Environment configuration loaded successfully")
}

// Check if there's data on STDIN
stat, _ := os.Stdin.Stat()
var stdinData string
if (stat.Mode() & os.ModeCharDevice) == 0 {
// Read from STDIN
reader := bufio.NewReader(os.Stdin)
var builder strings.Builder
for {
input, err := reader.ReadString('\n')
if err != nil && err != io.EOF {
log.Fatalf("Error reading from STDIN: %v", err)
}
builder.WriteString(input)
if err == io.EOF {
break
}
}
stdinData = builder.String()
}

for _, file := range args {
fmt.Printf("\nProcessing DSL file: %s\n", file)

Expand Down Expand Up @@ -71,6 +94,11 @@ var processCmd = &cobra.Command{
}
proc := processor.NewProcessor(&dslConfig, envConfig, verbose)

// If we have STDIN data, set it as initial output
if stdinData != "" {
proc.SetLastOutput(stdinData)
}

// Print configuration summary before processing
fmt.Println("\nConfiguration:")
for _, step := range dslConfig.Steps {
Expand Down
Loading

0 comments on commit ee20a20

Please sign in to comment.