MCPcopy Create free account
hub / github.com/OpenAnonymity/oa-chat / formatModels

Method formatModels

chat/api.js:122–180  ·  view source on GitHub ↗
(models)

Source from the content-addressed store, hash-verified

120 baseUrl: this.baseUrl,
121 headers: { Authorization: `Bearer ${key}`, 'Content-Type': 'application/json' }
122 };
123 }
124
125 prepareRequestBody(body, access) {
126 return this.options.prepareRequestBody
127 ? this.options.prepareRequestBody(body, { access, model: this.getModelBudgetMetadata(body.model) })
128 : body;
129 }
130
131 prepareFetchOptions(access, init) {
132 return {
133 ...init,
134 headers: access.headers,
135 ...(init.body ? { body: JSON.stringify(this.prepareRequestBody(JSON.parse(init.body), access)) } : {})
136 };
137 }
138
139 fetchWithRetry(access, url, init, config) {
140 return this.networkTransport.fetchWithRetry(url, this.prepareFetchOptions(access, init), {
141 ...config,
142 proxyConfig: access.proxyConfig || config?.proxyConfig
143 });
144 }
145
146 fetchWithRetryJson(access, url, init, config) {
147 return this.networkTransport.fetchWithRetryJson(url, this.prepareFetchOptions(access, init), {
148 ...config,
149 proxyConfig: access.proxyConfig || config?.proxyConfig
150 });
151 }
152
153 getModelBudgetMetadata(modelId) {
154 const baseId = String(modelId || '').split(':')[0];
155 return this.getCachedModels().find(model => model.id === baseId) || null;
156 }
157
158 sendCompletionStrict(messages, modelId, token, options = {}) {
159 return this.withRequestAccess(token, options, request =>
160 request._sendCompletionStrict(messages, modelId, token, options));
161 }
162
163 generateSessionTitle(prompt, token, options = {}) {
164 if (!this.extractTextContent(prompt).trim()) return Promise.resolve('');
165 return this.withRequestAccess(token, options, request =>
166 request._generateSessionTitle(prompt, token, options));
167 }
168
169 streamCompletion(messages, modelId, token, onChunk, onTokenUpdate, files = [], searchEnabled = false, abortController = null, onStreamOpen = null, onReasoningChunk = null, reasoningEnabled = true, reasoningEffort = DEFAULT_REASONING_EFFORT, onAccessProgress = null) {
170 return this.withRequestAccess(token, {
171 signal: abortController?.signal,
172 onProgress: onAccessProgress
173 }, request => request._streamCompletion(messages, modelId, token, onChunk,
174 onTokenUpdate, files, searchEnabled, abortController, onStreamOpen,
175 onReasoningChunk, reasoningEnabled, reasoningEffort));
176 }
177
178 // Get API key - only use ticket-based key
179 getApiKey() {

Callers 1

fetchModelsMethod · 0.95

Calls 2

capitalizeProviderMethod · 0.95
getDisplayNameMethod · 0.95

Tested by

no test coverage detected