-
Notifications
You must be signed in to change notification settings - Fork 0
chatbot: Add Langfuse feedback support #94
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
Conversation
awilfox
left a comment
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.
Overall info about how this was developed.
willa/web/app.py
Outdated
| async def get_step(self, step_id: str) -> Optional[StepDict]: | ||
| # Get step and related feedback | ||
| query = """ | ||
| SELECT s.*, | ||
| f.id feedback_id, | ||
| f.value feedback_value, | ||
| f."comment" feedback_comment | ||
| FROM "Step" s left join "Feedback" f on s.id = f."stepId" | ||
| WHERE s.id = $1 | ||
| """ | ||
| result = await self.execute_query(query, {"step_id": step_id}) | ||
| if not result: | ||
| return None | ||
| return self._convert_step_row_to_dict(result[0]) | ||
|
|
||
|
|
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.
This is a monkey patch for Chainlit/chainlit#2729.
| get_langfuse_client().create_score( | ||
| name='feedback', | ||
| value=float(feedback.value), | ||
| session_id=step['threadId'] if not trace_id else None, | ||
| trace_id=trace_id, | ||
| data_type='BOOLEAN', | ||
| comment=feedback.comment | ||
| ) |
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.
Based on 29816ad
| dl = ChainlitDataLayer(database_url=database_url) | ||
| dl.get_step = get_step.__get__(dl) | ||
| return dl |
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.
Horrible monkeypatch until Chainlit/chainlit#2729 is merged.
|
|
||
| if 'ai_message' in reply: | ||
| await cl.Message(content=reply['ai_message']).send() | ||
| cl.context.current_run.metadata['langfuse_trace_id'] = reply['langfuse_trace_id'] |
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.
Save the trace ID into the run metadata, which is where Chainlit stores Feedback objects (forId -> the run, not the message).
anarchivist
left a comment
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.
this looks great - thanks for submitting the upstream patch, too.
Co-authored-by: Dave Zuckerman <dzuckerm@berkeley.edu>
0f290a5 to
9394a6f
Compare
|
v2:
|
No description provided.