gpt4 book ai didi

sas - ChatGPT API 在 SAS 中集成时出错。无效的上下文类型 header

转载 作者:行者123 更新时间:2023-12-02 05:48:41 38 4
gpt4 key购买 nike

我想将chatgpt集成到sas中,但是当我执行代码时,出现如图所示的错误。

显示的错误消息是> Invalid-COntent Type header。扩展的 application/json。

enter image description here

%let chatgpt_api_token = sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
%let chatgpt_api_url = "https://api.openai.com/v1/chat/completions";
%let chat_prompt = "Hello, how can I assist you?";

/* Define the SAS macro to interact with the ChatGPT API */
%macro chat_with_gpt(prompt);
/* Prepare the JSON payload for the API request */
filename payload temp;
data null;
file payload;
put '{ "prompt": "' &prompt '", "max_tokens": 50, "model": "gpt-3.5-turbo" }';
run;

/* Submit the API request using PROC HTTP */
filename response temp;
proc http
method="POST"
url=&chatgpt_api_url
in=payload
out=response
headerout=header;
headers "Authorization" = "Bearer &chatgpt_api_token"
"Content-Type" = "application/json";
run;
/* Read the API response and save it to a SAS dataset */
data chatgpt_response;
infile response;
input;
put infile;
/* Parse the JSON response and store it in a variable */
response = infile;
run;

/* Display the API response in the SAS log */
proc print data=chatgpt_response;
run;
%mend;

/* Call the macro to initiate a chat with ChatGPT */
%chat_with_gpt(&chat_prompt);

尝试了不同的解决方案

最佳答案

您检查过您创建的有效负载吗?

put 语句上下文中宏变量的解析不会加倍,而不是 json 选项 prompt 的值。

尝试

%let chat_prompt = '"Hello, how can I assist you?"';

关于sas - ChatGPT API 在 SAS 中集成时出错。无效的上下文类型 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76297924/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com