I tried connecting to Chat GPT with the following web instructions and get the error as reflected ...
prompt = 'What is the capital of France?'; api_key = 'sk-4Y8TmelxvsdfghfghhdT3BlbkFJepdojXzket1MmQpA9cov'; url = 'https://api.openai.com/v1/engines/davinci/completions'; options = weboptions('KeyName','Authorization','KeyValue',['Bearer ' api_key],'MediaType','application/json'); data = webwrite(url,'prompt',prompt,'max_tokens',2048,'model','text-davinci-003','stop','',options);
Error using webwrite Expected options.MediaType to be 'application/x-www-form-urlencoded' for Name-Value pairs. Either set options.MediaType to 'application/x-www-form-urlencoded' or create a single encoded string from the Name-Value pairs.
answer = loadjson(data); answer = answer.choices{1}.text; disp(answer)
I have been researching the davinci/completions space and have working MATLAB code using net http. Get your API Key at OpenAPI:
import matlab.net.* import matlab.net.http.* % Define the API endpoint Davinci api_endpoint = "https://api.openai.com/v1/engines/davinci/completions"; % Define the API key from https://beta.openai.com/account/api-keys api_key = "XXXYYYZZZ"; % Define the parameters for the API request prompt = "How many tablespoons are in 2 cups?" parameters = struct('prompt',prompt, 'max_tokens',100); % Define the headers for the API request headers = matlab.net.http.HeaderField('Content-Type', 'application/json'); headers(2) = matlab.net.http.HeaderField('Authorization', ['Bearer ' + api_key]); % Define the request message request = matlab.net.http.RequestMessage('post',headers,parameters); % Send the request and store the response response = send(request, URI(api_endpoint)); % Extract the response text response_text = response.Body.Data; response_text = response_text.choices(1).text; disp(response_text);
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.