first commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
# BifrostTransform
|
||||
|
||||
**Özet:** Anthropic Messages API formatı ile OpenAI Chat Completions formatı arasında çift yönlü dönüşüm yapan katman (`internal/transform/anthropic_bifrost.go:74`). "Bifrost" (İskandinav mitolojisindeki köprü) adı, two-way dönüşümü simgeler.
|
||||
|
||||
**Kütüphaneler:** Go `encoding/json`, `strings`
|
||||
|
||||
**Bağlantılar:** [[AnthropicHandler]], [[Index]]
|
||||
|
||||
## Struct'lar
|
||||
|
||||
### Anthropic Format (Giriş/Çıkış)
|
||||
|
||||
| Struct | Alanlar |
|
||||
|---|---|
|
||||
| `AnthropicRequest` | `Model`, `MaxTokens`, `Messages []AnthropicMessage`, `System`, `Stream` |
|
||||
| `AnthropicMessage` | `Role`, `Content` |
|
||||
| `AnthropicResponse` | `ID`, `Type`, `Role`, `Content []AnthropicContent`, `Model`, `StopReason`, `StopSequence` |
|
||||
| `AnthropicContent` | `Type`, `Text` |
|
||||
|
||||
### OpenAI / Bifrost Format (Ara Katman)
|
||||
|
||||
| Struct | Alanlar |
|
||||
|---|---|
|
||||
| `BifrostRequest` | `Model`, `Messages []BifrostMessage`, `MaxTokens`, `Stream` |
|
||||
| `BifrostMessage` | `Role`, `Content` |
|
||||
| `BifrostResponse` | `ID`, `Object`, `Created`, `Model`, `Choices[{Message{Role,Content}, FinishReason, Index}]` |
|
||||
|
||||
## Dönüşüm Detayları
|
||||
|
||||
### Anthropic → OpenAI (`AnthropicToBifrost()`)
|
||||
|
||||
```
|
||||
Anthropic Request OpenAI Request
|
||||
───────────────── ─────────────
|
||||
model: "claude-3-5-sonnet" → model: "Anthropic/claude-3-5-sonnet"
|
||||
system: "Be helpful" → messages: [{role:"system", ...}, ...]
|
||||
messages: [{role, content}] → messages: [{role, content}]
|
||||
max_tokens: 1024 → max_tokens: 1024
|
||||
stream: true → stream: true
|
||||
```
|
||||
|
||||
### OpenAI → Anthropic (`BifrostToAnthropic()`)
|
||||
|
||||
```
|
||||
OpenAI Response Anthropic Response
|
||||
─────────────── ─────────────────
|
||||
id: "chatcmpl-xxx" → id: "chatcmpl-xxx"
|
||||
choices[].message.content → content: [{type:"text", text:"..."}]
|
||||
choices[].finish_reason → stop_reason: "stop"/"end_turn"
|
||||
model → model (same)
|
||||
```
|
||||
|
||||
## Model Prefix Tahmini (`guessProvider()`)
|
||||
|
||||
| Model içerir | Prefix | Örnek |
|
||||
|---|---|---|
|
||||
| `deepseek` | `DeepSeek/` | `deepseek-v4` → `DeepSeek/deepseek-v4` |
|
||||
| `gpt`, `openai` | `OpenAI/` | `gpt-4` → `OpenAI/gpt-4` |
|
||||
| `claude`, `anthropic` | `Anthropic/` | `claude-3` → `Anthropic/claude-3` |
|
||||
| `gemini` | `Google/` | `gemini-pro` → `Google/gemini-pro` |
|
||||
| diğer | `DeepSeek/` (varsayılan) | — |
|
||||
Reference in New Issue
Block a user