Skip to content

Commit

Permalink
cleanup + conversational
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-c committed Jan 24, 2025
1 parent f130185 commit 5b696c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions packages/tasks/src/snippets/curl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,6 @@ export function getCurlInferenceSnippet(
opts?: Record<string, unknown>
): InferenceSnippet[] {
return model.pipeline_tag && model.pipeline_tag in curlSnippets
? curlSnippets[model.pipeline_tag]?.(model, accessToken, provider, opts) ?? [{ content: "" }]
: [{ content: "" }];
? curlSnippets[model.pipeline_tag]?.(model, accessToken, provider, opts) ?? []
: [];
}
4 changes: 2 additions & 2 deletions packages/tasks/src/snippets/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,6 @@ export function getJsInferenceSnippet(
opts?: Record<string, unknown>
): InferenceSnippet[] {
return model.pipeline_tag && model.pipeline_tag in jsSnippets
? jsSnippets[model.pipeline_tag]?.(model, accessToken, provider, opts) ?? [{ content: "" }]
: [{ content: "" }];
? jsSnippets[model.pipeline_tag]?.(model, accessToken, provider, opts) ?? []
: [];
}
27 changes: 13 additions & 14 deletions packages/tasks/src/snippets/python.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { InferenceProvider } from "../inference-providers.js";
import { openAIbaseUrl, type InferenceProvider } from "../inference-providers.js";
import type { PipelineType } from "../pipelines.js";
import type { ChatCompletionInputMessage, GenerationParameters } from "../tasks/index.js";
import { stringifyGenerationConfig, stringifyMessages } from "./common.js";
Expand All @@ -12,8 +12,7 @@ from huggingface_hub import InferenceClient
client = InferenceClient(
provider="${provider}",
api_key="${accessToken || "{API_TOKEN}"}"
)
`;
)`;

export const snippetConversational = (
model: ModelDataMinimal,
Expand Down Expand Up @@ -46,9 +45,8 @@ export const snippetConversational = (
return [
{
client: "huggingface_hub",
content: `from huggingface_hub import InferenceClient
client = InferenceClient(api_key="${accessToken || "{API_TOKEN}"}")
content: `\
${snippetImportInferenceClient(accessToken, provider)}
messages = ${messagesStr}
Expand All @@ -67,7 +65,7 @@ for chunk in stream:
content: `from openai import OpenAI
client = OpenAI(
base_url="https://api-inference.huggingface.co/v1/",
base_url="${openAIbaseUrl(provider)}",
api_key="${accessToken || "{API_TOKEN}"}"
)
Expand All @@ -88,9 +86,8 @@ for chunk in stream:
return [
{
client: "huggingface_hub",
content: `from huggingface_hub import InferenceClient
client = InferenceClient(api_key="${accessToken || "{API_TOKEN}"}")
content: `\
${snippetImportInferenceClient(accessToken, provider)}
messages = ${messagesStr}
Expand All @@ -107,7 +104,7 @@ print(completion.choices[0].message)`,
content: `from openai import OpenAI
client = OpenAI(
base_url="https://api-inference.huggingface.co/v1/",
base_url="${openAIbaseUrl(provider)}",
api_key="${accessToken || "{API_TOKEN}"}"
)
Expand Down Expand Up @@ -197,7 +194,9 @@ export const snippetTextToImage = (
return [
{
client: "huggingface_hub",
content: `${snippetImportInferenceClient(accessToken, provider)}
content: `\
${snippetImportInferenceClient(accessToken, provider)}
# output is a PIL.Image object
image = client.text_to_image(
${getModelInputSnippet(model)},
Expand Down Expand Up @@ -370,8 +369,8 @@ export function getPythonInferenceSnippet(
} else {
const snippets =
model.pipeline_tag && model.pipeline_tag in pythonSnippets
? pythonSnippets[model.pipeline_tag]?.(model, accessToken, provider) ?? [{ content: "" }]
: [{ content: "" }];
? pythonSnippets[model.pipeline_tag]?.(model, accessToken, provider) ?? []
: [];

return snippets.map((snippet) => {
return {
Expand Down

0 comments on commit 5b696c0

Please sign in to comment.