-
Notifications
You must be signed in to change notification settings - Fork 0
Fixes ENG-1417: TS SDK Utilities #7
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 19 commits
Commits
Show all changes
24 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
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,21 @@ | ||
| # Specify files that shouldn't be modified by Fern | ||
|
|
||
| # Custom code | ||
|
|
||
| src/otel | ||
| src/eval_utils | ||
| src/decorators | ||
| src/index.ts | ||
| src/humanloop.client.ts | ||
|
|
||
| # Tests | ||
|
|
||
| tests | ||
|
|
||
| # CI Action | ||
|
|
||
| .github/workflows/ci.yml | ||
|
|
||
| # Prettier | ||
|
|
||
| .prettierrc.yml |
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 |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| tabWidth: 4 | ||
| printWidth: 120 | ||
| semi: true | ||
| plugins: | ||
| - "prettier-plugin-organize-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
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,22 @@ | ||
| export interface EvaluationContext { | ||
| /** Context Log to Humanloop. | ||
| * Per datapoint state that is set when an Evaluation is run. | ||
| */ | ||
|
|
||
| /** Required for associating a Log with the Evaluation Run. */ | ||
| source_datapoint_id: string; | ||
|
|
||
| /** Overloaded .log method call. */ | ||
| upload_callback: (log: string) => void; | ||
|
|
||
| /** ID of the evaluated File. */ | ||
| file_id: string; | ||
|
|
||
| /** Path of the evaluated File. */ | ||
| path: string; | ||
|
|
||
| /** Required for associating a Log with the Evaluation Run. */ | ||
| run_id: string; | ||
| } | ||
|
|
||
| export const EVALUATION_CONTEXT_VARIABLE_NAME = "__EVALUATION_CONTEXT"; |
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"; |
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,93 @@ | ||
| import { NodeTracerProvider, Tracer } from "@opentelemetry/sdk-trace-node"; | ||
| import { AnthropicInstrumentation } from "@traceloop/instrumentation-anthropic"; | ||
| import { CohereInstrumentation } from "@traceloop/instrumentation-cohere"; | ||
| import { OpenAIInstrumentation } from "@traceloop/instrumentation-openai"; | ||
| import { FlowKernelRequest } from "./api/types/FlowKernelRequest"; | ||
| import { ToolKernelRequest } from "./api/types/ToolKernelRequest"; | ||
| import { HumanloopClient as BaseHumanloopClient } from "./Client"; | ||
| import { HumanloopSpanExporter } from "./otel/exporter"; | ||
| import { moduleIsInstalled } from "./otel/helpers"; | ||
| import { HumanloopSpanProcessor } from "./otel/processor"; | ||
| import { flowUtilityFactory } from "./utilities/flow"; | ||
| import { promptUtilityFactory, UtilityPromptKernel } from "./utilities/prompt"; | ||
| import { toolUtilityFactory } from "./utilities/tool"; | ||
|
|
||
| export class HumanloopClient extends BaseHumanloopClient { | ||
| protected readonly opentelemetryTracerProvider: NodeTracerProvider; | ||
| protected readonly opentelemetryTracer: Tracer; | ||
|
|
||
| constructor(_options: BaseHumanloopClient.Options) { | ||
| super(_options); | ||
|
|
||
| this.opentelemetryTracerProvider = new NodeTracerProvider({ | ||
| spanProcessors: [new HumanloopSpanProcessor(new HumanloopSpanExporter(this))], | ||
| }); | ||
|
|
||
| if (moduleIsInstalled("openai")) { | ||
| const openai = require("openai").default; | ||
| const instrumentor = new OpenAIInstrumentation({ enrichTokens: true }); | ||
| instrumentor.manuallyInstrument(openai); | ||
| instrumentor.setTracerProvider(this.opentelemetryTracerProvider); | ||
| instrumentor.enable(); | ||
| } | ||
|
|
||
| if (moduleIsInstalled("@anthropic-ai/sdk")) { | ||
| const anthropic = require("@anthropic-ai/sdk"); | ||
| const instrumentor = new AnthropicInstrumentation(); | ||
| instrumentor.manuallyInstrument(anthropic); | ||
| instrumentor.setTracerProvider(this.opentelemetryTracerProvider); | ||
| instrumentor.enable(); | ||
| } | ||
|
|
||
| if (moduleIsInstalled("cohere-ai")) { | ||
| const cohere = require("cohere-ai"); | ||
| const instrumentor = new CohereInstrumentation(); | ||
| instrumentor.manuallyInstrument(cohere); | ||
| instrumentor.setTracerProvider(this.opentelemetryTracerProvider); | ||
| instrumentor.enable(); | ||
| } | ||
|
|
||
| this.opentelemetryTracerProvider.register(); | ||
|
|
||
| this.opentelemetryTracer = this.opentelemetryTracerProvider.getTracer("humanloop.sdk"); | ||
| } | ||
|
|
||
| public prompt<T extends (...args: any[]) => any>(promptUtilityArguments: { | ||
| callable: T; | ||
| promptKernel?: UtilityPromptKernel; | ||
| path?: string; | ||
| }) { | ||
| return promptUtilityFactory( | ||
| this.opentelemetryTracer, | ||
| promptUtilityArguments.callable, | ||
| promptUtilityArguments.promptKernel, | ||
| promptUtilityArguments.path | ||
| ); | ||
| } | ||
|
|
||
| public tool<T extends (...args: any[]) => any>(toolUtilityArguments: { | ||
| callable: T; | ||
| toolKernel: ToolKernelRequest; | ||
| path?: string; | ||
| }) { | ||
| return toolUtilityFactory( | ||
| this.opentelemetryTracer, | ||
| toolUtilityArguments.callable, | ||
| toolUtilityArguments.toolKernel, | ||
| toolUtilityArguments.path | ||
| ); | ||
| } | ||
|
|
||
| public flow<T extends (...args: any[]) => any>(flowUtilityArguments: { | ||
| callable: T; | ||
| flowKernel?: FlowKernelRequest; | ||
| path?: string; | ||
| }) { | ||
| return flowUtilityFactory( | ||
| this.opentelemetryTracer, | ||
| flowUtilityArguments.callable, | ||
| flowUtilityArguments.flowKernel, | ||
| flowUtilityArguments.path | ||
| ); | ||
| } | ||
| } |
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,4 +1,4 @@ | ||
| export * as Humanloop from "./api"; | ||
| export { HumanloopClient } from "./Client"; | ||
| export { HumanloopClient } from "./humanloop.client"; | ||
| export { HumanloopEnvironment } from "./environments"; | ||
| export { HumanloopError, HumanloopTimeoutError } from "./errors"; |
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 @@ | ||
| // Attribute name prefix on Humanloop spans for file-related attributes + path | ||
| export const HUMANLOOP_FILE_KEY = "humanloop.file"; | ||
| // Attribute name prefix on Humanloop spans for log-related attributes | ||
| export const HUMANLOOP_LOG_KEY = "humanloop.log"; | ||
| export const HUMANLOOP_FILE_TYPE_KEY = "humanloop.file_type"; | ||
| export const HUMANLOOP_PATH_KEY = "humanloop.file.path"; | ||
| export const HUMANLOOP_PARENT_SPAN_CTX_KEY = "humanloop.context.parentSpanId"; | ||
| export const HUMANLOOP_TRACE_FLOW_CTX_KEY = "humanloop.context.traceFlow"; | ||
|
|
||
| export type AsyncFunction = (...args: unknown[]) => Promise<unknown>; |
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.
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.
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.
ack fixed