Skip to content
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

refactor llm info #961

Merged
merged 23 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6cce2d1
llm as judge support
pelikhan Dec 19, 2024
9dcfc67
Merge remote-tracking branch 'origin/main' into judge
pelikhan Dec 20, 2024
9b572ef
style: πŸ’„ remove redundant blank line in judge.genai.mts
pelikhan Dec 20, 2024
5725842
feat: πŸ§ͺ extend judgeClassify to support WorkspaceFile
pelikhan Dec 20, 2024
e17d55b
feat: πŸ—οΈ add check for undefined text in tracePromptResult
pelikhan Dec 20, 2024
f16d915
add g2thinking
pelikhan Dec 20, 2024
c62171d
feat: ✨ add model alias support and update defaults
pelikhan Dec 20, 2024
0d394b9
feat: ✨ add support for listing model information in CLI
pelikhan Dec 20, 2024
d6da24c
updated list of models
pelikhan Dec 20, 2024
f034b86
feat: ✨ update LLM aliases and models, fix mistral typo
pelikhan Dec 20, 2024
fd17d69
feat: ✨ add logprobs and topLogprobs support
pelikhan Dec 20, 2024
aa7f334
feat: ✨ add aliases and logit_bias support to providers
pelikhan Dec 21, 2024
c7958a1
feat: πŸ”§ add `info models alias` command to CLI
pelikhan Dec 21, 2024
c3a2ca5
test: ♻️ simplify assertion and add new test case
pelikhan Dec 21, 2024
b1c78f0
chore: πŸ”§ update dependencies across multiple packages
pelikhan Dec 21, 2024
500f3fb
feat: ✨ add support for LLM provider aliases and options
pelikhan Dec 21, 2024
c5d16bf
feat: ✨ add embeddings model to llms.json configuration
pelikhan Dec 21, 2024
7c5d691
feat: πŸ“ add filter for empty user text and new aliases
pelikhan Dec 21, 2024
4e890ff
use provider in test scripts
pelikhan Dec 21, 2024
050f7f3
docs: ✏️ update CLI usage and configuration sections
pelikhan Dec 21, 2024
042a338
ci: πŸ”„ rename workflow to huggingface tests
pelikhan Dec 21, 2024
d0a02a9
env typo
pelikhan Dec 21, 2024
2408a79
feat: πŸ”§ update aliases and simplify template tracing
pelikhan Dec 21, 2024
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
2 changes: 1 addition & 1 deletion packages/core/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@
disableFallback: true,
})) || {}
if (!encode) {
logWarn(
logVerbose(

Check failure on line 788 in packages/core/src/chat.ts

View workflow job for this annotation

GitHub Actions / build

Did you mean `unable` instead of `unabled`?
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
`unabled to compute logit bias, no token encoder found for ${model}`
)
trace.warn(
Expand Down
80 changes: 80 additions & 0 deletions packages/sample/genaisrc/judge.genai.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
*
* @param task
* @param result
* @param categories
* @param options
* @returns
*/
async function judgeClassify(
task: Awaitable<string>,
result: Awaitable<string>,
categories: Record<string, string>,
options?: {
logprobs?: boolean
topLogprobs?: number
model?: ModelType
temperature?: number
}
) {
const unknown = "unknown"
const unknownText =
"if you do not have enough information or certainty to categorize the result"
+
const choices = { ...categories, ...{ [unknown]: unknownText } }
const res = await runPrompt(
async (ctx) => {
ctx.$`## Task
You will be given a task description in <TASK> and a response from a chat bot in <RESULT>.
Your task is to judge and classify <RESULT> according to the categories in <CATEGORY>.

- Rely exclusively on the information provided in the task and the response.

## Output
The output should start with the step-by-step explanation of the classification (one paragraph).
Finish the output with the category name on a single line, no other words.
`.role("system")
ctx.def("TASK", await task)
ctx.def("RESULT", await result)
ctx.def(
"CATEGORY",
Object.entries(choices)
.map((kv) => `- ${kv[0]}: ${kv[1]}`)
.join("\n")
)
},
{
system: ["system.output_plaintext", "system.safety_jailbreak"],
choices: Object.keys(choices),
logprobs: options?.logprobs,
topLogprobs: options?.topLogprobs,
temperature: options?.temperature || 0.1,
model: options?.model || "small",
}
)

// extract the classifiction
const category = Object.keys(choices)
.map((category) => ({
category,
l: res.text.lastIndexOf(category),
}))
.filter(({ l }) => l > -1)
.sort((a, b) => a.l - b.l)[0]?.category

const logprob = res.logprobs?.reverse().find((lp) => lp.token === category)
return {
category,
logprob,
}
}

const task = "Generate a funny joke."
//const { text: result } = await runPrompt(task)
let result = "Why did the tomato turn red? Because boo."

const res = await judgeClassify(task, result, {
pass: "the joke was funny",
fail: "the joke was not funny",
})
console.log(res)
Loading