-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(weave): load model default properly #3096
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,3 +121,68 @@ export const LLM_MAX_TOKENS = { | |
}; | ||
|
||
export type LLMMaxTokensKey = keyof typeof LLM_MAX_TOKENS; | ||
|
||
export const LLM_MAX_TOKENS_KEYS: LLMMaxTokensKey[] = Object.keys( | ||
LLM_MAX_TOKENS | ||
) as LLMMaxTokensKey[]; | ||
|
||
// Helper function to calculate string similarity using Levenshtein distance | ||
const getLevenshteinDistance = (str1: string, str2: string): number => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we are using |
||
const track = Array(str2.length + 1) | ||
.fill(null) | ||
.map(() => Array(str1.length + 1).fill(null)); | ||
|
||
for (let i = 0; i <= str1.length; i++) { | ||
track[0][i] = i; | ||
} | ||
for (let j = 0; j <= str2.length; j++) { | ||
track[j][0] = j; | ||
} | ||
|
||
for (let j = 1; j <= str2.length; j++) { | ||
for (let i = 1; i <= str1.length; i++) { | ||
const indicator = str1[i - 1] === str2[j - 1] ? 0 : 1; | ||
track[j][i] = Math.min( | ||
track[j][i - 1] + 1, // deletion | ||
track[j - 1][i] + 1, // insertion | ||
track[j - 1][i - 1] + indicator // substitution | ||
); | ||
} | ||
} | ||
return track[str2.length][str1.length]; | ||
}; | ||
|
||
// Main function to find most similar LLM name | ||
export const findMostSimilarLLMName = ( | ||
input: string, | ||
llmList: LLMMaxTokensKey[] | ||
): string => { | ||
const normalizedInput = input.toLowerCase().trim(); | ||
|
||
// If exact match exists, return it | ||
if (llmList.includes(normalizedInput as LLMMaxTokensKey)) { | ||
return normalizedInput; | ||
} | ||
|
||
let closestMatch = llmList[0]; | ||
let smallestDistance = Infinity; | ||
|
||
llmList.forEach(llmName => { | ||
const distance = getLevenshteinDistance( | ||
normalizedInput, | ||
llmName.toLowerCase() | ||
); | ||
|
||
if (distance < smallestDistance) { | ||
smallestDistance = distance; | ||
closestMatch = llmName; | ||
} | ||
|
||
if (llmName.includes(normalizedInput)) { | ||
closestMatch = llmName; | ||
smallestDistance = 0; | ||
} | ||
}); | ||
|
||
return closestMatch; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
import {toast} from '@wandb/weave/common/components/elements/Toast'; | ||
import {SetStateAction, useCallback, useState} from 'react'; | ||
|
||
import {LLMMaxTokensKey} from './llmMaxTokens'; | ||
import { | ||
findMostSimilarLLMName, | ||
LLM_MAX_TOKENS_KEYS, | ||
LLMMaxTokensKey, | ||
} from './llmMaxTokens'; | ||
import { | ||
OptionalTraceCallSchema, | ||
PlaygroundResponseFormats, | ||
|
@@ -34,7 +39,7 @@ const DEFAULT_PLAYGROUND_STATE = { | |
presencePenalty: 0, | ||
// nTimes: 1, | ||
maxTokensLimit: 16384, | ||
model: 'gpt-4o-mini' as LLMMaxTokensKey, | ||
model: 'gpt-4o-mini-2024-07-18' as LLMMaxTokensKey, | ||
}; | ||
|
||
export const usePlaygroundState = () => { | ||
|
@@ -106,6 +111,20 @@ export const usePlaygroundState = () => { | |
if (inputs.presence_penalty) { | ||
newState.presencePenalty = parseFloat(inputs.presence_penalty); | ||
} | ||
if (inputs.model) { | ||
if (LLM_MAX_TOKENS_KEYS.includes(inputs.model as LLMMaxTokensKey)) { | ||
newState.model = inputs.model as LLMMaxTokensKey; | ||
} else { | ||
const closestModel = findMostSimilarLLMName( | ||
inputs.model, | ||
LLM_MAX_TOKENS_KEYS | ||
); | ||
toast( | ||
`We currently don't support ${inputs.model}, in the playground. We will default to ${closestModel}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we always want to default to the most similar model? can it ever be a typo? I would expect this case to most likely happen with custom models, which they might not want to have auto-selected. |
||
); | ||
newState.model = closestModel as LLMMaxTokensKey; | ||
} | ||
} | ||
return [newState]; | ||
}); | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.