Skip to content

Commit

Permalink
Feature - Default Category (#333)
Browse files Browse the repository at this point in the history
* Update model methods to run background task when creating the endpoint and creating score endpoint for runpod to use

* Handle error from Runpod, URL inference from yaml file

* Update backend/app/api/endpoints/base/score.py

Co-authored-by: Rafael Mosquera <[email protected]>

* Rename method

* rename endpoint

* Print background tasks and correct typo

* Correct typos and correct schemas

* model uid

* remove c

* ad ta to metada (facepalm)

* add update publish status to make change the publish state of the models

* change order of background tasks

* print instead of raising error for the second background task to run

* add show category optional for Generative text

* add functionality to remove user_input in artifacts for generative text

---------

Co-authored-by: Rafael Mosquera <[email protected]>
  • Loading branch information
shincap8 and remg1997 authored Feb 5, 2025
1 parent e54520d commit bd0598d
Showing 1 changed file with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const EvaluateTextsGenerative: FC<
const [signInConsent, setSignInConsent] = useState(true);
const [showInput, setShowInput] = useState(false);
const [showLoader, setShowLoader] = useState(false);
const [showCategory, setShowCategory] = useState(true);
const [showCategory, setShowCategory] = useState(false);
const [finishConversation, setFinishConversation] = useState(false);
const [disabledInput, setDisabledInput] = useState(false);
const [disableTypeOfConversation, setDisableTypeOfConversation] =
Expand All @@ -47,15 +47,15 @@ const EvaluateTextsGenerative: FC<
const [isCreatingTexts, setIsCreatingTexts] = useState(false);
const [isTied, setIsTied] = useState(true);
const [artifactsInput, setArtifactsInput] = useState<any>(
generative_context.artifacts,
generative_context.artifacts
);
const [prompt, setPrompt] = useState(
"Enter text here. Do not copy and paste",
"Enter text here. Do not copy and paste"
);
const { post, response } = useFetch();
const { user } = useContext(UserContext);
const { metadataExample, modelInputs, updateModelInputs } = useContext(
CreateInterfaceContext,
CreateInterfaceContext
);
const neccessaryFields = ["original_prompt", "category"];

Expand Down Expand Up @@ -87,7 +87,7 @@ const EvaluateTextsGenerative: FC<
task_id: taskId,
user_id: user.id,
round_id: realRoundId,
},
}
);
if (response.ok) {
if (redirectUrl) {
Expand All @@ -103,10 +103,6 @@ const EvaluateTextsGenerative: FC<
}
};

useEffect(() => {
checkIfUserReachedNecessaryExamples();
}, []);

const generateTexts = async () => {
if (neccessaryFields.every((item) => modelInputs.hasOwnProperty(item))) {
setIsCreatingTexts(true);
Expand All @@ -129,7 +125,7 @@ const EvaluateTextsGenerative: FC<
generatedTexts.map((text: any) => ({
...text,
score: 50,
})),
}))
);
updateModelInputs({
[field_names_for_the_model.generated_answers ?? "generated_answers"]:
Expand Down Expand Up @@ -179,18 +175,18 @@ const EvaluateTextsGenerative: FC<

const checkIsTied = () => {
const isTied = texts.every(
(text) => text.score === texts[0].score && texts.length > 1,
(text) => text.score === texts[0].score && texts.length > 1
);
setIsTied(isTied);
};

const checkNotAnswers = async (generatedTexts: any) => {
// check if in some of the texts the provider name is None, in that case return True
const notAnswers = generatedTexts.every(
(text: any) => text.provider === "None",
(text: any) => text.provider === "None"
);
const allTheAnswersAreEmpty = generatedTexts.every(
(text: any) => text.text === "\n",
(text: any) => text.text === "\n"
);
return notAnswers || allTheAnswersAreEmpty;
};
Expand All @@ -199,13 +195,13 @@ const EvaluateTextsGenerative: FC<
updateModelInputs({
[field_names_for_the_model.best_answer ?? "best_answer"]: texts.reduce(
(max: { score: number }, answer: { score: number }) =>
answer.score > max.score ? answer : max,
answer.score > max.score ? answer : max
),
});
setBestAnswer(
texts.reduce((max: { score: number }, answer: { score: number }) =>
answer.score > max.score ? answer : max,
),
answer.score > max.score ? answer : max
)
);

setChatHistory({
Expand All @@ -216,7 +212,7 @@ const EvaluateTextsGenerative: FC<
id: "1",
text: texts.reduce(
(max: { score: number }, answer: { score: number }) =>
answer.score > max.score ? answer : max,
answer.score > max.score ? answer : max
).text,
},
],
Expand Down Expand Up @@ -259,6 +255,27 @@ const EvaluateTextsGenerative: FC<
setShowInput(true);
};

useEffect(() => {
checkIfUserReachedNecessaryExamples();
if ("show_category" in artifactsInput) {
setShowCategory(artifactsInput?.show_category);
let category = "Unguided";
if ("default_category" in artifactsInput) {
category = artifactsInput?.default_category;
}
updateModelInputs({
category: category,
});
updateModelInputs({
initial_timestamp: Date.now(),
});
setShowInput(true);
setShowCategory(false);
} else {
setShowCategory(true);
}
}, []);

useEffect(() => {
updateModelInputs({
[field_names_for_the_model.generated_answers ?? "generated_answers"]:
Expand Down

0 comments on commit bd0598d

Please sign in to comment.