You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When developing a new feature, there's an annoying amount of boiler plate I need to write - creating mock data in a json format, creating a stories.tsx file, writing the Props and function definition, and writing the Python function. I think this can mostly be automated, and makes it lower friction to add features. Eg adding a generate_stub_files function to utils. Here's an attempt:
# Split the string into a list of words
words = s.split('_')
# Capitalize the first letter of each word and join them
camel = ''.join([word.capitalize() for word in words])
# Return the first letter in lowercase
return camel[0].lower() + camel[1:]
def snake_to_pascal(s: str) -> str:
# Split the string into a list of words
words = s.split('_')
# Capitalize the first letter of each word and join them
pascal = ''.join([word.capitalize() for word in words])
return pascal
# %%
# Copy and paste to mock file
mock_data = {
"prompt": prompt,
"top_k_log_probs": top_log_probs.tolist(),
"top_k_tokens": top_tokens,
"correct_tokens": correct_tokens,
"correct_token_rank": correct_token_rank,
"correct_token_log_prob": correct_token_log_prob.tolist(),
}
vis_name = "LogProbVis"
mock_types = {
"prompt": "string[]",
"top_k_log_probs": "number[][]",
"top_k_tokens": "string[][]",
"correct_tokens": "string[]",
"correct_token_rank": "number[]",
"correct_token_log_prob": "number[]",
}
print(mock_data)
# %%
s = []
for name in mock_data:
data = mock_data[name]
typ = mock_types[name]
if isinstance(data, torch.Tensor):
data = data.tolist()
print(f"export const {snake_to_camel('mock_'+name)}: {typ} = {data};")
print()
# %%
newline = "\n"
template = f"""import {{ ComponentStory, ComponentMeta }} from "@storybook/react";
import React from "react";
import {{ {", ".join(map(lambda name: snake_to_camel("mock_" + name), mock_data.keys()))} }} from "./mocks/{vis_name[0].lower() + vis_name[1:]}";
import { {vis_name} } from "./{vis_name}";
export default {{
component: {vis_name}
}} as ComponentMeta<typeof {vis_name}>;
const Template: ComponentStory<typeof {vis_name}> = (args) => (
<{vis_name} {{...args}} />
);
export const SmallModelExample = Template.bind({{}});
SmallModelExample.args = {{
{f",{newline} ".join([f"{snake_to_camel(name)}: {snake_to_camel('mock_'+name)}" for name in mock_data])}
}};
"""
print(template)
# %%
func_defn = f"""
export function {vis_name}({{
{f",{newline} ".join(map(snake_to_camel, mock_data.keys()))}
}}: {vis_name}Props) {{
"""
interface = f"""
export interface {vis_name}Props {{
{''';
/**
*/
'''.join([f"{snake_to_camel(name)}: {mock_types[name]}" for name in mock_types])}
}}
"""
print(func_defn)
print()
print()
print()
print(interface)```
The text was updated successfully, but these errors were encountered:
When developing a new feature, there's an annoying amount of boiler plate I need to write - creating mock data in a json format, creating a stories.tsx file, writing the Props and function definition, and writing the Python function. I think this can mostly be automated, and makes it lower friction to add features. Eg adding a
generate_stub_files
function toutils
. Here's an attempt:The text was updated successfully, but these errors were encountered: