-
Notifications
You must be signed in to change notification settings - Fork 0
Fixes ENG-1430: Add eval run utility in TS #8
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
Merged
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
a0addad
Early draft
7b19f43
Fixed exporter
69fed78
processor correctly implements interface
001376e
Update yarn lock
8d64904
Added back prompt test
2a0ffc0
Added provider tests
71f6416
Yarn lock change
2e7752c
Added API keys to CI action
c15337e
debugging api keys
3ad22fe
whitespace fix attempt
25faed6
Fixed wrong names on CI secrets
1c18a7f
Added instrumentation function
3d38f5e
QA Changes
1c54577
Debugging webpack test
a7e3d13
Leftover console log
04efcb5
More QA
e8c61d4
QA changes
544092d
Fixed tool test
1e781c4
Sorted imports
cde2c6f
Import sort + code cleanup
461e07b
Added scripts for local testing
a953502
amend prepack script
2ffcd33
nit in .fernignore
5f57e74
Reorganised imports
39f218e
Init draft eval_utils
b0d5a2a
Ported eval_utils
68e4a69
Reordered imports
e386add
package json tweaks
4e81c98
Type errors
35f1fd4
Prompt instrumentation works in all downstream examples
8de2fe9
Eval works with simple callables
f91133b
QA pass over eval run
6a7d506
Fixed webpack test
aac5c01
use lodash for safe object comparison
c16600a
change to use smaller models
harry-humanloop 85d59b3
Harry feedback
49837d1
Support streamable mode + added doc to utilities
e5cab4f
Docstring for run eval in TS
776f824
QA for processor changes
9277556
QA pass + PR review feedback
e5fad7c
Added catch blocks detailing the upsert error
385002c
Better messages around instrumented provider
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,27 @@ | ||
| # Specify files that shouldn't be modified by Fern | ||
|
|
||
| # Custom code | ||
|
|
||
| src/otel | ||
| src/eval_utils | ||
| src/utilities | ||
| src/index.ts | ||
| src/humanloop.client.ts | ||
|
|
||
| # Tests | ||
|
|
||
| tests | ||
|
|
||
| # CI Action | ||
|
|
||
| .github/workflows/ci.yml | ||
|
|
||
| # Config files | ||
|
|
||
| .prettierrc.yml | ||
| babel.config.js | ||
| jest.config.js | ||
|
|
||
| # Package Scripts | ||
|
|
||
| scripts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| node_modules | ||
| .DS_Store | ||
| /dist | ||
| /dist | ||
| .env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Ignore Fern auto-generated files | ||
|
|
||
| src/Client.ts | ||
| src/api | ||
| src/core | ||
| src/errors | ||
| src/serialization | ||
| src/environment.ts | ||
| src/version.ts | ||
|
|
||
| tests/custom.test.ts | ||
| tests/unit | ||
|
|
||
| jest.config.js | ||
| package.json | ||
| yarn.lock | ||
| tsconfig.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,10 @@ | ||
| tabWidth: 4 | ||
| printWidth: 120 | ||
| printWidth: 88 | ||
| semi: true | ||
| importOrderSeparation: true | ||
| importOrderSortSpecifiers: true | ||
| importOrderGroupNamespaceSpecifiers: true | ||
| importOrder: ["<THIRD_PARTY_MODULES>", "^[./]"] | ||
| trailingComma: "all" | ||
| plugins: | ||
| - "@trivago/prettier-plugin-sort-imports" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| module.exports = { | ||
| presets: [ | ||
| [ | ||
| "@babel/preset-env", | ||
| { targets: { node: "current" } } | ||
| ], | ||
| ], | ||
| plugins: [ | ||
| "@babel/plugin-transform-modules-commonjs" | ||
| ] | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/bin/sh | ||
| cat .yalc.clean | xargs rm -rf; | ||
| rm -f .yalc.clean; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/bin/sh | ||
| if npm list --global | grep -q yalc; then | ||
| # Local dev environment | ||
| cp -rv dist/. . | awk '{print $3}' | tail -n +2 | cut -c 3- > .yalc.clean; | ||
| echo .yalc.clean >> .yalc.clean; | ||
| else | ||
| # CI environment, releasing the package | ||
| cp -rv dist/. .; | ||
| fi | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import hash from "stable-hash"; | ||
|
|
||
| import { FlowLogRequest, PromptLogRequest } from "../api"; | ||
| import { DatapointResponse } from "../api"; | ||
| import { Humanloop } from "../index"; | ||
| import { Version } from "./types"; | ||
|
|
||
| type EvaluationContextState = { | ||
| fileId?: string; | ||
| path?: string; | ||
| uploadCallback: (logId: string, datapoint: DatapointResponse) => void; | ||
| evaluatedVersion?: Version; | ||
| }; | ||
|
|
||
| type EvaluationContextKey = { | ||
| inputs: Record<string, unknown> | undefined; | ||
| messages: Humanloop.ChatMessage[] | undefined; | ||
| }; | ||
|
|
||
| type EvaluationContextValue = { | ||
| runId: string; | ||
| sourceDatapointId: string; | ||
| uploadCallback: (logId: string) => void; | ||
| }; | ||
|
|
||
| class EvaluationContext { | ||
| private state?: EvaluationContextState; | ||
| private static instance: EvaluationContext; | ||
| private inputMappings: Map<string, EvaluationContextValue[]> = new Map(); | ||
|
|
||
| private constructor() {} | ||
|
|
||
| public static getInstance(): EvaluationContext { | ||
| if (!EvaluationContext.instance) { | ||
| EvaluationContext.instance = new EvaluationContext(); | ||
| } | ||
| return EvaluationContext.instance; | ||
| } | ||
|
|
||
| public setState(state: EvaluationContextState): void { | ||
| this.state = state; | ||
| } | ||
|
|
||
| public getState(): Omit<EvaluationContextState, "uploadCallback"> | undefined { | ||
| return this.state === undefined | ||
| ? this.state | ||
| : { | ||
| fileId: this.state.fileId, | ||
| path: this.state.path, | ||
| evaluatedVersion: this.state.evaluatedVersion, | ||
| }; | ||
| } | ||
|
|
||
| public addDatapoint(datapoint: DatapointResponse, runId: string): void { | ||
| if (this.state === undefined) { | ||
| throw new Error("EvaluationContext state is not set"); | ||
| } | ||
| const key = hash({ inputs: datapoint.inputs, messages: datapoint.messages }); | ||
|
|
||
| if (!this.inputMappings.has(key)) { | ||
| this.inputMappings.set(key, []); | ||
| } | ||
| this.inputMappings.get(key)!.push({ | ||
| runId, | ||
| sourceDatapointId: datapoint.id, | ||
| uploadCallback: (logId: string) => | ||
| this.state!.uploadCallback(logId, datapoint), | ||
| }); | ||
| } | ||
|
|
||
| public getDatapoint(key: EvaluationContextKey): EvaluationContextValue { | ||
| if (key.inputs !== undefined && "inputs" in key.inputs) { | ||
| key = { ...key, inputs: key.inputs.inputs as Record<string, unknown> }; | ||
| } | ||
| const mappings = this.inputMappings.get(hash(key)); | ||
| if (!mappings || mappings.length === 0) { | ||
| throw new Error( | ||
| `No input mappings found for: ${JSON.stringify(key)}. Try using peekDatapoint() first.`, | ||
| ); | ||
| } | ||
| return mappings.pop()!; | ||
| } | ||
|
|
||
| public peekDatapoint(key: EvaluationContextKey): boolean { | ||
| const mappings = this.inputMappings.get(hash(key)); | ||
| return mappings !== undefined && mappings.length > 0; | ||
| } | ||
|
|
||
| public isEvaluatedFile(args: FlowLogRequest | PromptLogRequest) { | ||
| return ( | ||
| this.state && | ||
| (this.state.fileId === args.id || this.state.path === args.path) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export const evaluationContext = EvaluationContext.getInstance(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from "./context"; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.