Im trying to make a sentence generator using open ai with a simple prompt

look at the code

local API_KEY = "key"

local function generateConversation(prompt)
	local url = "https://api.openai.com/v1/engines/davinci/completions"  -- Use the correct engine name

	local headers = {
		["Authorization"] = "Bearer " .. API_KEY
	}

	local data = {
		prompt = prompt,
		max_tokens = 50,
		temperature = 0.7
	}

	local response = game:GetService("HttpService"):RequestAsync({
		Url = url,
		Method = "POST",
		Headers = headers,
		Body = game:GetService("HttpService"):JSONEncode(data)
	})

	if response.StatusCode == 200 then
		local decodedResponse = game:GetService("HttpService"):JSONDecode(response.Body)
		return decodedResponse.choices[1].text
	else
		print("API Request Error:", response.StatusMessage)
		return "Failed to generate conversation line."
	end
end

local prompt = "Person A: Hey, did you hear about Peter Griffin eating dogs?\nPerson B: What? That's ridiculous!"

local response = generateConversation(prompt)

print(response)

the problem is my brain literally got smaller trying to continue this code so i need a better version

4 Likes