MCPcopy
hub / github.com/Bistutu/FluentRead / common

Function common

entrypoints/service/common.ts:7–38  ·  view source on GitHub ↗
(message: any)

Source from the content-addressed store, hash-verified

5import { services } from "../utils/option";
6
7async function common(message: any) {
8 try {
9
10 const headers = new Headers({
11 'Content-Type': 'application/json',
12 'Authorization': `Bearer ${config.token[config.service]}`
13 });
14
15 if(config.service === services.openrouter){
16 headers.append('HTTP-Referer', 'https://fluent.thinkstu.com');
17 headers.append('X-Title', 'FluentRead');
18 }
19
20 const url = config.proxy[config.service] || urls[config.service];
21
22 const resp = await fetch(url, {
23 method: method.POST,
24 headers,
25 body: commonMsgTemplate(message.origin)
26 });
27
28 if (!resp.ok) {
29 throw new Error(`翻译失败: ${resp.status} ${resp.statusText} body: ${await resp.text()}`);
30 }
31
32 const result = await resp.json();
33 return contentPostHandler(result.choices[0].message.content);
34 } catch (error) {
35 console.error('API调用失败:', error);
36 throw error;
37 }
38}
39
40export default common;

Callers

nothing calls this directly

Calls 2

commonMsgTemplateFunction · 0.90
contentPostHandlerFunction · 0.90

Tested by

no test coverage detected