{"id":37008837,"url":"https://github.com/focusbp/openai-response-php","last_synced_at":"2026-01-14T00:50:29.397Z","repository":{"id":321282738,"uuid":"1085178317","full_name":"focusbp/openai-response-php","owner":"focusbp","description":"A lightweight utility for working with OpenAI Responses API and Vector Stores.","archived":false,"fork":false,"pushed_at":"2025-10-28T21:03:45.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-28T21:25:40.764Z","etag":null,"topics":["function-calling","openai","openai-api","php","vector-store"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/focusbp.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-28T17:29:18.000Z","updated_at":"2025-10-28T21:03:50.000Z","dependencies_parsed_at":"2025-10-28T21:25:49.487Z","dependency_job_id":"3b7ba697-7388-4758-bb7a-88715d96025c","html_url":"https://github.com/focusbp/openai-response-php","commit_stats":null,"previous_names":["focusbp/openai-response-php"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/focusbp/openai-response-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/focusbp%2Fopenai-response-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/focusbp%2Fopenai-response-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/focusbp%2Fopenai-response-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/focusbp%2Fopenai-response-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/focusbp","download_url":"https://codeload.github.com/focusbp/openai-response-php/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/focusbp%2Fopenai-response-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28407198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["function-calling","openai","openai-api","php","vector-store"],"created_at":"2026-01-14T00:50:29.294Z","updated_at":"2026-01-14T00:50:29.373Z","avatar_url":"https://github.com/focusbp.png","language":"PHP","readme":"# OpenAI Response PHP\n\nA lightweight PHP library that wraps the OpenAI Responses API to provide:\n\n- **Vector Store integration** (sync local text files into an OpenAI Vector Store and use them as context)\n- **Function Calling support** (tool invocation with typed arguments)\n\nThis library is intended to be easy to drop into a simple PHP app, even on older environments.\n\n## Install\n\nYou can install it via Composer:\n\n```bash\ncomposer require focusbp/openai-response-php\n```\n\n---\n\n## Features\n\n### 🧠 Vector Store Integration\n- Syncs a local directory of text files into an OpenAI Vector Store.\n- Lets the model answer questions using that knowledge.\n\n### 🔧 Function Calling\n- Define tools (functions) in PHP and expose them to the model.\n- The model can call your tools with structured arguments.\n- Supports dependency injection via a controller object.\n\n### 💬 Conversation Recording\n- Conversation history (messages) can be persisted via `Recorder` implementations:\n  - `SessionRecorder` (stores in `$_SESSION`)\n  - `FileRecorder` (stores in local JSON files)\n\n### 📡 Status Polling\n- Includes a simple async-style status polling example using `status_poll.php` to report \"what the AI is doing right now\" to the frontend.\n\n---\n\n## Requirements\n\n- **PHP**: 7.3+ (no typed properties required)\n- **Extensions**: `cURL`, `json`\n- **Web server**: Any server that can run PHP (Apache, nginx + PHP-FPM, etc.)\n- **OpenAI API Key**\n\n---\n\n## Quick Start\n\nThis is the fastest way to see it working in a browser.\n\n1. **Set your API key**\n\n   Open `tests/config/config.php` and set your OpenAI API key:\n\n   ```php\n   $apikey = 'sk-...';\n   ```\n\n2. **Deploy**\n\n   Upload the entire `tests/` directory (and the project library) to a PHP-capable web server.\n\n3. **Access the demo UI**\n\n   Open `index.php` in your browser.  \n   The sample UI can answer:\n   - questions about upcoming events (from the Vector Store)\n   - weather questions (via Function Calling)\n\n---\n\n## Vector Store Usage\n\n### 1. Add source files\nPut plain text files (or other supported text content) into the `vector_store/` directory.  \nFor example:\n\n```text\nvector_store/\n  events.txt\n  faq.txt\n  company_info.txt\n```\n\nThese files act as your \"knowledge base.\"\n\n### 2. Sync with OpenAI\nFrom the sample UI (the test app in `tests/`), click:\n\n**\"Sync Vector Store\"**\n\nWhen you click that:\n- The library will upload/sync the contents of `vector_store/` to the configured Vector Store in OpenAI.\n- The Vector Store will then be used to ground answers.\n\nIf a Vector Store does not exist yet, the library can create one.  \nIf it already exists, the library can update it.\n\n---\n\n## Function Calling\n\nThe library exposes a Function Calling interface so the model can decide to call your PHP functions as tools.\n\n### 1. Create a tool\n\nCreate a class in the `function_tools/` directory that implements `\\focusbp\\OpenAIResponsePhp\\FunctionTool`.\n\nExample (simplified):\n\n```php\nclass Weather implements \\focusbp\\OpenAIResponsePhp\\FunctionTool {\n\n    public function name(): string {\n        return \"weather\";\n    }\n\n    public function description(): string {\n        return \"Returns a weather forecast.\";\n    }\n\n    public function parameters(): array {\n        return [\n            'type' =\u003e 'object',\n            'properties' =\u003e [\n                'city' =\u003e [\n                    'type' =\u003e 'string',\n                    'description' =\u003e 'Name of the city to get the weather for (e.g. \"Tokyo\", \"Osaka\")',\n                ],\n            ],\n            'required' =\u003e ['city'],\n            'additionalProperties' =\u003e false,\n        ];\n    }\n\n    public function execute(\\focusbp\\OpenAIResponsePhp\\Controller $ctl, array $arguments) {\n        $city = isset($arguments['city']) ? (string)$arguments['city'] : '';\n\n        if ($city === '') {\n            return [\n                'ok'    =\u003e false,\n                'error' =\u003e 'Missing required argument \"city\".',\n            ];\n        }\n\n        // Demo implementation\n        return [\n            'ok'       =\u003e true,\n            'city'     =\u003e $city,\n            'forecast' =\u003e 'Sunny',\n        ];\n    }\n}\n```\n\n### 2. Dependency injection via Controller\n\nIf your tool needs shared services like:\n- database connections\n- HTTP clients\n- config\n\n…you can create your own class that **extends** `\\focusbp\\OpenAIResponsePhp\\Controller` and put those dependencies there.\n\nThen, when you instantiate the `OpenAI` client, pass that controller instance into the constructor.\n\nInside `execute()`, you’ll receive that same `$ctl` instance, so you can do things like `$ctl-\u003edb-\u003equery(...)` or `$ctl-\u003eweatherApi-\u003efetch(...)`.\n\n### 3. Auto-loading\n\nAny class you put in `function_tools/` that implements `FunctionTool` will be auto-discovered and made available to the model.\n\n---\n\n## Conversation \u0026 Status\n\n### Message history\n\nThe library keeps a running conversation history (system / user / assistant / tool messages).  \nThis can be persisted using a `Recorder`:\n\n- `SessionRecorder` keeps messages in `$_SESSION`.\n- `FileRecorder` can write JSON logs to disk.\n\nBoth provide:\n- `read()`\n- `write()`\n- `append()`\n\n### Status polling\n\nThe sample UI calls `status_poll.php` on an interval and displays a short status string (e.g. “fetching vector store…”).  \nThis status string is stored via a `StatusManager` implementation.\n\nExample implementation:\n- `SessionStatusManager` stores a `_status_msg` value in `$_SESSION`.\n\n---\n\n## Logging\n\nAll request/response logs and debug output can be written to the `log/` directory.\n\nIf you’re debugging or auditing model behavior:\n- Check the generated files in `log/`.\n- You can also wire up a `FileRecorder` so you have a full transcript.\n\n\n---\n\n## Project Structure (reference)\n\nBelow is a typical layout to help you navigate:\n\n```text\n/ (project root)\n├─ src/\n│  ├─ OpenAI.php                # Main wrapper class\n│  ├─ Controller.php            # Base controller for dependency injection\n│  ├─ Recorder.php              # Interface for saving conversation history\n│  ├─ SessionRecorder.php       # Recorder using $_SESSION\n│  ├─ FileRecorder.php          # Recorder using local JSON files\n│  ├─ StatusManager.php         # Interface for run status tracking\n│  ├─ SessionStatusManager.php  # Session-based StatusManager\n│  └─ ... other core classes ...\n│\n├─ function_tools/\n│  ├─ Weather.php               # Example FunctionTool implementation\n│  └─ ... your tools ...\n│\n├─ vector_store/\n│  └─ *.txt                     # Knowledge base files to sync\n│\n├─ log/\n│  └─ *.log                     # Logs and conversation transcripts\n│\n├─ tests/\n│  ├─ index.php                 # Browser demo UI\n│  ├─ status_poll.php           # Polling endpoint for status\n│  └─ style.css                 # Simple chat UI styling\n│\n└─ README.md\n```\n\n---\n\n## Demo Flow (What the sample UI does)\n\n1. You open `tests/index.php` in your browser.\n2. You see a chat-like interface.\n3. You ask something like:\n   - “What upcoming events are there?”\n   - “What’s the weather tomorrow in Tokyo?”\n4. Under the hood:\n   - For event questions, it retrieves knowledge from the synced Vector Store.\n   - For weather questions, it calls the `Weather` tool via Function Calling.\n5. The UI polls `status_poll.php` so you can see status text like “Start AI Processing...” or other internal messages.\n\n---\n\n## Security Notes\n\n- Do not expose your API key publicly.  \n  `tests/index.php` is for local or protected testing.\n- Vector Store content is sent to OpenAI.  \n  Do not sync files that contain secrets, PII, or anything you’re not comfortable sending to an API.\n- Logs may contain both user input and model output.\n\n---\n\n## License\n\nAdd your preferred license here (MIT, Apache-2.0, etc.).\n\n---\n\n## Contributing\n\nPull requests and issues are welcome.  \nIf you add new tools or storage backends (e.g. RedisRecorder, DatabaseStatusManager), please include minimal usage docs in your PR so others can learn from it.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffocusbp%2Fopenai-response-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffocusbp%2Fopenai-response-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffocusbp%2Fopenai-response-php/lists"}