feat: 更新调用grok接口
This commit is contained in:
parent
8cd2cca57a
commit
4aee7f9ffb
2
.env
2
.env
|
|
@ -20,4 +20,4 @@ SILICONFLOW_API_KEY=sk-ojmkkuyrfigcmdlijbirbjaqmuwhhfsddcqdvpvayspqrupc
|
||||||
DEEPSEEK_API_KEY=sk-e8941dc2bf1d4d099001b161db6f4317
|
DEEPSEEK_API_KEY=sk-e8941dc2bf1d4d099001b161db6f4317
|
||||||
|
|
||||||
# Grok
|
# Grok
|
||||||
GROK_API_KEY=xai-hKcnlbz5N2AWSdWYvV29G7iBmiI8FFU3lQLDG25Xw6BGjjhkYGGqPSSjiaxnAySViM3AYiYTeJwFFjJK
|
GROK_API_KEY=lichao1314
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
export const PROVIDER_TYPE = {
|
export const PROVIDER_TYPE = {
|
||||||
Deep: {
|
Deep: {
|
||||||
name: 'Deep',
|
name: 'Deep',
|
||||||
baseUrl: 'https://api.deepseek.com/chat/completions',
|
baseUrl: 'https://api.deepseek.com',
|
||||||
model: 'deepseek-chat',
|
model: 'deepseek-chat',
|
||||||
},
|
},
|
||||||
Flow: {
|
Flow: {
|
||||||
name: 'Flow',
|
name: 'Flow',
|
||||||
baseUrl: 'https://api.siliconflow.cn/v1/chat/completions',
|
baseUrl: 'https://api.siliconflow.cn',
|
||||||
model: 'deepseek-ai/DeepSeek-V3',
|
model: 'deepseek-ai/DeepSeek-V3',
|
||||||
},
|
},
|
||||||
Grok: {
|
Grok: {
|
||||||
name: 'Grok',
|
name: 'Grok',
|
||||||
baseUrl: 'https://api.x.ai/v1/chat/completions',
|
baseUrl: 'http://141.98.197.39:8000',
|
||||||
model: 'grok-2-latest',
|
model: 'grok-4.20-beta',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,14 @@ export class DeepseekService {
|
||||||
|
|
||||||
const apiKey = apiKeys[provider];
|
const apiKey = apiKeys[provider];
|
||||||
|
|
||||||
|
// 使用 OpenAI 接口规范
|
||||||
|
const endpoint = `${baseUrl}/v1/chat/completions`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
baseUrl,
|
endpoint,
|
||||||
{
|
{
|
||||||
|
model,
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
role: 'system',
|
role: 'system',
|
||||||
|
|
@ -34,18 +38,19 @@ export class DeepseekService {
|
||||||
content: message,
|
content: message,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
model,
|
|
||||||
stream: false,
|
stream: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${apiKey}`,
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': `Bearer ${apiKey}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue