MCPcopy Create free account
hub / github.com/pollinations/pollinations / chatCompletion

Function chatCompletion

packages/mcp/src/services/textService.js:78–240  ·  view source on GitHub ↗
(params)

Source from the content-addressed store, hash-verified

76}
77
78async function chatCompletion(params) {
79 requireApiKey();
80
81 const {
82 messages,
83 model = "openai",
84 temperature,
85 max_tokens,
86 top_p,
87 frequency_penalty,
88 presence_penalty,
89 repetition_penalty,
90 seed,
91 stop,
92 response_format,
93 stream = false,
94 stream_options,
95 reasoning_effort,
96 tools,
97 tool_choice,
98 parallel_tool_calls,
99 functions,
100 function_call,
101 modalities,
102 audio,
103 logprobs,
104 top_logprobs,
105 logit_bias,
106 user,
107 } = params;
108
109 if (!messages || !Array.isArray(messages) || messages.length === 0) {
110 throw new Error("Messages array is required and must not be empty");
111 }
112
113 const validation = await validateTextModel(model);
114 if (!validation.valid) {
115 throw new Error(
116 `${validation.error} Did you mean: ${validation.suggestions.join(", ")}? ` +
117 `Use listTextModels to see all ${validation.availableCount} available models.`,
118 );
119 }
120
121 const requestBody = {
122 messages,
123 model,
124 temperature,
125 max_tokens,
126 top_p,
127 frequency_penalty,
128 presence_penalty,
129 repetition_penalty,
130 seed,
131 stop,
132 response_format,
133 stream,
134 stream_options,
135 reasoning_effort,

Callers

nothing calls this directly

Calls 8

requireApiKeyFunction · 0.90
validateTextModelFunction · 0.90
postChatCompletionFunction · 0.90
createTextContentFunction · 0.90
createMCPResponseFunction · 0.90
jsonMethod · 0.80
pushMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected