We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
如下是一个调用OpenAI api的controller,请求OpenAI API接口的时候,自定义header带不上。 const Controller = require('egg').Controller;
class OpenAIController extends Controller { async completions() { const param = this.ctx.request.body; const apiUrl = ${this.config.openai.baseUrl}/completions; try { const result = await this.ctx.curl(apiUrl, { method: 'POST', contentType: 'json', headers: { Authorization: Bearer ${this.config.openai.apiKey}}, }, data: param, streaming: param.stream, dataType: 'json', }); this.ctx.status = result.status; this.ctx.set(result.header); this.ctx.body = result.data; } catch (error) { this.ctx.status = 200; this.ctx.body = { error: 'error' }; this.ctx.logger.info('OpenAI API call failed:', error); } } }
${this.config.openai.baseUrl}/completions
Bearer ${this.config.openai.apiKey}}
module.exports = OpenAIController;
如下是抓包的结果: 从抓包的请求中可以看到,并没有自定义headers Authorization 这个请求头,这个是不符合预期的。
归档.zip
V16.20.1
3
无
mac
The text was updated successfully, but these errors were encountered:
注意:上述示例中的代码要运行,需要将config/config.default.js中的apikey字段设置成一个有效的apikey
Sorry, something went wrong.
No branches or pull requests
Your detail info about the Bug:
如下是一个调用OpenAI api的controller,请求OpenAI API接口的时候,自定义header带不上。
const Controller = require('egg').Controller;
class OpenAIController extends Controller {
async completions() {
const param = this.ctx.request.body;
const apiUrl =
${this.config.openai.baseUrl}/completions
;try {
const result = await this.ctx.curl(apiUrl, {
method: 'POST',
contentType: 'json',
headers: {
Authorization:
Bearer ${this.config.openai.apiKey}}
,},
data: param,
streaming: param.stream,
dataType: 'json',
});
this.ctx.status = result.status;
this.ctx.set(result.header);
this.ctx.body = result.data;
} catch (error) {
this.ctx.status = 200;
this.ctx.body = { error: 'error' };
this.ctx.logger.info('OpenAI API call failed:', error);
}
}
}
module.exports = OpenAIController;
如下是抓包的结果:
从抓包的请求中可以看到,并没有自定义headers Authorization 这个请求头,这个是不符合预期的。
Reproduction Repo
归档.zip
Node Version
V16.20.1
Eggjs Version
3
Plugin Name and its version
无
Platform and its version
mac
The text was updated successfully, but these errors were encountered: