( ctx context.Context, systemPrompt string, messages []map[string]any, opts CompleteOptions, )
| 606 | out <- EventResult{Event: map[string]any{"type": "stop_reason", "stop_reason": stopReason}} |
| 607 | } |
| 608 | return true |
| 609 | }) |
| 610 | if err != nil { |
| 611 | out <- EventResult{Err: err} |
| 612 | } |
| 613 | }() |
| 614 | |
| 615 | return out |
| 616 | } |
| 617 | |
| 618 | type OpenAICompatibleClient struct { |
| 619 | LLMClientBase |
| 620 | } |
| 621 | |
| 622 | var _ LLMClient = (*OpenAICompatibleClient)(nil) |
| 623 | |
| 624 | func (c *OpenAICompatibleClient) buildHeaders() map[string]string { |
| 625 | return map[string]string{ |
| 626 | "Authorization": "Bearer " + c.APIKey, |
| 627 | "Content-Type": "application/json", |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | func (c *OpenAICompatibleClient) chatCompletionsURL() string { |
| 632 | baseURL := strings.TrimRight(c.BaseURL, "/") |
| 633 | if strings.HasSuffix(baseURL, "/chat/completions") { |
| 634 | return baseURL |
| 635 | } |
| 636 | if strings.HasSuffix(baseURL, "/v1") { |
| 637 | baseURL = strings.TrimSuffix(baseURL, "/v1") |
| 638 | } |
| 639 | return baseURL + "/chat/completions" |
| 640 | } |
| 641 | |
| 642 | func (c *OpenAICompatibleClient) buildMessages(systemPrompt string, messages []map[string]any) []map[string]any { |
| 643 | converted := convertAnthropicMessagesToOpenAI(messages) |
| 644 | result := make([]map[string]any, 0, len(converted)+1) |
| 645 |
nothing calls this directly
no test coverage detected