Thomas G. Lopes commited on
Commit
f9fa0a5
·
1 Parent(s): 491aab8

routing mode for snippets

Browse files
src/lib/components/inference-playground/code-snippets.svelte CHANGED
@@ -40,7 +40,7 @@
40
  let showToken = $state(false);
41
 
42
  type GetSnippetArgs = {
43
- tokenStr: string;
44
  conversation: ConversationClass;
45
  lang: InferenceSnippetLanguage;
46
  };
@@ -53,6 +53,7 @@
53
  max_tokens: data.config.max_tokens,
54
  temperature: data.config.temperature,
55
  top_p: data.config.top_p,
 
56
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
  } as any;
58
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -61,7 +62,7 @@
61
  }
62
 
63
  if (isCustomModel(model)) {
64
- const snippets = getInferenceSnippet(conversation, lang, tokenStr, opts);
65
  return snippets
66
  .filter(s => s.client.startsWith("open") || lang === "sh")
67
  .map(s => {
@@ -74,7 +75,7 @@
74
  });
75
  }
76
 
77
- return getInferenceSnippet(conversation, lang, tokenStr, opts);
78
  }
79
 
80
  // { javascript: 0, python: 0, http: 0 } at first
@@ -101,10 +102,10 @@
101
  if (isCustomModel(conversation.model)) {
102
  const t = conversation.model.accessToken;
103
 
104
- return t && showToken ? t : "YOUR_ACCESS_TOKEN";
105
  }
106
 
107
- return token.value && showToken ? token.value : "YOUR_HF_TOKEN";
108
  });
109
 
110
  const snippetsByLang = $derived({
 
40
  let showToken = $state(false);
41
 
42
  type GetSnippetArgs = {
43
+ tokenStr?: string;
44
  conversation: ConversationClass;
45
  lang: InferenceSnippetLanguage;
46
  };
 
53
  max_tokens: data.config.max_tokens,
54
  temperature: data.config.temperature,
55
  top_p: data.config.top_p,
56
+ accessToken: tokenStr,
57
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
  } as any;
59
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
 
62
  }
63
 
64
  if (isCustomModel(model)) {
65
+ const snippets = getInferenceSnippet(conversation, lang, opts);
66
  return snippets
67
  .filter(s => s.client.startsWith("open") || lang === "sh")
68
  .map(s => {
 
75
  });
76
  }
77
 
78
+ return getInferenceSnippet(conversation, lang, opts);
79
  }
80
 
81
  // { javascript: 0, python: 0, http: 0 } at first
 
102
  if (isCustomModel(conversation.model)) {
103
  const t = conversation.model.accessToken;
104
 
105
+ return t && showToken ? t : undefined;
106
  }
107
 
108
+ return token.value && showToken ? token.value : undefined;
109
  });
110
 
111
  const snippetsByLang = $derived({
src/lib/utils/business.svelte.ts CHANGED
@@ -316,8 +316,8 @@ export type GetInferenceSnippetReturn = InferenceSnippet[];
316
  export function getInferenceSnippet(
317
  conversation: ConversationClass,
318
  language: InferenceSnippetLanguage,
319
- accessToken: string,
320
  opts?: {
 
321
  messages?: ConversationEntityMembers["messages"];
322
  streaming?: ConversationEntityMembers["streaming"];
323
  max_tokens?: ConversationEntityMembers["config"]["max_tokens"];
@@ -342,7 +342,7 @@ export function getInferenceSnippet(
342
  provider,
343
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
344
  { ...providerMapping, hfModelId: model.id } as any,
345
- { ...opts, accessToken },
346
  );
347
 
348
  return allSnippets
 
316
  export function getInferenceSnippet(
317
  conversation: ConversationClass,
318
  language: InferenceSnippetLanguage,
 
319
  opts?: {
320
+ accessToken?: string;
321
  messages?: ConversationEntityMembers["messages"];
322
  streaming?: ConversationEntityMembers["streaming"];
323
  max_tokens?: ConversationEntityMembers["config"]["max_tokens"];
 
342
  provider,
343
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
344
  { ...providerMapping, hfModelId: model.id } as any,
345
+ { ...opts, directRequest: false },
346
  );
347
 
348
  return allSnippets