@@ -185,61 +185,63 @@ fn is_valid_model(client: &Client, api_key: Option<&str>, args: &Args) -> CliRes
185
185
186
186
fn get_prompt_file ( args : & Args ) -> CliResult < PromptFile > {
187
187
// Get prompt file if --prompt-file is used
188
- let prompt_file = if let Some ( prompt_file) = args. flag_prompt_file . clone ( ) {
189
- // Read prompt file
190
- let prompt_file = fs:: read_to_string ( prompt_file) ?;
191
- // Try to parse prompt file as JSON, if error then show it in JSON format
192
- let prompt_file: PromptFile = match serde_json:: from_str ( & prompt_file) {
193
- Ok ( val) => val,
194
- Err ( e) => {
195
- let error_json = json ! ( { "error" : e. to_string( ) } ) ;
196
- return fail_clierror ! ( "{error_json}" ) ;
197
- } ,
198
- } ;
199
- prompt_file
200
- }
201
- // Otherwise, get default prompt file
202
- else {
203
- #[ allow( clippy:: let_and_return) ]
204
- let default_prompt_file = PromptFile {
205
- name : "My Prompt File" . to_string ( ) ,
206
- description : "My prompt file for qsv's describegpt command." . to_string ( ) ,
207
- author : "My Name" . to_string ( ) ,
208
- version : "1.0.0" . to_string ( ) ,
209
- tokens : 50 ,
210
- dictionary_prompt : "Here are the columns for each field in a data dictionary:\n \n - \
211
- Type: the data type of this column\n - Label: a human-friendly \
212
- label for this column\n - Description: a full description for \
213
- this column (can be multiple sentences)\n \n Generate a data \
214
- dictionary as aforementioned (in JSON output) where each field \
215
- has Name, Type, Label, and Description (so four columns in \
216
- total) based on the following summary statistics and frequency \
217
- data from a CSV file.\n \n Summary \
218
- Statistics:\n \n {stats}\n \n Frequency:\n \n {frequency}"
219
- . to_string ( ) ,
220
- description_prompt : "Generate only a description that is within 8 sentences about the \
221
- entire dataset{json_add} based on the following summary \
222
- statistics and frequency data derived from the CSV file it came \
223
- from.\n \n Summary \
224
- Statistics:\n \n {stats}\n \n Frequency:\n \n {frequency}\n \n Do not \
225
- output the summary statistics for each field. Do not output the \
226
- frequency for each field. Do not output data about each field \
227
- individually, but instead output about the dataset as a whole in \
228
- one 1-8 sentence description."
229
- . to_string ( ) ,
230
- tags_prompt : "A tag is a keyword or label that categorizes datasets with \
231
- other, similar datasets. Using the right tags makes it easier \
232
- for others to find and use datasets.\n \n Generate single-word \
233
- tags{json_add} about the dataset (lowercase only and remove all \
234
- whitespace) based on the following summary statistics and \
235
- frequency data from a CSV file.\n \n Summary \
236
- Statistics:\n \n {stats}\n \n Frequency:\n \n {frequency}"
237
- . to_string ( ) ,
238
- json : true ,
239
- jsonl : false ,
188
+ let prompt_file =
189
+ if let Some ( prompt_file) = args. flag_prompt_file . clone ( ) {
190
+ // Read prompt file
191
+ let prompt_file = fs:: read_to_string ( prompt_file) ?;
192
+ // Try to parse prompt file as JSON, if error then show it in JSON format
193
+ let prompt_file: PromptFile = match serde_json:: from_str ( & prompt_file) {
194
+ Ok ( val) => val,
195
+ Err ( e) => {
196
+ let error_json = json ! ( { "error" : e. to_string( ) } ) ;
197
+ return fail_clierror ! ( "{error_json}" ) ;
198
+ } ,
199
+ } ;
200
+ prompt_file
201
+ }
202
+ // Otherwise, get default prompt file
203
+ else {
204
+ #[ allow( clippy:: let_and_return) ]
205
+ let default_prompt_file = PromptFile {
206
+ name : "My Prompt File" . to_string ( ) ,
207
+ description : "My prompt file for qsv's describegpt command." . to_string ( ) ,
208
+ author : "My Name" . to_string ( ) ,
209
+ version : "1.0.0" . to_string ( ) ,
210
+ tokens : 50 ,
211
+ dictionary_prompt : "Here are the columns for each field in a data \
212
+ dictionary:\n \n - Type: the data type of this column\n - \
213
+ Label: a human-friendly label for this column\n - \
214
+ Description: a full description for this column (can be \
215
+ multiple sentences)\n \n Generate a data dictionary as \
216
+ aforementioned (in JSON output) where each field has Name, \
217
+ Type, Label, and Description (so four columns in total) \
218
+ based on the following summary statistics and frequency data \
219
+ from a CSV file.\n \n Summary \
220
+ Statistics:\n \n {stats}\n \n Frequency:\n \n {frequency}"
221
+ . to_string ( ) ,
222
+ description_prompt : "Generate only a description that is within 8 sentences about \
223
+ the entire dataset{json_add} based on the following summary \
224
+ statistics and frequency data derived from the CSV file it \
225
+ came from.\n \n Summary \
226
+ Statistics:\n \n {stats}\n \n Frequency:\n \n {frequency}\n \n Do \
227
+ not output the summary statistics for each field. Do not \
228
+ output the frequency for each field. Do not output data \
229
+ about each field individually, but instead output about the \
230
+ dataset as a whole in one 1-8 sentence description."
231
+ . to_string ( ) ,
232
+ tags_prompt : "A tag is a keyword or label that categorizes datasets with \
233
+ other, similar datasets. Using the right tags makes it \
234
+ easier for others to find and use datasets.\n \n Generate \
235
+ single-word tags{json_add} about the dataset (lowercase only \
236
+ and remove all whitespace) based on the following summary \
237
+ statistics and frequency data from a CSV file.\n \n Summary \
238
+ Statistics:\n \n {stats}\n \n Frequency:\n \n {frequency}"
239
+ . to_string ( ) ,
240
+ json : true ,
241
+ jsonl : false ,
242
+ } ;
243
+ default_prompt_file
240
244
} ;
241
- default_prompt_file
242
- } ;
243
245
Ok ( prompt_file)
244
246
}
245
247
@@ -297,18 +299,19 @@ fn get_completion(
297
299
}
298
300
299
301
// If --max-tokens is specified, use it
300
- let max_tokens = if arg_is_some ( "--max-tokens" ) {
301
- args. flag_max_tokens
302
- }
303
- // If --prompt-file is used, use the tokens field from the prompt file
304
- else if args. flag_prompt_file . clone ( ) . is_some ( ) {
305
- let prompt_file = get_prompt_file ( args) ?;
306
- prompt_file. tokens
307
- }
308
- // Else use the default max tokens value in USAGE
309
- else {
310
- args. flag_max_tokens
311
- } ;
302
+ let max_tokens =
303
+ if arg_is_some ( "--max-tokens" ) {
304
+ args. flag_max_tokens
305
+ }
306
+ // If --prompt-file is used, use the tokens field from the prompt file
307
+ else if args. flag_prompt_file . clone ( ) . is_some ( ) {
308
+ let prompt_file = get_prompt_file ( args) ?;
309
+ prompt_file. tokens
310
+ }
311
+ // Else use the default max tokens value in USAGE
312
+ else {
313
+ args. flag_max_tokens
314
+ } ;
312
315
313
316
// Create request data
314
317
let request_data = json ! ( {
0 commit comments