Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: some props of the model trigger payload had snake_case, fixed them to camelCase #1254

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/console/src/app/(providers)/root-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const RootProvider = ({ children }: { children: React.ReactNode }) => {
const { initPipelineBuilder } = useInstillStore(useShallow(selector));

const initCreateResourceFormStore = useCreateResourceFormStore(
(store) => store.init
(store) => store.init,
);
const closeModal = useModalStore((store) => store.closeModal);

Expand Down
56 changes: 28 additions & 28 deletions packages/toolkit/src/constant/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,33 @@ export const defaultCodeSnippetStyles = {

const taskPayloads = {
TASK_CLASSIFICATION: `"classification": {
"image_url": {your-input-image-url}
"imageUrl": {your-input-image-url}
}`,
TASK_DETECTION: `"detection": {
"image_url": {your-input-image-url}
"imageUrl": {your-input-image-url}
}`,
TASK_KEYPOINT: `"keypoint": {
"image_url": {your-input-image-url}
"imageUrl": {your-input-image-url}
}`,
TASK_OCR: `"ocr": {
"image_url": {your-input-image-url}
"imageUrl": {your-input-image-url}
}`,
TASK_INSTANCE_SEGMENTATION: `"instance_segmentation": {
"image_url": {your-input-image-url}
TASK_INSTANCE_SEGMENTATION: `"instanceSegmentation": {
"imageUrl": {your-input-image-url}
}`,
TASK_SEMANTIC_SEGMENTATION: `"semantic_segmentation": {
"image_url": {your-input-image-url}
TASK_SEMANTIC_SEGMENTATION: `"semanticSegmentation": {
"imageUrl": {your-input-image-url}
}`,
TASK_TEXT_GENERATION: `"text_generation": {
TASK_TEXT_GENERATION: `"textGeneration": {
"prompt": "In this beautiful day,",
"system_message": "you are a helpful assistant",
"max_new_tokens": 1024,
"top_k": 5,
"systemMessage": "you are a helpful assistant",
"maxNewTokens": 1024,
"topK": 5,
"temperature": 0.7
}`,
TASK_TEXT_GENERATION_CHAT: `"text_generation": {
TASK_TEXT_GENERATION_CHAT: `"textGeneration": {
"prompt": "How is the weather today?",
"chat_history": [
"chatHistory": [
{
"role": "user",
"content": [
Expand All @@ -64,36 +64,36 @@ const taskPayloads = {
]
}
],
"system_message": "you are a helpful assistant",
"max_new_tokens": 1024,
"top_k": 5,
"systemMessage": "you are a helpful assistant",
"maxNewTokens": 1024,
"topK": 5,
"temperature": 0.7
}`,
TASK_TEXT_TO_IMAGE: `"text_to_image": {
TASK_TEXT_TO_IMAGE: `"textToImage": {
"prompt": "award winning high resolution photo of a giant tortoise",
"steps": 1,
"cfg_scale": 5.5,
"cfgScale": 5.5,
"seed": 1,
"samples": 1
}`,
TASK_IMAGE_TO_IMAGE: `"image_to_image": {
TASK_IMAGE_TO_IMAGE: `"imageToImage": {
"prompt": "spacedog",
"prompt_image_url": "https://artifacts.instill.tech/imgs/dog.jpg",
"promptImageUrl": "https://artifacts.instill.tech/imgs/dog.jpg",
"steps": 1,
"cfg_scale": 5.5,
"cfgScale": 5.5,
"seed": 1,
"samples": 1
}`,
TASK_VISUAL_QUESTION_ANSWERING: `"visual_question_answering": {
TASK_VISUAL_QUESTION_ANSWERING: `"visualQuestionAnswering": {
"prompt": "what is in the image?",
"prompt_images": [
"promptImages": [
{
"prompt_image_url": "https://artifacts.instill.tech/imgs/dog.jpg"
"promptImageUrl": "https://artifacts.instill.tech/imgs/dog.jpg"
}
],
"system_message": "you are a helpful assistant",
"max_new_tokens": 1024,
"top_k": 5,
"systemMessage": "you are a helpful assistant",
"maxNewTokens": 1024,
"topK": 5,
"temperature": 0.7
}`,
};
Expand Down
8 changes: 8 additions & 0 deletions packages/toolkit/src/lib/convertSentenceToCamelCase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//https://stackoverflow.com/a/71426723/2205002
export const convertSentenceToCamelCase = (str: string) =>
str
.split(" ")
.map((e, i) =>
i ? e.charAt(0).toUpperCase() + e.slice(1).toLowerCase() : e.toLowerCase()
)
.join("");
1 change: 1 addition & 0 deletions packages/toolkit/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export * from "./getCaptializeTwoWordsFromName";
export * from "./convertLongNumberToK";
export * from "./formatNumberToLocale";
export * from "./generateDateInPast";
export * from "./convertSentenceToCamelCase";

import debounce from "lodash.debounce";
export { debounce };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
useLastModelTriggerResult,
useShallow,
useTriggerUserModelAsync,
convertSentenceToCamelCase,
} from "../../../lib";
import { ModelReadme } from "./ModelReadme";
import { z } from "zod";
Expand All @@ -47,7 +48,11 @@ const selector = (store: InstillStore) => ({
});

const convertTaskNameToPayloadPropName = (taskName?: ModelTask) =>
taskName ? taskName.replace("TASK_", "").toLowerCase() : null;
taskName
? convertSentenceToCamelCase(
taskName.replace(/TASK_|_/g, (d) => (d === "TASK_" ? "" : " "))
)
orangecoloured marked this conversation as resolved.
Show resolved Hide resolved
: null;

const convertValuesToString = (props: Record<string, unknown>) => {
const convertedProps: Record<string, unknown> = {};
Expand Down
Loading