Skip to content

Commit

Permalink
use kserve llm as base template instead of sentiment classifier (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
jairad26 authored Sep 17, 2024
1 parent d61252e commit f9ab303
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
28 changes: 16 additions & 12 deletions functions/assembly/index.ts
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();
}
6 changes: 3 additions & 3 deletions hypermode.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"$schema": "https://manifest.hypermode.com/hypermode.json",
"models": {
// Models used by your Hypermode project are defined here.
// As an example, the particular model below is a sentiment classifier from Hugging Face,
// As an example, the particular model below is Meta's Llama 3.1 8B LLM from Hugging Face,
// which is hosted on Hypermode and used in the starter function in this repository.
// You can update or remove this model as needed.
"sentiment-classifier": {
"sourceModel": "distilbert/distilbert-base-uncased-finetuned-sst-2-english",
"text-generator": {
"sourceModel": "meta-llama/Meta-Llama-3.1-8B-Instruct",
"provider": "hugging-face",
"host": "hypermode"
}
Expand Down

0 comments on commit f9ab303

Please sign in to comment.