Skip to content

Commit

Permalink
first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
Wauplin committed Jan 25, 2024
1 parent de90a9e commit 5912d96
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
5 changes: 5 additions & 0 deletions packages/tasks/src/model-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export interface ModelData {
base_model_name?: string;
task_type?: string;
};
tokenizer?: {
bos_token?: string;
chat_template?: string;
eos_token?: string;
}
};
/**
* all the model tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@
};
$: widgetComponent =
model.pipeline_tag && model.pipeline_tag in WIDGET_COMPONENTS
? WIDGET_COMPONENTS[model.pipeline_tag as keyof typeof WIDGET_COMPONENTS]
: undefined;
model.tags && "conversational" in model.tags
? ConversationalWidget
: model.pipeline_tag && model.pipeline_tag in WIDGET_COMPONENTS
? WIDGET_COMPONENTS[model.pipeline_tag as keyof typeof WIDGET_COMPONENTS]
: undefined;
// prettier-ignore
$: widgetProps = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import type { WidgetProps, ExampleRunOpts, InferenceRunOpts } from "../../shared/types.js";
import { Template } from "@huggingface/jinja";
import type { WidgetExampleTextInput } from "@huggingface/tasks";
import WidgetOutputConvo from "../../shared/WidgetOutputConvo/WidgetOutputConvo.svelte";
Expand Down Expand Up @@ -66,13 +67,27 @@
updateUrl({ text: trimmedText });
}
const requestBody = {
inputs: {
generated_responses: conversation.generated_responses,
past_user_inputs: conversation.past_user_inputs,
text: trimmedText,
},
};
const chat = [
{ role: "user", content: "Hello, how are you?" },
{ role: "assistant", content: "I'm doing great. How can I help you today?" },
{ role: "user", content: "I'd like to show off how chat templating works!" },
];
const chatTemplate = model.config?.tokenizer?.chat_template;
if (chatTemplate === undefined) {
outputJson = "";
output = [];
error = "No chat template found in tokenizer config";
return;
}
const template = new Template(chatTemplate);
const chatText = template.render({
messages: chat,
bos_token: model.config?.tokenizer?.bos_token,
eos_token: model.config?.tokenizer?.eos_token,
});
const requestBody = { inputs: chatText };
addInferenceParameters(requestBody, model);
isLoading = true;
Expand Down

0 comments on commit 5912d96

Please sign in to comment.