-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Components] langfuse - new components #15694
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
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 |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import constants from "../../common/constants.mjs"; | ||
| import app from "../../langfuse.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "langfuse-add-feedback", | ||
| name: "Add Feedback", | ||
| description: "Attach user feedback to an existing trace in Langfuse. [See the documentation](https://api.reference.langfuse.com/#tag/comments/POST/api/public/comments).", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| projectId: { | ||
| propDefinition: [ | ||
| app, | ||
| "projectId", | ||
| ], | ||
| }, | ||
| objectType: { | ||
| propDefinition: [ | ||
| app, | ||
| "objectType", | ||
| ], | ||
| }, | ||
| objectId: { | ||
| propDefinition: [ | ||
| app, | ||
| "objectId", | ||
| ({ objectType }) => ({ | ||
| objectType, | ||
| }), | ||
| ], | ||
| }, | ||
| content: { | ||
| type: "string", | ||
| label: "Content", | ||
| description: "The content of the comment. May include markdown. Currently limited to 3000 characters.", | ||
| }, | ||
| }, | ||
| methods: { | ||
| addFeedback(args = {}) { | ||
| return this.app.post({ | ||
| path: "/comments", | ||
| ...args, | ||
| }); | ||
| }, | ||
| async getObjectId() { | ||
| const { | ||
| app, | ||
| objectType, | ||
| objectId, | ||
| } = this; | ||
| if (objectType == constants.OBJECT_TYPE.PROMPT) { | ||
| const prompt = await app.getPrompt({ | ||
| promptName: objectId, | ||
| }); | ||
| return prompt?.id; | ||
| } | ||
| return objectId; | ||
| }, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| getObjectId, | ||
| addFeedback, | ||
| projectId, | ||
| objectType, | ||
| content, | ||
| } = this; | ||
|
|
||
| const objectId = await getObjectId(); | ||
|
|
||
| const response = await addFeedback({ | ||
| $, | ||
| data: { | ||
| projectId, | ||
| objectType, | ||
| objectId, | ||
| content, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", "Successfully added feedback."); | ||
| return response; | ||
| }, | ||
| }; | ||
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,126 @@ | ||
| import { v4 as uuid } from "uuid"; | ||
| import app from "../../langfuse.app.mjs"; | ||
| import constants from "../../common/constants.mjs"; | ||
| import utils from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "langfuse-log-trace", | ||
| name: "Log Trace", | ||
| description: "Log a new trace in LangFuse with details. [See the documentation](https://api.reference.langfuse.com/#tag/ingestion/POST/api/public/ingestion).", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| name: { | ||
| type: "string", | ||
| label: "Name", | ||
| description: "The name of the trace", | ||
| }, | ||
| input: { | ||
| type: "string", | ||
| label: "Input", | ||
| description: "The input of the trace", | ||
| }, | ||
| output: { | ||
| type: "string", | ||
| label: "Output", | ||
| description: "The output of the trace", | ||
| }, | ||
| userId: { | ||
| type: "string", | ||
| label: "User ID", | ||
| description: "The ID of the user", | ||
| optional: true, | ||
| }, | ||
| sessionId: { | ||
| label: "Session ID", | ||
| description: "The ID of the session", | ||
| optional: true, | ||
| propDefinition: [ | ||
| app, | ||
| "objectId", | ||
| () => ({ | ||
| objectType: constants.OBJECT_TYPE.SESSION, | ||
| }), | ||
| ], | ||
| }, | ||
| release: { | ||
| type: "string", | ||
| label: "Release", | ||
| description: "The release of the trace", | ||
| optional: true, | ||
| }, | ||
| version: { | ||
| type: "string", | ||
| label: "Version", | ||
| description: "The version of the trace", | ||
| optional: true, | ||
| }, | ||
| metadata: { | ||
| type: "string", | ||
| label: "Metadata", | ||
| description: "The metadata of the trace", | ||
| optional: true, | ||
| }, | ||
| tags: { | ||
| type: "string[]", | ||
| label: "Tags", | ||
| description: "The tags of the trace", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| batchIngestion(args = {}) { | ||
| return this.app.post({ | ||
| path: "/ingestion", | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| async run({ $ }) { | ||
| const { | ||
| batchIngestion, | ||
| name, | ||
| userId, | ||
| input, | ||
| output, | ||
| sessionId, | ||
| release, | ||
| version, | ||
| metadata, | ||
| tags, | ||
| } = this; | ||
|
|
||
| const timestamp = new Date().toISOString(); | ||
| const id = uuid(); | ||
|
|
||
| const response = await batchIngestion({ | ||
| $, | ||
| data: { | ||
| batch: [ | ||
| { | ||
| id, | ||
| timestamp, | ||
| type: constants.INGESTION_TYPE.TRACE_CREATE, | ||
| body: { | ||
| id, | ||
| timestamp, | ||
| name, | ||
| userId, | ||
| input: utils.parseJson(input), | ||
| output: utils.parseJson(output), | ||
| sessionId, | ||
| release, | ||
| version, | ||
| metadata: utils.parseJson(metadata), | ||
| tags, | ||
| public: true, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
| $.export("$summary", "Successfully logged a new trace"); | ||
| return response; | ||
| }, | ||
| }; | ||
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,40 @@ | ||
| const REGION_PLACEHOLDER = "{region}"; | ||
| const BASE_URL = "https://{region}.langfuse.com"; | ||
| const VERSION_PATH = "/api/public"; | ||
|
|
||
| const INGESTION_TYPE = { | ||
| TRACE_CREATE: "trace-create", | ||
| SCORE_CREATE: "score-create", | ||
| SPAN_CREATE: "span-create", | ||
| SPAN_UPDATE: "span-update", | ||
| GENERATION_CREATE: "generation-create", | ||
| GENERATION_UPDATE: "generation-update", | ||
| EVENT_CREATE: "event-create", | ||
| SDK_LOG: "sdk-log", | ||
| OBSERVATION_CREATE: "observation-create", | ||
| OBSERVATION_UPDATE: "observation-update", | ||
| }; | ||
|
|
||
| const LAST_DATE_AT = "lastDateAt"; | ||
| const IS_FIRST_RUN = "isFirstRun"; | ||
| const DEFAULT_LIMIT = 100; | ||
| const DEFAULT_MAX = 1000; | ||
|
|
||
| const OBJECT_TYPE = { | ||
| TRACE: "TRACE", | ||
| OBSERVATION: "OBSERVATION", | ||
| SESSION: "SESSION", | ||
| PROMPT: "PROMPT", | ||
| }; | ||
|
|
||
| export default { | ||
| REGION_PLACEHOLDER, | ||
| BASE_URL, | ||
| VERSION_PATH, | ||
| INGESTION_TYPE, | ||
| LAST_DATE_AT, | ||
| IS_FIRST_RUN, | ||
| DEFAULT_LIMIT, | ||
| DEFAULT_MAX, | ||
| OBJECT_TYPE, | ||
| }; |
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,41 @@ | ||
| async function iterate(iterations) { | ||
| const items = []; | ||
| for await (const item of iterations) { | ||
| items.push(item); | ||
| } | ||
| return items; | ||
| } | ||
|
|
||
| function getNestedProperty(obj, propertyString) { | ||
| const properties = propertyString.split("."); | ||
| return properties.reduce((prev, curr) => prev?.[curr], obj); | ||
| } | ||
|
|
||
| const parseJson = (input) => { | ||
| const parse = (value) => { | ||
| if (typeof(value) === "string") { | ||
| try { | ||
| return parseJson(JSON.parse(value)); | ||
| } catch (e) { | ||
| return value; | ||
| } | ||
| } else if (typeof(value) === "object" && value !== null) { | ||
| return Object.entries(value) | ||
| .reduce((acc, [ | ||
| key, | ||
| val, | ||
| ]) => Object.assign(acc, { | ||
| [key]: parse(val), | ||
| }), {}); | ||
| } | ||
| return value; | ||
| }; | ||
|
|
||
| return parse(input); | ||
| }; | ||
|
|
||
| export default { | ||
| iterate, | ||
| getNestedProperty, | ||
| parseJson, | ||
| }; |
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.