import{Gt as e,wn as t,ya as n}from"./training-B42Vc7Pp.js";import{Pn as r}from"./settings-DtMTlq96.js";import{c as i,d as a,f as o}from"./recipes-db-9afCcYaD.js";function s(e){let t=new TextEncoder().encode(e),n=``,r=32768;for(let e=0;e<t.length;e+=r)n+=String.fromCharCode(...t.subarray(e,e+r));return btoa(n)}async function c(e=`openai`){let{lines:t,conversations:c}=await r(e);if(c===0)return n.info(`No chats with a user and assistant exchange to export.`),null;let l=new Date().toISOString().slice(0,10),u=`chat-finetune${e===`openai`?``:`-${e}`}-${l}.jsonl`,d=await o({filename:u,content_base64:s(t.join(`
`)),preview_size:10}),f=a();return f.recipe.seed_config={source:{seed_type:`local`,path:d.resolved_path},sampling_strategy:`ordered`,selection_strategy:null},f.ui.nodes=[{id:`seed`,x:0,y:0,width:400}],f.ui.seed_source_type=`local`,f.ui.seed_columns=d.columns,f.ui.seed_preview_rows=d.preview_rows??[],f.ui.local_file_name=u,(await i({name:`Chat fine-tuning ${l}`,payload:f})).id}async function l(i=`openai`){let{lines:a,conversations:o}=await r(i);if(o===0)return n.info(`No chats with a user and assistant exchange to export.`),!1;let s=new Date().toISOString().slice(0,10),c=i===`openai`?``:`-${i}`,l=await t(new File([a.join(`
`)],`chat-finetune${c}-${s}.jsonl`,{type:`application/x-ndjson`}));return e.getState().selectLocalDataset(l.stored_path),!0}export{c as createFineTuneRecipeFromChats,l as loadFineTuneDatasetInTrainTab};