(
providerConfig: ProviderConfig,
model: string,
question: string,
images: AIContentPart[],
modeConfig: ProviderModeConfig,
systemPrompt: string,
token?: AbortToken,
isSearch = false,
)
| 2757 | |
| 2758 | private async callOpenAIChatOrSearch( |
| 2759 | providerConfig: ProviderConfig, |
| 2760 | model: string, |
| 2761 | question: string, |
| 2762 | images: AIContentPart[], |
| 2763 | modeConfig: ProviderModeConfig, |
| 2764 | systemPrompt: string, |
| 2765 | token?: AbortToken, |
| 2766 | isSearch = false, |
| 2767 | ): Promise<{ |
| 2768 | text: string; |
| 2769 | sources: Array<{ url: string; title?: string }>; |
| 2770 | images: AIImage[]; |
| 2771 | }> { |
| 2772 | const url = providerConfig.responses |
| 2773 | ? resolveResponsesEndpointUrl(providerConfig, modeConfig) |
| 2774 | : resolveEndpointUrl( |
| 2775 | resolveBaseUrl(providerConfig, modeConfig), |
| 2776 | modeConfig.endpoint || "chat/completions", |
| 2777 | ); |
| 2778 | const authMode = resolveAuthMode( |
| 2779 | getProviderProfile(providerConfig), |
| 2780 | modeConfig, |
| 2781 | providerConfig, |
| 2782 | ); |
| 2783 | |
| 2784 | const imageUrlPolicy = modeConfig.imageUrlPolicy ?? "any"; |
| 2785 | const safeImages = |
| 2786 | imageUrlPolicy === "data-only" |
| 2787 | ? images.filter( |
| 2788 | (part) => |
| 2789 | part.type === "image_url" && !!parseDataUrl(part.image_url.url), |
| 2790 | ) |
| 2791 | : images; |
| 2792 | |
| 2793 | const authConfig = applyAuthConfig(authMode, providerConfig, url, { |
| 2794 | "Content-Type": "application/json", |
| 2795 | }); |
| 2796 | |
| 2797 | const sys = (systemPrompt || "").trim(); |
| 2798 | let data: any; |
| 2799 | |
| 2800 | if (providerConfig.responses) { |
| 2801 | const inputContent = buildResponsesInputContent(question, safeImages); |
| 2802 | data = { |
| 2803 | model, |
| 2804 | input: |
| 2805 | inputContent.length > 0 |
| 2806 | ? [{ role: "user", content: inputContent }] |
| 2807 | : question, |
| 2808 | stream: providerConfig.stream, |
| 2809 | }; |
| 2810 | if (sys) data.instructions = sys; |
| 2811 | if (isSearch) { |
| 2812 | data.tools = [{ type: "web_search" }]; |
| 2813 | data.include = ["web_search_call.action.sources"]; |
| 2814 | } |
| 2815 | } else { |
| 2816 | const messages: any[] = []; |
no test coverage detected