39 lines
1.3 KiB
Markdown
39 lines
1.3 KiB
Markdown
# OpenAI Flow
|
||
|
||
**Özet:** OpenAI-compatible isteklerin gateway üzerinden direkt passthrough akışı.
|
||
|
||
**Kütüphaneler:** Fiber v3, Go `net/http`
|
||
|
||
**Bağlantılar:** [[OpenAIHandler]], [[ProxyEngine]], [[RequestLog]], [[Index]]
|
||
|
||
## Akış Diyagramı
|
||
|
||
```mermaid
|
||
sequenceDiagram
|
||
participant Client
|
||
participant Gateway
|
||
participant Proxy
|
||
participant Upstream
|
||
participant DB
|
||
|
||
Client->>Gateway: POST /v1/chat/completions
|
||
Note over Gateway: OpenAIHandler
|
||
Gateway->>Gateway: fiberToHTTPHeaders()
|
||
Gateway->>Gateway: API key auto-inject (gerekirse)
|
||
Gateway->>Gateway: copyResponseHeaders()
|
||
Gateway->>Proxy: Forward(method, targetURL, headers, body, timeout)
|
||
Proxy->>Upstream: POST <OPENAI_BACKEND>/v1/chat/completions
|
||
Upstream-->>Proxy: 200 OK + response body
|
||
Proxy-->>Gateway: ForwardResult{StatusCode, Body, Headers}
|
||
Gateway->>Gateway: copyResponseHeaders() (skip hop-by-hop)
|
||
Gateway->>DB: go db.Create(logEntry) — fire-and-forget
|
||
Gateway-->>Client: 200 OK + original response body
|
||
```
|
||
|
||
## Önemli Noktalar
|
||
|
||
- İstek body'si **olduğu gibi** iletilir (dönüşüm yok)
|
||
- Response header'ları kopyalanırken `Transfer-Encoding`, `Content-Length`, `Connection` atlanır
|
||
- Upstream hatasında client `502 Bad Gateway` alır
|
||
- DB loglama bir goroutine içinde çalışır, asla ana isteği bloke etmez
|