Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API应该如何请求? #77

Closed
QC2168 opened this issue May 12, 2024 · 0 comments
Closed

API应该如何请求? #77

QC2168 opened this issue May 12, 2024 · 0 comments

Comments

@QC2168
Copy link

QC2168 commented May 12, 2024

我根据readme.md的描述发出请求,得到的是状态码400

fetch('https://burn.hair/v1/chat/completions', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json' // 根据API要求可选添加
  },
  data:{
    model: 'gpt-3.5-turbo-0613',
    messages: [
      {
        role: 'user',
        content: '你好'
      }
    ]
  }
})
.then(response => {
  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`);
  }
  return response.json(); // 或者.text()取决于响应类型
})
.then(data => {
  console.log('请求成功,返回的数据:', data);
})
.catch(error => {
  console.error('请求发生错误:', error);
});
@QC2168 QC2168 closed this as completed May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant