Skip to content

feature(wren-ai-service): integrate Langfuse SDK to represent the evaluation result#395

Merged
paopa merged 8 commits intoepic/ai-service/evaluation-framework-v1from
feature/integrate-langfuse-inot-pipes
Jun 12, 2024
Merged

feature(wren-ai-service): integrate Langfuse SDK to represent the evaluation result#395
paopa merged 8 commits intoepic/ai-service/evaluation-framework-v1from
feature/integrate-langfuse-inot-pipes

Conversation

@paopa
Copy link
Contributor

@paopa paopa commented Jun 11, 2024

This PR aims to integrate the decorator-based Langfuse SDK to collect data for the evaluation process. By default, the environment setup is disabled. To enable Langfuse, follow these steps:

# .env.dev file
# Langfuse configuration
LANGFUSE_ENABLE=True
LANGFUSE_SECRET_KEY=
LANGFUSE_PUBLIC_KEY=
LANGFUSE_HOST=

Fill in the environment variables. You can generate the secret key, public key, and host by following the instructions at Langfuse Documentation.

Currently, we don't set the session ID. When implementing the main process for the evaluation, refer to the following code to set up the session ID.

@observe()
async def main(user_id: str):
    langfuse_context.update_current_trace(
        user_id=user_id, 
        session_id=f"{user_id}_{uuid.uuid4()}"
    )
    return await story()


async def run():
    await asyncio.gather(main("foo"), main("bar"))
    langfuse_context.flush()


asyncio.run(run())

Screenshots

image image image image image

@paopa paopa marked this pull request as ready for review June 11, 2024 11:07
@paopa paopa requested a review from cyyeh June 11, 2024 11:07
@cyyeh cyyeh changed the base branch from main to epic/ai-service/evaluation-framework-v1 June 11, 2024 15:05
@cyyeh cyyeh changed the base branch from epic/ai-service/evaluation-framework-v1 to main June 12, 2024 01:23
@cyyeh cyyeh changed the base branch from main to epic/ai-service/evaluation-framework-v1 June 12, 2024 01:23
Copy link
Member

@cyyeh cyyeh left a comment

Choose a reason for hiding this comment

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

should we call langfuse_context.flush() during the server shutdown event in the lifespan function in wren-ai-service/src/__main__.py?

Also in each pipeline, you call langfuse_context.flush() in the end, I wonder what would happen if langfuse is disabled then?

Copy link
Member

Choose a reason for hiding this comment

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

I suppose we also need to add langfuse related env to .env.prod.example, wren-ai-service/docker/docker-compose.yml, docker/.env.example and docker/docker-compose-dev.yaml, docker/docker-compose.yaml?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can also setup thie environment variable in the future? LANGFUSE_DEBUG

Copy link
Member

Choose a reason for hiding this comment

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

This can be added in the initialization part: Authentication check

Copy link
Member

Choose a reason for hiding this comment

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

We should manually add input/output data if needed: https://langfuse.com/docs/sdk/python/decorators#large-inputoutput-data

@cyyeh
Copy link
Member

cyyeh commented Jun 12, 2024

Overall LGTM, I would like to discuss with you the capture_input part

@paopa paopa requested a review from cyyeh June 12, 2024 09:08
@paopa
Copy link
Contributor Author

paopa commented Jun 12, 2024

After a discussion with @cyyeh, we decided not to capture the span input for all steps. Other suggestions, such as the Langfuse debug mode and authentication check, are interesting features. However, we will not include them in this PR as it is focused on the evaluation framework.

Copy link
Member

@cyyeh cyyeh left a comment

Choose a reason for hiding this comment

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

LGTM

@paopa paopa merged commit 3a34b2f into epic/ai-service/evaluation-framework-v1 Jun 12, 2024
@paopa paopa deleted the feature/integrate-langfuse-inot-pipes branch June 12, 2024 09:21
cyyeh pushed a commit that referenced this pull request Jun 12, 2024
…luation result (#395)

* fix: phony demo folder (#394)

* chore: upgrade the libs

* chore: environment variables for Langfuse

* feature: langfuse configuration initialize

* feature: integrate the langfuse into pipelines

* feature: don't capture the input and embedding output

* feature: decorator on the concept pipelines

* chore: add env variables into docker componse file
cyyeh pushed a commit that referenced this pull request Jun 12, 2024
…luation result (#395)

* fix: phony demo folder (#394)

* chore: upgrade the libs

* chore: environment variables for Langfuse

* feature: langfuse configuration initialize

* feature: integrate the langfuse into pipelines

* feature: don't capture the input and embedding output

* feature: decorator on the concept pipelines

* chore: add env variables into docker componse file
paopa added a commit that referenced this pull request Jul 9, 2024
paopa added a commit that referenced this pull request Jul 9, 2024
…luation result (#395) (#495)

* feature(wren-ai-service): integrate Langfuse SDK to represent the evaluation result (#395)

* chore: modify the import operation to the suitable place
onlyjackfrost pushed a commit that referenced this pull request Jul 11, 2024
…luation result (#395) (#495)

* feature(wren-ai-service): integrate Langfuse SDK to represent the evaluation result (#395)

* chore: modify the import operation to the suitable place
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants