1 line
1.8 KiB
JSON
1 line
1.8 KiB
JSON
{"repo": "bigwhiteshark/360gpt", "files": {"src/api/index.ts": {"991d8a1dcebd16296a3ebe88e7720be41aa4dfb6": {"t": 1785768138.6715188, "n": 1615, "h": "60f875abd9c1d26b", "c": "import type { ChatMessage, ChatResponse } from '@/types';\nconst apiKey = '';\nconst apiUrl = 'https://api.360.cn/v1/chat/completions';\nexport const chat = async (\n messageList: ChatMessage[]\n): Promise<ChatResponse | undefined> => {\n try {\n const result = await fetch(apiUrl, {\n method: 'post',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey}`,\n },\n body: JSON.stringify({\n model: '360gpt-pro',\n messages: messageList,\n stream: false,\n }),\n });\n return result.json() as Promise<ChatResponse>;\n } catch (err) {\n console.error(err);\n }\n};\n\nexport const chatStream = async (messageList: ChatMessage[]) => {\n try {\n const result = await fetch(apiUrl, {\n method: 'post',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey}`,\n },\n body: JSON.stringify({\n model: '360gpt-pro',\n messages: messageList,\n stream: true,\n }),\n });\n return result;\n } catch (err) {\n console.error(err);\n }\n};\n\n/* export const chat = async (messageList: ChatMessage[]) => {\n try {\n const result = await fetch(apiUrl, {\n method: 'post',\n // signal: AbortSignal.timeout(8000),\n // 开启后到达设定时间会中断流式输出\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey}`,\n },\n body: JSON.stringify({\n model: '360gpt-pro',\n stream: true,\n messages: messageList,\n }),\n });\n return result;\n } catch (error) {\n console.log(error);\n }\n}; */\n"}}}} |