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

Evals #37

Merged
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5177c29
fix: setup evals actions
sshivaditya Nov 21, 2024
e61e401
fix: setup evals actions
sshivaditya Nov 21, 2024
148a73f
feat: adds ClosedQA, ContextPrecision
sshivaditya Nov 22, 2024
ae6d163
fix: removed ClosedQA
sshivaditya Nov 22, 2024
e075c71
fix: cspell and knip
sshivaditya Nov 22, 2024
a077ad8
fix: deps issues
sshivaditya Nov 22, 2024
122efad
fix: downgraded typebox
sshivaditya Nov 22, 2024
43e5e50
fix: evals action
sshivaditya Nov 22, 2024
a518e5e
fix: braintrust action
sshivaditya Nov 22, 2024
8dfe444
fix: update permission
sshivaditya Nov 22, 2024
2bad0fe
fix: add github token to the braintrust
sshivaditya Nov 22, 2024
399d80a
fix: update permission
sshivaditya Nov 22, 2024
139770e
fix: github action
sshivaditya Nov 22, 2024
633ebfe
fix: action
sshivaditya Nov 22, 2024
75a2f87
fix: action
sshivaditya Nov 22, 2024
a4351af
fix: action file dir
sshivaditya Nov 22, 2024
022b9ce
fix: updated package.json
sshivaditya Nov 22, 2024
98d3777
fix: add env to the action
sshivaditya Nov 22, 2024
1d2309c
fix: log env
sshivaditya Nov 23, 2024
2cb4a14
fix: actions env
sshivaditya Nov 23, 2024
58c01ac
fix: updated workflow
sshivaditya Nov 30, 2024
311fc4a
fix: updated workflow
sshivaditya Nov 30, 2024
4a9df8a
fix: package.json duplicate items
sshivaditya Nov 30, 2024
171e427
fix: fixed lockfile
sshivaditya Nov 30, 2024
64263de
fix: lockfile
sshivaditya Dec 1, 2024
766e23f
fix: remove unused deps
sshivaditya Dec 1, 2024
75779f8
fix: update workflow
sshivaditya Dec 1, 2024
fa8934f
fix: evals workflow
sshivaditya Dec 10, 2024
a8922db
fix: add workflow dispatch
sshivaditya Dec 10, 2024
2f0cb7a
fix: evals secrets
sshivaditya Dec 11, 2024
cab2349
fix: prettier and jest
sshivaditya Dec 11, 2024
dd39b3b
fix: fix knip
sshivaditya Dec 11, 2024
cfe8c4d
fix: formatting
sshivaditya Dec 13, 2024
fe11d1b
fix: ncc compile error
sshivaditya Dec 13, 2024
7ec1087
fix: ncc compile error
sshivaditya Dec 13, 2024
5d27598
chore: updated manifest.json and dist build
github-actions[bot] Dec 13, 2024
a5d9302
fix: change to /ask
sshivaditya Dec 13, 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
5 changes: 4 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
"dylib",
"mobileprovision",
"icns",
"hono"
"hono",
"braintrust",
"autoevals",
"SEPERATOR"
],
"dictionaries": ["typescript", "node", "software-terms"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
Expand Down
2 changes: 1 addition & 1 deletion .github/knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const config: KnipConfig = {
ignore: ["src/types/config.ts", "**/__mocks__/**", "**/__fixtures__/**"],
ignoreExportsUsedInFile: true,
// eslint can also be safely ignored as per the docs: https://knip.dev/guides/handling-issues#eslint--jest
ignoreDependencies: ["eslint-config-prettier", "eslint-plugin-prettier", "ts-node", "hono", "cross-env"],
ignoreDependencies: ["eslint-config-prettier", "eslint-plugin-prettier", "hono", "ts-node"],
eslint: true,
};

Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/evals-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Run Braintrust Evals

on:
workflow_run:
workflows: ["Knip"]
types:
- completed

permissions: write-all

jobs:
eval:
name: Run evals
runs-on: ubuntu-latest
permissions: write-all

steps:
- uses: actions/setup-node@v4
with:
node-version: "20.10.0"

- uses: actions/checkout@master
with:
fetch-depth: 0

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install toolchain
run: bun install --frozen-lockfile

- name: Run Evals
id: evals
run: bun eval
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
VOYAGEAI_API_KEY: ${{ secrets.VOYAGEAI_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
UBIQUITY_OS_APP_NAME: ${{ secrets.UBIQUITY_OS_APP_NAME }}
BRAINTRUST_API_KEY: ${{ secrets.BRAINTRUST_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Add Evals Report to Github Comment
if: always()
run: echo "$(cat eval-results.md)" >> $GITHUB_STEP_SUMMARY
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ junit.xml
cypress/screenshots
script.ts
.wrangler
test-dashboard.md
test-dashboard.md
eval-results.md
126 changes: 62 additions & 64 deletions CHANGELOG.md

Large diffs are not rendered by default.

Binary file modified bun.lockb
Binary file not shown.
25 changes: 25 additions & 0 deletions evals/data/eval-gold-responses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"issueResponses": [
{
"scenario": "manifest.name mismatch ",
"issue": {
"body": "Manifests need to be updated so the name matches the intended name, which is the name of the repo it lives in.\n\nAny mismatch in manifest.name and the plugin repo, and we will not be able to install those plugins. The config will look like this:\n\nThis is because the worker URL contains the repo name, and we use that to match against manifest.name.",
"number": 27,
"html_url": "https://github.com/ubiquity-os/ubiquity-os-plugin-installer/issues/27/",
"question": "@ubosshivaditya could you please provide a summary of the issue ?"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be a problem to leave in @ubosshivaditya?

Also this seems like a random example can you explain the context of this file further?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can modify the app name to whatever is stored in the secrets; it doesn't matter, as the askQuestion function will be triggered either way.

This file primarily contains solid baseline examples, including "gold star" responses to questions. We run the model with the same context and should expect similar performance.

Copy link
Member

@0x4007 0x4007 Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can modify the app name to whatever is stored in the secrets; it doesn't matter,

We have the production and beta instance of the app so I'm not sure about dealing with secrets to save the names. Think through how this will be configured and let me know what you think makes sense

including "gold star" responses to questions.

I guess it's "gold standard" I just messed up the terminology when I called it "gold star".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the production and beta instance of the app so I'm not sure about dealing with secrets to save the names. Think through how this will be configured and let me know what you think makes sense

I think it would be better if we could just hard code names, and keep in consistent in the workflow.

I guess it's "gold standard" I just messed up the terminology when I called it "gold star".

No, you were correct—it's called a "gold star response"1. "Gold standard" is a different approach, but not the one we're discussing here.

Footnotes

  1. https://arxiv.org/html/2410.23214v1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard coding seems questionable for developers but generally yes I agree that it's easier to deal with vs secrets. @gentlementlegen please decide

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is no longer relevant, as we are using the LLM command router.

},
"expectedResponse": "The manifest.name should match the name of the repo it lives in. This is because the worker URL contains the repo name, and we use that to match against manifest.name.",
"sender": {
"login": "sshivaditya2019",
"type": "User"
},
"repository": {
"name": "ubiquity-os-plugin-installer",
"owner": {
"login": "ubiquity-os",
"type": "Organization"
}
}
}
]
}
114 changes: 114 additions & 0 deletions evals/handlers/setup-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { SupabaseClient } from "@supabase/supabase-js";
import { createAdapters } from "../../src/adapters";
import { CommentSimilaritySearchResult } from "../../src/adapters/supabase/helpers/comment";
import { IssueSimilaritySearchResult } from "../../src/adapters/supabase/helpers/issues";
import { fetchRepoLanguageStats, fetchRepoDependencies } from "../../src/handlers/ground-truths/chat-bot";
import { findGroundTruths } from "../../src/handlers/ground-truths/find-ground-truths";
import { logger } from "../../src/helpers/errors";
import { formatChatHistory } from "../../src/helpers/format-chat-history";
import { recursivelyFetchLinkedIssues } from "../../src/helpers/issue-fetching";
import { Context } from "../../src/types";
import { VoyageAIClient } from "voyageai";
import OpenAI from "openai";

const SEPERATOR = "######################################################\n";

export interface FetchContext {
rerankedText: string[];
formattedChat: string[];
groundTruths: string[];
}

export interface EvalClients {
supabase: SupabaseClient;
voyage: VoyageAIClient;
openai: OpenAI;
}

export const initAdapters = (context: Context, clients: EvalClients): Context => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't have passed linter settings. Make sure you run yarn format in case the git hooks aren't working. We don't generally allow arrow functions unless they are used in some tiny callback context.

const adapters = createAdapters(clients.supabase, clients.voyage, clients.openai, context);
context.adapters = adapters;

// Update adapter contexts
Object.values(adapters).forEach((adapterGroup) => {
Object.values(adapterGroup).forEach((adapter) => {
if (adapter && typeof adapter === "object" && "context" in adapter) {
adapter.context = context;
}
});
});
return context;
};

export async function fetchContext(context: Context, question: string): Promise<FetchContext> {
const {
config: { similarityThreshold },
adapters: {
supabase: { comment, issue },
voyage: { reranker },
},
} = context;
const { specAndBodies, streamlinedComments } = await recursivelyFetchLinkedIssues({
context,
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
});
let formattedChat = await formatChatHistory(context, streamlinedComments, specAndBodies);
logger.info(`${formattedChat.join("")}`);
// using db functions to find similar comments and issues
const [similarComments, similarIssues] = await Promise.all([
comment.findSimilarComments(question, 1 - similarityThreshold, ""),
issue.findSimilarIssues(question, 1 - similarityThreshold, ""),
]);
// combine the similar comments and issues into a single array
const similarText = [
...(similarComments?.map((comment: CommentSimilaritySearchResult) => comment.comment_plaintext) || []),
...(similarIssues?.map((issue: IssueSimilaritySearchResult) => issue.issue_plaintext) || []),
];
// filter out any empty strings
formattedChat = formattedChat.filter((text) => text);
// rerank the similar text using voyageai
const rerankedText = similarText.length > 0 ? await reranker.reRankResults(similarText, question) : [];
// gather structural data about the payload repository
const [languages, { dependencies, devDependencies }] = await Promise.all([fetchRepoLanguageStats(context), fetchRepoDependencies(context)]);
let groundTruths: string[] = [];
if (!languages.length) {
groundTruths.push("No languages found in the repository");
}
if (!Reflect.ownKeys(dependencies).length) {
groundTruths.push("No dependencies found in the repository");
}
if (!Reflect.ownKeys(devDependencies).length) {
groundTruths.push("No devDependencies found in the repository");
}
if (groundTruths.length > 3) {
groundTruths = await findGroundTruths(context, "chat-bot", { languages, dependencies, devDependencies });
}
return {
rerankedText,
formattedChat,
groundTruths,
};
}

export function formattedHistory(fetchContext: FetchContext): string {
//Iterate through the formatted chat history and add it to the final formatted chat
let formattedChat = "#################### Chat History ####################\n";
fetchContext.formattedChat.forEach((chat) => {
formattedChat += chat;
});
formattedChat += SEPERATOR;
//Iterate through the reranked text and add it to the final formatted chat
formattedChat += "#################### Reranked Text ####################\n";
fetchContext.rerankedText.forEach((reranked) => {
formattedChat += reranked;
});
formattedChat += SEPERATOR;
//Iterate through the ground truths and add it to the final formatted chat
formattedChat += "#################### Ground Truths ####################\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these many hashtags really necessary? I thought writing in plain markdown syntax is sufficient.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-12-11 at 12 26 58 PM

It’s not necessary, but it helps a lot when looking through the context in the braintrust context viewer. This formatting is only used for the context stored in braintrust; otherwise, the flow uses the regular formatted chat history.

fetchContext.groundTruths.forEach((truth) => {
formattedChat += truth;
});
formattedChat += SEPERATOR;
return formattedChat;
}
Loading
Loading