Skip to content

Commit

Permalink
write finetuning json
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdai committed Sep 21, 2024
1 parent a620fd0 commit f8d8e33
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ __pycache__
data
notebooks
.DS_Store
finetuning_examples
16 changes: 15 additions & 1 deletion arc_finetuning_st/finetuning/finetuning_example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from typing import Annotated, Any, Callable, List
from pathlib import Path
from typing import Annotated, Any, Callable, List, Optional

from llama_index.core.base.llms.types import ChatMessage, MessageRole
from llama_index.core.bridge.pydantic import BaseModel, WrapSerializer
Expand All @@ -12,6 +13,8 @@
)
from arc_finetuning_st.workflows.models import Attempt

DEFAULT_OUTPUT_DIRNAME = "finetuning_examples"


def remove_additional_kwargs(value: Any, handler: Callable, info: Any) -> Any:
partial_result = handler(value, info)
Expand Down Expand Up @@ -67,3 +70,14 @@ def from_attempts(
def to_json(self) -> str:
data = self.model_dump()
return json.dumps(data, indent=4)

def write_json(
self,
dirpath: Optional[Path] = None,
dirname: str = DEFAULT_OUTPUT_DIRNAME,
) -> None:
data = self.model_dump()
dir = Path(dirpath or Path(__file__).parents[2].absolute(), dirname)
dir.mkdir(exist_ok=True, parents=True)
with open(Path(dir, "test.json"), "w") as f:
json.dump(data, f)
7 changes: 5 additions & 2 deletions arc_finetuning_st/streamlit/controller.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import json
import logging
import uuid
from os import listdir
Expand Down Expand Up @@ -146,8 +147,6 @@ def task_file_names(self) -> List[str]:
return listdir(self._data_path)

def load_task(self, selected_task: str) -> Any:
import json

task_path = Path(self._data_path, selected_task)

with open(task_path) as f:
Expand Down Expand Up @@ -256,6 +255,10 @@ def _display_finetuning_example() -> None:
save_col, close_col = st.columns([1, 1])
with save_col:
if st.button("Save", use_container_width=True):
finetuning_example.write_json()
st.success(
"Successfully saved finetuning example."
)
st.session_state.show_finetuning_preview_dialog = (
False
)
Expand Down

0 comments on commit f8d8e33

Please sign in to comment.