-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use kserve llm as base template instead of sentiment classifier (#79)
- Loading branch information
Showing
2 changed files
with
19 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
import { models } from "@hypermode/functions-as"; | ||
import { ClassificationModel } from "@hypermode/models-as/models/experimental/classification"; | ||
import { | ||
OpenAIChatModel, | ||
SystemMessage, | ||
UserMessage, | ||
} from "@hypermode/models-as/models/openai/chat"; | ||
const modelName = "text-generator"; | ||
|
||
const modelName = "sentiment-classifier"; | ||
const threshold: f32 = 0.5; | ||
export function generateText(text: string): string { | ||
const model = models.getModel<OpenAIChatModel>(modelName); | ||
|
||
export function testClassifier(text: string): string { | ||
const model = models.getModel<ClassificationModel>(modelName); | ||
const input = model.createInput([text]); | ||
const output = model.invoke(input); | ||
const input = model.createInput([ | ||
new SystemMessage("You are a helpful assistant."), | ||
new UserMessage(text), | ||
]); | ||
|
||
input.temperature = 0.7; | ||
|
||
const prediction = output.predictions[0]; | ||
if (prediction.confidence >= threshold) { | ||
return prediction.label; | ||
} | ||
const output = model.invoke(input); | ||
|
||
return ""; | ||
return output.choices[0].message.content.trim(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters