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

XRequest等工具希望支持配置请求头 #369

Open
whz2008888 opened this issue Dec 17, 2024 · 2 comments
Open

XRequest等工具希望支持配置请求头 #369

whz2008888 opened this issue Dec 17, 2024 · 2 comments

Comments

@whz2008888
Copy link

whz2008888 commented Dec 17, 2024

需求动机

有些时候流式需要使用 Bearer token进行校验,但XRequest中提供的自定义fetch,使用起来XRequestCallbacks监测不到,如果要实现带入token如下段代码

const AIRequest = XRequest({
       fetch: ()=>fetch('BASE_URL + PATH', {  
           method:'POST',
           body: JSON.stringify({text:'hello'}),
           headers: {
               'Authorization': `Bearer ${getCookie('access_token')}`,
               "Content-Type": "application/json"
           },
       }),
     });

提议的 API 是什么样的?

希望改进为

 const AIRequest = XRequest({
         baseURL: BASE_URL + PATH,
         model: MODEL,
         baseURL:'https://???????',
         headers: {
                'Authorization': `Bearer ${getCookie('access_token')}`,
                "Content-Type": "application/json"
            },
      });
    
@YumoImer
Copy link
Collaborator

使用起来XRequestCallbacks监测不到

这个问题应该不存在,可能我理解有误。请再详细补充说明下。

@YumoImer
Copy link
Collaborator

XRequest中提供的自定义fetch

fetch 感觉可以解决你的问题「配置请求头」。

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

2 participants