Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions packages/tasks/src/model-libraries-snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,11 +788,11 @@ export const transformers = (model: ModelData): string[] => {
if (model.pipeline_tag && LIBRARY_TASK_MAPPING.transformers?.includes(model.pipeline_tag)) {
const pipelineSnippet = ["# Use a pipeline as a high-level helper", "from transformers import pipeline", ""];

if (model.tags.includes("conversational") && model.config?.tokenizer_config?.chat_template) {
if (model.tags?.includes("conversational") && model.config?.tokenizer_config?.chat_template) {
pipelineSnippet.push("messages = [", ' {"role": "user", "content": "Who are you?"},', "]");
}
pipelineSnippet.push(`pipe = pipeline("${model.pipeline_tag}", model="${model.id}"` + remote_code_snippet + ")");
if (model.tags.includes("conversational") && model.config?.tokenizer_config?.chat_template) {
if (model.tags?.includes("conversational") && model.config?.tokenizer_config?.chat_template) {
pipelineSnippet.push("pipe(messages)");
}

Expand Down
4 changes: 2 additions & 2 deletions packages/tasks/src/snippets/curl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const snippetBasic = (model: ModelDataMinimal, accessToken: string): stri
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"`;

export const snippetTextGeneration = (model: ModelDataMinimal, accessToken: string): string => {
if (model.tags.includes("conversational")) {
if (model.tags?.includes("conversational")) {
// Conversational model detected, so we display a code snippet that features the Messages API
return `curl 'https://api-inference.huggingface.co/models/${model.id}/v1/chat/completions' \\
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}" \\
Expand All @@ -28,7 +28,7 @@ export const snippetTextGeneration = (model: ModelDataMinimal, accessToken: stri
};

export const snippetImageTextToTextGeneration = (model: ModelDataMinimal, accessToken: string): string => {
if (model.tags.includes("conversational")) {
if (model.tags?.includes("conversational")) {
// Conversational model detected, so we display a code snippet that features the Messages API
return `curl 'https://api-inference.huggingface.co/models/${model.id}/v1/chat/completions' \\
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}" \\
Expand Down
4 changes: 2 additions & 2 deletions packages/tasks/src/snippets/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ query({"inputs": ${getModelInputSnippet(model)}}).then((response) => {
});`;

export const snippetTextGeneration = (model: ModelDataMinimal, accessToken: string): string => {
if (model.tags.includes("conversational")) {
if (model.tags?.includes("conversational")) {
// Conversational model detected, so we display a code snippet that features the Messages API
return `import { HfInference } from "@huggingface/inference";

Expand All @@ -43,7 +43,7 @@ for await (const chunk of inference.chatCompletionStream({
};

export const snippetImageTextToTextGeneration = (model: ModelDataMinimal, accessToken: string): string => {
if (model.tags.includes("conversational")) {
if (model.tags?.includes("conversational")) {
// Conversational model detected, so we display a code snippet that features the Messages API
return `import { HfInference } from "@huggingface/inference";

Expand Down
4 changes: 2 additions & 2 deletions packages/tasks/src/snippets/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ export const pythonSnippets: Partial<Record<PipelineType, (model: ModelDataMinim
};

export function getPythonInferenceSnippet(model: ModelDataMinimal, accessToken: string): string {
if (model.pipeline_tag === "text-generation" && model.tags.includes("conversational")) {
if (model.pipeline_tag === "text-generation" && model.tags?.includes("conversational")) {
// Conversational model detected, so we display a code snippet that features the Messages API
return snippetConversational(model, accessToken);
} else if (model.pipeline_tag === "image-text-to-text" && model.tags.includes("conversational")) {
} else if (model.pipeline_tag === "image-text-to-text" && model.tags?.includes("conversational")) {
// Example sending an image to the Message API
return snippetConversationalWithImage(model, accessToken);
} else {
Expand Down
Loading