{"id":17941793,"url":"https://github.com/inferablehq/inferable-bash","last_synced_at":"2025-08-15T20:31:17.018Z","repository":{"id":259192270,"uuid":"876552943","full_name":"inferablehq/inferable-bash","owner":"inferablehq","description":"A lightweight Bash SDK for interacting with the Inferable API. This SDK allows you to register and run Inferable functions directly from shell scripts.","archived":false,"fork":false,"pushed_at":"2024-10-22T07:00:43.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-10-23T10:05:07.914Z","etag":null,"topics":["ai-agents","bash"],"latest_commit_sha":null,"homepage":"https://www.inferable.ai","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/inferablehq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-22T06:59:45.000Z","updated_at":"2024-10-22T07:03:06.000Z","dependencies_parsed_at":"2024-10-23T11:33:52.104Z","dependency_job_id":null,"html_url":"https://github.com/inferablehq/inferable-bash","commit_stats":null,"previous_names":["inferablehq/inferable-bash"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inferablehq%2Finferable-bash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inferablehq%2Finferable-bash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inferablehq%2Finferable-bash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inferablehq%2Finferable-bash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inferablehq","download_url":"https://codeload.github.com/inferablehq/inferable-bash/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229948901,"owners_count":18149574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-agents","bash"],"created_at":"2024-10-29T02:04:12.369Z","updated_at":"2024-12-16T11:06:15.688Z","avatar_url":"https://github.com/inferablehq.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Inferable Bash SDK\n\n\u003e **Note**: This is a demonstration project to show that \"all we need is HTTP\" for an Inferable integration. We don't recommend creating bash-based AI clients for production use.\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Documentation](https://img.shields.io/badge/docs-inferable.ai-brightgreen)](https://docs.inferable.ai/)\n\nA lightweight Bash SDK for interacting with the Inferable API. This SDK allows you to register and run Inferable functions directly from shell scripts.\n\n## Installation\n\n1. Download the SDK:\n\n```bash\ncurl -O https://raw.githubusercontent.com/inferablehq/inferable-bash/main/inferable.sh\nchmod +x inferable.sh\n```\n\n2. Set up your environment:\n\n```bash\nexport INFERABLE_API_SECRET=\"your-api-secret\"  # Required\nexport INFERABLE_API_ENDPOINT=\"https://api.inferable.ai\"  # Optional, defaults to https://api.inferable.ai\nexport INFERABLE_MACHINE_ID=\"custom-machine-id\"  # Optional, auto-generated if not provided\n```\n\n## Quick Start\n\nHere's a minimal example to get you started with the Inferable Bash SDK:\n\n```bash\n#!/bin/bash\n\n# Source the SDK\nsource ./inferable.sh\n\n# Initialize the SDK\ninferable_init || exit 1\n\n# Create a handler file (handler.sh)\ncat \u003e handler.sh \u003c\u003c 'EOF'\n#!/bin/bash\n\nfunction_name=$1\ninput=$2\n\ncase \"$function_name\" in\n    \"greet\")\n        name=$(echo \"$input\" | jq -r '.name')\n        echo \"{\\\"message\\\": \\\"Hello, $name!\\\"}\"\n        ;;\n    *)\n        echo \"{\\\"error\\\": \\\"Unknown function\\\"}\"\n        ;;\nesac\nEOF\n\nchmod +x handler.sh\n\n# Define your functions\nFUNCTIONS='[\n    {\n        \"name\": \"greet\",\n        \"description\": \"Greet a user\",\n        \"schema\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"name\": {\"type\": \"string\"}\n            },\n            \"required\": [\"name\"]\n        }\n    }\n]'\n\n# Register the service\nCLUSTER_ID=$(register_service \"greeting-service\" \"$FUNCTIONS\")\n\n# Start polling with your handler\nstart_service \"$CLUSTER_ID\" \"greeting-service\" \"./handler.sh\"\n```\n\n## Dependencies\n\n- `bash` (version 4.0 or later)\n- `curl` for making HTTP requests\n- `jq` for JSON processing\n\n## API Reference\n\n### Core Functions\n\n#### `inferable_init`\n\nInitializes the SDK and validates the connection to Inferable.\n\n```bash\ninferable_init || exit 1\n```\n\n#### `register_service`\n\nRegisters a new service with Inferable.\n\n```bash\nregister_service \u003cservice_name\u003e \u003cfunctions_json\u003e\n```\n\nParameters:\n\n- `service_name`: Name of your service\n- `functions_json`: JSON array of function definitions\n\nReturns: Cluster ID on success\n\n#### `start_service`\n\nStarts the service and begins polling for jobs.\n\n```bash\nstart_service \u003ccluster_id\u003e \u003cservice_name\u003e \u003chandler_script\u003e [poll_interval]\n```\n\nParameters:\n\n- `cluster_id`: ID returned from register_service\n- `service_name`: Name of your service\n- `handler_script`: Path to your handler script\n- `poll_interval`: Optional polling interval in seconds (default: 10)\n\n### Utility Functions\n\n#### `generate_machine_id`\n\nGenerates a unique machine identifier.\n\n```bash\nmachine_id=$(generate_machine_id \u003clength\u003e)\n```\n\n#### `make_request`\n\nMakes an HTTP request to the Inferable API.\n\n```bash\nmake_request \u003cmethod\u003e \u003cpath\u003e [body]\n```\n\n## Handler Script\n\nYour handler script should accept two arguments:\n\n1. Function name\n2. JSON input data\n\nExample handler:\n\n```bash\n#!/bin/bash\n\nfunction_name=$1\ninput=$2\n\ncase \"$function_name\" in\n    \"myFunction\")\n        # Process the input\n        value=$(echo \"$input\" | jq -r '.someField')\n\n        # Return JSON result\n        echo \"{\\\"result\\\": \\\"Processed $value\\\"}\"\n        ;;\n    *)\n        echo \"{\\\"error\\\": \\\"Unknown function\\\"}\"\n        ;;\nesac\n```\n\n## Environment Variables\n\n| Variable                 | Required | Default                    | Description                        |\n| ------------------------ | -------- | -------------------------- | ---------------------------------- |\n| `INFERABLE_API_SECRET`   | Yes      | -                          | Your Inferable API secret          |\n| `INFERABLE_API_ENDPOINT` | No       | `https://api.inferable.ai` | Inferable API endpoint             |\n| `INFERABLE_MACHINE_ID`   | No       | Auto-generated             | Unique identifier for this machine |\n\n## Error Handling\n\nThe SDK includes basic error handling. Functions will return non-zero exit codes on failure. We recommend wrapping critical operations in error checks:\n\n```bash\nif ! inferable_init; then\n    echo \"Failed to initialize SDK\" \u003e\u00262\n    exit 1\nfi\n\nCLUSTER_ID=$(register_service \"my-service\" \"$FUNCTIONS\")\nif [ -z \"$CLUSTER_ID\" ]; then\n    echo \"Failed to register service\" \u003e\u00262\n    exit 1\nfi\n```\n\n## Best Practices\n\n1. Always source the SDK rather than executing it:\n\n```bash\nsource ./inferable.sh  # Correct\n./inferable.sh        # Incorrect\n```\n\n2. Validate the initialization:\n\n```bash\ninferable_init || exit 1\n```\n\n3. Use error handling in your handler scripts:\n\n```bash\n#!/bin/bash\n\nfunction_name=$1\ninput=$2\n\nif [ -z \"$input\" ]; then\n    echo \"{\\\"error\\\": \\\"No input provided\\\"}\"\n    exit 1\nfi\n\n# Process function...\n```\n\n4. Set reasonable polling intervals based on your needs:\n\n```bash\n# More frequent polling (5 seconds)\nstart_service \"$CLUSTER_ID\" \"my-service\" \"./handler.sh\" 5\n\n# Less frequent polling (30 seconds)\nstart_service \"$CLUSTER_ID\" \"my-service\" \"./handler.sh\" 30\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finferablehq%2Finferable-bash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finferablehq%2Finferable-bash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finferablehq%2Finferable-bash/lists"}