#What is the endpoint URL for GPT 3.5 Turbo?

6 messages · Page 1 of 1 (latest)

wheat ember
#

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()

}`

oak vine
#

Did you even look at the open ai documentation?

wheat ember
# oak vine Did you even look at the open ai documentation?

Yeah but if i use this i get "Invalid API response". let endpoint = URL(string: "https://api.openai.com/v1/chat/completions")! let headers = ["Content-Type": "application/json", "Authorization": "Bearer sk-", "model": "gpt-3.5-turbo"]

oak vine
wheat ember
oak vine
#

Well, share the whole request them, because there's clearly something being wrong.