I'm currently using DaVinci, I heard 3.5 Turbo is 1/10th the cost but i can't cant the endpoint URL for it anywhere.
`func enhanceRestaurantDescription(inputText: String, restaurantName: String, completion: @escaping (String?, Error?) -> Void) {
// Define the API endpoint URL
let endpoint = URL(string: "https://api.openai.com/v1/engines/text-davinci-003/completions")!
// Define the API request headers
let headers = ["Content-Type": "application/json",
"Authorization": "Bearer sk------------------------------------"]
// Define the API request parameters
let prompt = "Write a polished and more appealing description for \(restaurantName) in first person. The restaurant owner says: \(inputText)"
let parameters: [String: Any] = ["prompt": prompt,
"max_tokens": 256,//64, "n": 1, //"stop": ["\n"]
]
// Create the API request
var request = URLRequest(url: endpoint)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = try! JSONSerialization.data(withJSONObject: parameters)
// Send the API request and handle the response
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
completion(nil, error)
} else if let data = data {
if let response = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let choices = response["choices"] as? [[String: Any]],
let text = choices.first?["text"] as? String {
let rewrittenText = text.replacingOccurrences(of: prompt, with: "").trimmingCharacters(in: .whitespacesAndNewlines)
completion(rewrittenText, nil)
} else {
completion(nil, NSError(domain: "Invalid API response", code: 0, userInfo: nil))
}
}
}
task.resume()
}`