Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Set up the prompt for ChatGPT to complete
- local prompt = "Hello, ChatGPT! What's your favorite color?"
- -- Set up the headers for the API request
- local headers = {
- ["Content-Type"] = "application/json",
- ["Authorization"] = "Bearer " .. api_key
- }
- -- Set up the request body for the API request
- local body = {
- prompt = prompt,
- max_tokens = 50,
- temperature = 0.5,
- n = 1
- }
- -- Encode the request body as JSON
- local encoded_body = http.encode_json(body)
- -- Send the API request and receive the response
- local response = http.post(endpoint, headers, encoded_body)
- -- Decode the response body from JSON
- local decoded_body = http.decode_json(response.body)
- -- Extract the completed text from the response
- local completed_text = decoded_body.choices[1].text
- -- Print the completed text to the ComputerCraft terminal
- print(completed_text)
Advertisement
Add Comment
Please, Sign In to add comment