first commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
# OpenAIHandler
|
||||
|
||||
**Özet:** `/v1/*` route'unu karşılar (`handlers/openai.go:29`), gelen istekleri olduğu gibi `OPENAI_BACKEND` adresine iletir. OpenAI-compatible bir proxy'dir.
|
||||
|
||||
**Kütüphaneler:** Fiber v3, GORM, Go `net/http`
|
||||
|
||||
**Bağlantılar:** [[Main]], [[ProxyEngine]], [[RequestLog]], [[Config]], [[OpenAI Flow]]
|
||||
|
||||
## Davranış
|
||||
|
||||
1. Gelen isteği alır, header'ları `net/http.Header` formatına çevirir (`fiberToHTTPHeaders()`)
|
||||
2. Eğer `OPENAI_KEY` tanımlanmışsa ve client Authorization göndermemişse, otomatik ekler
|
||||
3. [[ProxyEngine]] ile isteği `OPENAI_BACKEND + originalURL` adresine forward eder
|
||||
4. Response header'larını kopyalar (`copyResponseHeaders()` — Transfer-Encoding, Content-Length, Connection atlanır)
|
||||
5. Yanıtı olduğu gibi client'a döndürür
|
||||
6. [[RequestLog]]'a fire-and-forget goroutine ile kayıt ekler
|
||||
|
||||
## Endpoint
|
||||
|
||||
```
|
||||
ANY /v1/chat/completions
|
||||
ANY /v1/models
|
||||
Authorization: Bearer <api-key>
|
||||
```
|
||||
|
||||
## Yardımcı Fonksiyonlar
|
||||
|
||||
| Fonksiyon | Açıklama |
|
||||
|---|---|
|
||||
| `fiberToHTTPHeaders(c fiber.Ctx) http.Header` | Fiber header'larını `net/http` formatına çevirir |
|
||||
| `copyResponseHeaders(c fiber.Ctx, headers http.Header)` | Upstream response header'larını Fiber response'a kopyalar (hop-by-hop atlanır) |
|
||||
|
||||
## Hata Durumu
|
||||
|
||||
- Upstream hatasında → `502 Bad Gateway` + hata mesajı
|
||||
- Loglama hatası → ana isteği etkilemez (fire-and-forget)
|
||||
Reference in New Issue
Block a user