mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-06-05 13:58:15 +02:00
feat: add Claude API bridge - transparent OpenAI-to-Anthropic protocol conversion
When provider is set to "claude" in config, all OpenAI-compatible API calls are automatically bridged to Anthropic Claude Messages API, including: - Non-streaming and streaming chat completions - Tool calls (function calling) with full bidirectional conversion - Eino multi-agent via HTTP transport hook (claudeRoundTripper) - System message extraction, auth header conversion (Bearer → x-api-key) - SSE stream format conversion (content_block_delta → OpenAI delta) - TestOpenAI handler support for Claude connectivity testing Zero impact when provider is "openai" or empty (default behavior unchanged). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -64,6 +64,9 @@ func (c *Client) ChatCompletion(ctx context.Context, payload interface{}, out in
|
||||
if strings.TrimSpace(c.config.APIKey) == "" {
|
||||
return fmt.Errorf("openai api key is empty")
|
||||
}
|
||||
if c.isClaude() {
|
||||
return c.claudeChatCompletion(ctx, payload, out)
|
||||
}
|
||||
|
||||
baseURL := strings.TrimSuffix(c.config.BaseURL, "/")
|
||||
if baseURL == "" {
|
||||
@@ -156,6 +159,9 @@ func (c *Client) ChatCompletionStream(ctx context.Context, payload interface{},
|
||||
if strings.TrimSpace(c.config.APIKey) == "" {
|
||||
return "", fmt.Errorf("openai api key is empty")
|
||||
}
|
||||
if c.isClaude() {
|
||||
return c.claudeChatCompletionStream(ctx, payload, onDelta)
|
||||
}
|
||||
|
||||
baseURL := strings.TrimSuffix(c.config.BaseURL, "/")
|
||||
if baseURL == "" {
|
||||
@@ -294,6 +300,9 @@ func (c *Client) ChatCompletionStreamWithToolCalls(
|
||||
if strings.TrimSpace(c.config.APIKey) == "" {
|
||||
return "", nil, "", fmt.Errorf("openai api key is empty")
|
||||
}
|
||||
if c.isClaude() {
|
||||
return c.claudeChatCompletionStreamWithToolCalls(ctx, payload, onContentDelta)
|
||||
}
|
||||
|
||||
baseURL := strings.TrimSuffix(c.config.BaseURL, "/")
|
||||
if baseURL == "" {
|
||||
|
||||
Reference in New Issue
Block a user