{"id":26935369,"url":"https://github.com/code-monad/prompt-wrapper","last_synced_at":"2025-04-02T11:19:08.394Z","repository":{"id":284272261,"uuid":"954394218","full_name":"code-monad/prompt-wrapper","owner":"code-monad","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-25T02:52:29.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T03:29:06.301Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/code-monad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-03-25T02:39:49.000Z","updated_at":"2025-03-25T02:52:32.000Z","dependencies_parsed_at":"2025-03-25T03:39:11.328Z","dependency_job_id":null,"html_url":"https://github.com/code-monad/prompt-wrapper","commit_stats":null,"previous_names":["code-monad/prompt-wrapper"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-monad%2Fprompt-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-monad%2Fprompt-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-monad%2Fprompt-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-monad%2Fprompt-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/code-monad","download_url":"https://codeload.github.com/code-monad/prompt-wrapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246802571,"owners_count":20836374,"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":[],"created_at":"2025-04-02T11:19:07.867Z","updated_at":"2025-04-02T11:19:08.380Z","avatar_url":"https://github.com/code-monad.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Prompt Wrapper Service\n\nA simple service that provides wise sayings from an LLM (OpenRouter) with rate limiting and caching.\n\n## Features\n\n- RESTful HTTP endpoints for managing sayings and presets\n- Rate limiting for users\n- Persistent storage with Sled embedded database\n- Rich UI-ready preset configurations\n- Random preset selection for each user session\n- Integration with OpenRouter for LLM capabilities\n- Test user available in debug builds for easy testing\n\n## Setup\n\n1. Clone the repository\n2. Copy `.env.example` to `.env` and update with your settings\n3. Get an API key from [OpenRouter](https://openrouter.ai)\n4. Update the `.env` file with your OpenRouter API key\n5. Customize prompt presets in `presets.yaml` file\n\n## Running the service\n\n```bash\ncargo run\n```\n\nThe service will be available at http://localhost:3000\n\n## API Endpoints\n\n### Sayings Resource\n\n#### GET /sayings\n\nReturns a list of sayings for the specified user.\n\n**Query Parameters:**\n- `user_id` (optional): Identifier for the user. If not provided, a default value is used.\n- `limit` (optional): Maximum number of sayings to return. Default is 10.\n\n**Response:**\n```json\n[\n  {\n    \"id\": \"uuid1\",\n    \"content\": \"Saying content 1\",\n    \"created_at\": \"2023-01-01T00:00:00Z\",\n    \"source\": \"llm\"\n  },\n  {\n    \"id\": \"uuid2\",\n    \"content\": \"Saying content 2\",\n    \"created_at\": \"2023-01-01T00:00:00Z\",\n    \"source\": \"llm\"\n  }\n]\n```\n\n#### GET /sayings/latest\n\nReturns the latest saying for the specified user.\n\n**Query Parameters:**\n- `user_id` (optional): Identifier for the user. If not provided, a default value is used.\n\n**Response:**\n```json\n{\n  \"id\": \"uuid\",\n  \"content\": \"The saying content\",\n  \"created_at\": \"2023-01-01T00:00:00Z\",\n  \"source\": \"llm\"\n}\n```\n\n#### POST /sayings\n\nCreates a new saying using the OpenRouter LLM API and returns it.\n\n**Query Parameters:**\n- `user_id` (optional): Identifier for the user. If not provided, a default value is used.\n\n**Request Body:**\n```json\n{\n  \"prompt\": \"Optional prompt to guide the LLM\",\n  \"preset_id\": \"Optional preset ID to use a specific preset\"\n}\n```\n\nIf neither `prompt` nor `preset_id` is provided, the service will use the preset that was randomly selected for the user.\n\n**Response:**\n```json\n{\n  \"id\": \"uuid\",\n  \"content\": \"The saying content\",\n  \"created_at\": \"2023-01-01T00:00:00Z\",\n  \"source\": \"llm\"\n}\n```\n\n### User Status Resource\n\n#### GET /users/{user_id}/status\n\nReturns the user's rate limit status, their last retrieved saying, and their currently selected preset.\n\n**Response:**\n```json\n{\n  \"user_id\": \"user123\",\n  \"can_query\": true,\n  \"remaining_requests\": 5,\n  \"reset_at\": \"2023-01-01T01:00:00Z\",\n  \"last_saying\": {\n    \"id\": \"uuid\",\n    \"content\": \"The last saying content\",\n    \"created_at\": \"2023-01-01T00:00:00Z\",\n    \"source\": \"llm\"\n  },\n  \"selected_preset\": {\n    \"id\": \"oracle\",\n    \"name\": \"Ape Oracle\",\n    \"description\": \"Ancient wisdom for modern questions\",\n    \"tags\": [\"oracle\", \"wisdom\", \"mystical\"],\n    \"button_text\": \"Reveal My Answer\",\n    \"loading_text\": \"Consulting the oracle...\",\n    \"instruction_text\": \"Focus on your question, press the button, and receive wisdom from the Ape Oracle...\"\n  }\n}\n```\n\n### Presets Resource\n\n#### GET /presets\n\nReturns all available presets.\n\n**Response:**\n```json\n[\n  {\n    \"id\": \"oracle\",\n    \"name\": \"Ape Oracle\",\n    \"description\": \"Ancient wisdom for modern questions\",\n    \"tags\": [\"oracle\", \"wisdom\", \"mystical\"],\n    \"button_text\": \"Reveal My Answer\",\n    \"loading_text\": \"Consulting the oracle...\",\n    \"instruction_text\": \"Focus on your question, press the button, and receive wisdom from the Ape Oracle...\"\n  },\n  {\n    \"id\": \"fortune\",\n    \"name\": \"Fortune Teller\",\n    \"description\": \"Glimpse into your future\",\n    \"tags\": [\"fortune\", \"future\", \"prediction\"],\n    \"button_text\": \"Read My Fortune\",\n    \"loading_text\": \"Gazing into the crystal ball...\",\n    \"instruction_text\": \"Think of what you wish to know about your future, then press the button...\"\n  }\n]\n```\n\n#### GET /presets/{preset_id}\n\nReturns a specific preset by ID.\n\n**Response:**\n```json\n{\n  \"id\": \"oracle\",\n  \"name\": \"Ape Oracle\",\n  \"description\": \"Ancient wisdom for modern questions\",\n  \"tags\": [\"oracle\", \"wisdom\", \"mystical\"],\n  \"button_text\": \"Reveal My Answer\",\n  \"loading_text\": \"Consulting the oracle...\",\n  \"instruction_text\": \"Focus on your question, press the button, and receive wisdom from the Ape Oracle...\"\n}\n```\n\n## Presets Configuration\n\nPresets are defined in a YAML file specified by the `PRESETS_FILE_PATH` environment variable. Each preset contains:\n\n- `id`: Unique identifier for the preset\n- `name`: Display name for the preset\n- `description`: Short description of the preset's purpose\n- `tags`: List of category tags\n- `button_text`: Text to display on action buttons\n- `loading_text`: Text to display during loading/processing\n- `instruction_text`: Guidance text for users\n- `system_prompt`: The system prompt to set the context for the LLM\n- `user_prompts`: List of possible user prompts that will be randomly selected\n\nExample preset configuration:\n\n```yaml\n- id: oracle\n  name: Ape Oracle\n  description: Ancient wisdom for modern questions\n  tags:\n    - oracle\n    - wisdom\n    - mystical\n  button_text: Reveal My Answer\n  loading_text: Consulting the oracle...\n  instruction_text: Focus on your question, press the button, and receive wisdom from the Ape Oracle...\n  system_prompt: \u003e\n    You are the Ape Oracle, a mystical entity that provides profound, \n    wise, and sometimes cryptic answers to unspoken questions.\n  user_prompts:\n    - \"Will I find success?\"\n    - \"What should I do next?\"\n    - \"Is this the right path?\"\n```\n\n## Configuration\n\nAll configuration is done through environment variables or the `.env` file:\n\n- `SERVER_HOST`: Host to bind the server to\n- `SERVER_PORT`: Port to bind the server to\n- `OPENROUTER_API_KEY`: Your OpenRouter API key\n- `OPENROUTER_MODEL`: The model to use (default: mistralai/mistral-7b-instruct)\n- `RATE_LIMIT_MAX_REQUESTS`: Maximum number of requests per window\n- `RATE_LIMIT_WINDOW_SECONDS`: Window size in seconds for rate limiting\n- `STORAGE_TYPE`: Type of storage to use (memory, sled, redis, sqlite)\n- `STORAGE_CONNECTION_STRING`: Connection string for the storage\n- `PRESETS_FILE_PATH`: Path to the presets YAML file\n\n## Development Features\n\n### Test User\n\nIn debug builds (when compiling without the `--release` flag), a test user is automatically initialized with:\n\n- User ID: `test_user` \n- Empty initial state (no pre-populated sayings)\n- Fresh rate limit quota (according to configured settings)\n\nThe test user follows a completely dynamic workflow identical to regular users:\n- All sayings are generated on-demand via the LLM or cache\n- Rate limiting follows standard rules\n- Presets are dynamically selected for each user session\n- No hardcoded or static responses are used\n\nYou can use this test user for development and testing purposes by including `user_id=test_user` in your requests:\n\n```\nGET /sayings?user_id=test_user\n```\n\n**Note:** This test user ID is blocked in release/production builds to prevent misuse in production environments.\nTo test in release mode, use a different user ID.\n\n## License\n\nMIT ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-monad%2Fprompt-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcode-monad%2Fprompt-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-monad%2Fprompt-wrapper/lists"}