Skip to content

feat: OpenAI-compat /v1/embeddings endpoint + bug fixes (v0.3.0)#4

Merged
TadMSTR merged 4 commits into
mainfrom
feat/openai-compat-v0.3.0
May 28, 2026
Merged

feat: OpenAI-compat /v1/embeddings endpoint + bug fixes (v0.3.0)#4
TadMSTR merged 4 commits into
mainfrom
feat/openai-compat-v0.3.0

Conversation

@TadMSTR
Copy link
Copy Markdown
Owner

@TadMSTR TadMSTR commented May 28, 2026

Summary

  • Add POST /v1/embeddings endpoint that translates to /api/embed internally — enables Graphiti (and any OpenAI SDK client) to route through OQP without changing its provider config
  • New openai_compat.py module handles path detection, rewrite, and Ollama→OpenAI response format wrapping
  • Embedding cache, auth, and priority ceiling all apply unchanged to the compat endpoint
  • Fix asyncio.get_event_loop() deprecation in Python 3.10+ (→ get_running_loop())
  • Fix streaming response connection leak on client disconnect (missing finally: await r.aclose())
  • Fix _apply_env_overrides crash (TypeError: list indices must be integers) when env var contains a numeric path component (e.g. OQP_OLLAMA__HOSTS__0__URL)

Test plan

  • pytest tests/ passes 150/150 (14 new + 136 existing)
  • curl -X POST http://localhost:11435/v1/embeddings -d '{"model":"bge-m3","input":"test"}' returns OpenAI format
  • Cache hit on repeated embedding request via /v1/embeddings
  • Auth check applies: unauthenticated request to /v1/embeddings returns 401
  • CI is green before tagging v0.3.0

Note: After this PR merges and CI passes, tag v0.3.0 to trigger GHCR publish. Then update forge agent-platform/docker-compose.yml to v0.3.0 and reconfigure Graphiti (separate helm-build task).

🤖 Generated with Claude Code

TadMSTR and others added 4 commits May 28, 2026 07:49
Add OpenAI-compatible embedding endpoint so Graphiti (and any OpenAI SDK
client) can route through OQP without reconfiguration.

New:
- openai_compat.py: path detection (is_openai_compat_path), path rewrite
  (/v1/embeddings → /api/embed), and response wrapping (Ollama → OpenAI
  embeddings format). Always-on; no config required.
- proxy_handler: detect /v1/embeddings, rewrite path before enqueue, wrap
  response after dispatch. Cache and auth apply unchanged.
- _enqueue_request / dispatch_request: add path_override param for compat
  path rewrite to propagate through queue/cache/dispatch logic.
- 14 new tests covering path detection, rewrite, response wrapping, and
  list-index env var skip behavior.

Bug fixes:
- main.py: asyncio.get_event_loop() → get_running_loop() (DeprecationWarning
  in 3.10+, RuntimeError in 3.12+)
- proxy.py: streaming generator now closes httpx response in finally block
  to prevent connection leak on client disconnect
- config.py: _apply_env_overrides now skips any key with a numeric path
  component instead of crashing with TypeError when the target is a list
  (e.g. OQP_OLLAMA__HOSTS__0__URL)

Bump version to 0.3.0.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…edundant import

- openai_compat.py: rewrite_path() now returns "/api/embed" (was "api/embed") —
  missing slash produced malformed URLs like "http://host:11434api/embed"
- proxy.py: comment on stream_gen finally block — explains it closes the httpx
  connection on client disconnect to prevent connection leak (not obvious from code)
- main.py: comment on get_running_loop() — explains why get_event_loop() was
  replaced (deprecated 3.10+, raises RuntimeError in 3.12+)
- main.py: remove local `import json as _json` inside proxy_handler — json is
  already imported at module level; use it directly
- test_openai_compat.py: update expected values to match corrected "/api/embed"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add endpoint to the Endpoints table and a dedicated section explaining the
translation, Graphiti config snippet, and that it is always-on.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@TadMSTR TadMSTR merged commit 7cf3f0a into main May 28, 2026
7 checks passed
@TadMSTR TadMSTR deleted the feat/openai-compat-v0.3.0 branch May 28, 2026 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant