From fa745ebece6d3f5c1cf5dbc518cfabb3dfbc9365 Mon Sep 17 00:00:00 2001 From: Mishig Davaadorj Date: Wed, 20 Nov 2024 10:39:58 +0100 Subject: [PATCH] llama_cpp_python use same snippet --- packages/tasks/src/model-libraries-snippets.spec.ts | 1 + packages/tasks/src/model-libraries-snippets.ts | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/tasks/src/model-libraries-snippets.spec.ts b/packages/tasks/src/model-libraries-snippets.spec.ts index 7ca049f3f..fa87d8242 100644 --- a/packages/tasks/src/model-libraries-snippets.spec.ts +++ b/packages/tasks/src/model-libraries-snippets.spec.ts @@ -6,6 +6,7 @@ describe("model-libraries-snippets", () => { it("llama_cpp_python conversational", async () => { const model: ModelData = { id: "bartowski/Llama-3.2-3B-Instruct-GGUF", + pipeline_tag: "text-generation", tags: ["conversational"], inference: "", }; diff --git a/packages/tasks/src/model-libraries-snippets.ts b/packages/tasks/src/model-libraries-snippets.ts index 9b5187875..a9ef6e465 100644 --- a/packages/tasks/src/model-libraries-snippets.ts +++ b/packages/tasks/src/model-libraries-snippets.ts @@ -1,6 +1,9 @@ import type { ModelData } from "./model-data.js"; import type { WidgetExampleTextInput, WidgetExampleSentenceSimilarityInput } from "./widget-example.js"; import { LIBRARY_TASK_MAPPING } from "./library-to-tasks.js"; +import { getModelInputSnippet } from "./snippets/inputs.js"; +import { ChatCompletionInputMessage } from "./tasks/index.js"; +import { stringifyMessages } from "./snippets/common.js"; const TAG_CUSTOM_CODE = "custom_code"; @@ -430,13 +433,9 @@ llm = Llama.from_pretrained( ]; if (model.tags.includes("conversational")) { + const messages = getModelInputSnippet(model) as ChatCompletionInputMessage[]; snippets.push(`llm.create_chat_completion( - messages = [ - { - "role": "user", - "content": "What is the capital of France?" - } - ] + messages = ${stringifyMessages(messages, { attributeKeyQuotes: true, indent: "\t" })} )`); } else { snippets.push(`output = llm(