@@ -189,11 +189,7 @@ private extension GenerativeContentRemote {
189189 string: String ,
190190 feature: GenerativeContentRemoteFeature ,
191191 token: JWToken ) async throws -> String {
192- let prompt = [
193- " What is the ISO language code of the language used in the below text? " +
194- " Do not include any explanations and only provide the ISO language code in your response. " ,
195- " Text: ``` \( string) ``` "
196- ] . joined ( separator: " \n " )
192+ let prompt = String ( format: AIRequestPrompts . identifyLanguage, string)
197193 let parameters : [ String : Any ] = [ ParameterKey . token: token. token,
198194 ParameterKey . question: prompt,
199195 ParameterKey . stream: ParameterValue . stream,
@@ -219,73 +215,60 @@ private extension GenerativeContentRemote {
219215 categories: [ ProductCategory ] ,
220216 tags: [ ProductTag ] ,
221217 token: JWToken ) async throws -> AIProduct {
222- var inputComponents = [
223- " You are a WooCommerce SEO and marketing expert, perform in-depth research about the product " +
224- " using the provided name, keywords and tone, and give your response in the below JSON format. " ,
225- " keywords: ``` \( keywords) ``` " ,
226- " tone: ``` \( tone) ``` " ,
227- ]
218+ var inputComponents = [ String ( format: AIRequestPrompts . inputComponents, keywords, tone) ]
228219
229220 // Name will be added only if `productName` is available.
230221 // TODO: this code related to `productName` can be removed after releasing the new product creation with AI flow. Github issue: 13108
231222 if let productName = productName, !productName. isEmpty {
232- inputComponents. insert ( " name: ``` \( productName) ``` " , at: 1 )
223+ inputComponents. insert ( String ( format : AIRequestPrompts . productNameTemplate , productName) , at: 1 )
233224 }
234225
235226 let input = inputComponents. joined ( separator: " \n " )
236227
237228 let jsonResponseFormatDict : [ String : Any ] = {
238229 let tagsPrompt : String = {
239230 guard !tags. isEmpty else {
240- return " Suggest an array of the best matching tags for this product. "
231+ return AIRequestPrompts . defaultTagsPrompt
241232 }
242233
243- return " Given the list of available tags ``` \( tags. map { $0. name } . joined ( separator: " , " ) ) ```, " +
244- " suggest an array of the best matching tags for this product. You can suggest new tags as well. "
234+ return String ( format: AIRequestPrompts . existingTagsPrompt, tags. map { $0. name } . joined ( separator: " , " ) )
245235 } ( )
246236
247237 let categoriesPrompt : String = {
248238 guard !categories. isEmpty else {
249- return " Suggest an array of the best matching categories for this product. "
239+ return AIRequestPrompts . defaultCategoriesPrompt
250240 }
251241
252- return " Given the list of available categories ``` \( categories. map { $0. name } . joined ( separator: " , " ) ) ```, " +
253- " suggest an array of the best matching categories for this product. You can suggest new categories as well. "
242+ return String ( format: AIRequestPrompts . existingCategoriesPrompt, categories. map { $0. name } . joined ( separator: " , " ) )
254243 } ( )
255244
256245 let shippingPrompt = {
257246 var dict = [ String: String] ( )
258247 if let weightUnit {
259- dict [ " weight " ] = " Guess and provide only the number in \( weightUnit) "
248+ dict [ " weight " ] = String ( format : AIRequestPrompts . weightPrompt , weightUnit)
260249 }
261250
262251 if let dimensionUnit {
263- dict [ " length " ] = " Guess and provide only the number in \( dimensionUnit) "
264- dict [ " width " ] = " Guess and provide only the number in \( dimensionUnit) "
265- dict [ " height " ] = " Guess and provide only the number in \( dimensionUnit) "
252+ dict [ " length " ] = String ( format : AIRequestPrompts . lengthPrompt , dimensionUnit)
253+ dict [ " width " ] = String ( format : AIRequestPrompts . widthPrompt , dimensionUnit)
254+ dict [ " height " ] = String ( format : AIRequestPrompts . heightPrompt , dimensionUnit)
266255 }
267256 return dict
268257 } ( )
269258
270259 // swiftlint:disable line_length
271- return [ " names " : " An array of strings, containing three different names of the product, written in the language with ISO code ``` \( language) ``` " ,
272- " descriptions " : " An array of strings, each containing three different product descriptions of around 100 words long each in a ``` \( tone) ``` tone, "
273- + " written in the language with ISO code ``` \( language) ``` " ,
274- " short_descriptions " : " An array of strings, each containing three different short descriptions of the product in a ``` \( tone) ``` tone, "
275- + " written in the language with ISO code ``` \( language) ``` " ,
276- " virtual " : " A boolean value that shows whether the product is virtual or physical " ,
260+ return [ " names " : String ( format: AIRequestPrompts . namesFormat, language) ,
261+ " descriptions " : String ( format: AIRequestPrompts . descriptionsFormat, tone, language) ,
262+ " short_descriptions " : String ( format: AIRequestPrompts . shortDescriptionsFormat, tone, language) ,
263+ " virtual " : AIRequestPrompts . virtualFormat,
277264 " shipping " : shippingPrompt,
278- " price " : " Guess the price in \( currencySymbol) , do not include the currency symbol, "
279- + " only provide the price as a number " ,
265+ " price " : String ( format: AIRequestPrompts . priceFormat, currencySymbol) ,
280266 " tags " : tagsPrompt,
281267 " categories " : categoriesPrompt]
282268 } ( )
283269
284- let expectedJsonFormat =
285- " Your response should be in JSON format and don't send anything extra. " +
286- " Don't include the word JSON in your response: " +
287- " \n " +
288- ( jsonResponseFormatDict. toJSONEncoded ( ) ?? " " )
270+ let expectedJsonFormat = String ( format: AIRequestPrompts . jsonFormatInstructions,
271+ jsonResponseFormatDict. toJSONEncoded ( ) ?? " " )
289272
290273 let prompt = input + " \n " + expectedJsonFormat
291274
0 commit comments