from langfree.transform import RunData
shiny
Shiny for Python is a front end framework that allows you to quickly build simple applications. It’s perfect for customizing your own data annotation and review app for LLMs1. This module contains opinionated components that display ChatOpenAI run information in Shiny Apps.
render_input_chat
render_input_chat (run:langfree.transform.RunData, markdown=True)
Render the chat history, except for the last output as a group of cards.
render_input
will take an instance of RunData
and render a set of Shiny cards, with each card containing one turn of the chat conversation:
with _temp_env_var(tmp_env): #context manager that has specific environment vars for testing
= RunData.from_run_id('1863d76e-1462-489a-a8a7-e0404239fe47')
_tst_run
= render_input_chat(_tst_run) _rendered_inp
/Users/hamel/mambaforge/lib/python3.10/site-packages/langchain_core/_api/beta_decorator.py:86: LangChainBetaWarning: The function `load` is in beta. It is actively being worked on, so the API may change.
warn_beta(
Below, we render the first card in the conversation:
0] # the first message in the conversation _rendered_inp.children[
You are a helpful documentation Q&A assistant, trained to answer questions from LangSmith's documentation. LangChain is a framework for building applications using large language models. The current time is 2023-09-05 16:49:07.308007.
Relevant documents will be retrieved in the following messages.
Here is the last card in the conversation:
-1] # the last message in the conversation _rendered_inp.children[
How do I move my project between organizations?
3] _rendered_inp.children[
{'id': 'ee152e0b-0de2-48ea-94e5-a14b8c0d5178',
'inputs': [{'required': False,
'suggestions': [{'listing': {'address': '2430 Victory Park Lane '
'Unit 2508',
'baths': 2.1,
'beds': 2,
'close_date': None,
'close_price': None,
'id': '7ff2fad0-cc63-11e5-913f-f23c91c841bd',
'mls': 'NTREIS',
'mls_number': '13315265',
'price': 1350000,
'status': 'Active',
'type': 'compact_listing'},
'type': 'input_form_suggestion',
'value': '1st listing'},
{'listing': {'address': '2430 Victory Park Lane '
'Unit 2003',
'baths': 2,
'beds': 1,
'close_date': None,
'close_price': None,
'id': '33836686-d0db-11e5-b351-f23c91c841bd',
'mls': 'NTREIS',
'mls_number': '13317847',
'price': 770000,
'status': 'Active',
'type': 'compact_listing'},
'type': 'input_form_suggestion',
'value': '2nd listing'},
{'listing': {'address': '2430 Victory Park Lane '
'Unit 3001',
'baths': 7.3,
'beds': 5,
'close_date': None,
'close_price': None,
'id': 'cdaef89c-cb9a-11e5-b4c2-f23c91c841bd',
'mls': 'NTREIS',
'mls_number': '13314620',
'price': 7995000,
'status': 'Active',
'type': 'compact_listing'},
'type': 'input_form_suggestion',
'value': '3rd listing'},
{'listing': {'address': '2430 Victory Park Lane '
'Unit 2301',
'baths': 1,
'beds': 1,
'close_date': None,
'close_price': None,
'id': '7e84d768-a814-11e5-8e1e-f23c91c841bd',
'mls': 'NTREIS',
'mls_number': '13291126',
'price': 399900,
'status': 'Active',
'type': 'compact_listing'},
'type': 'input_form_suggestion',
'value': '4th listing'},
{'listing': {'address': '2430 Victory Park Lane '
'Unit 1908',
'baths': 2.1,
'beds': 2,
'close_date': None,
'close_price': None,
'id': '58a718e4-9f54-11e5-a0f8-f23c91c841bd',
'mls': 'NTREIS',
'mls_number': '13286938',
'price': 999000,
'status': 'Active',
'type': 'compact_listing'},
'type': 'input_form_suggestion',
'value': '5th listing'}],
'title': 'Which one of the following listings do you want to use?',
'type': 'input_form_input'}],
'type': 'input_form'}
assert len(_rendered_inp.children) == len(_run.inputs)
render_funcs
render_funcs (run:langfree.transform.RunData, markdown=True)
Render functions as a group of cards.
Similar to render_input
, render_funcs
will take an instance of RunData
and render a set of Shiny cards, with each card containing a function definition that was passed to OpenAI via the Function Calling API:
= render_funcs(_run)
_rendered_func assert len(_run.funcs) == len(_rendered_func.children)
This is one of the functions:
2] _rendered_func.children[
{ "type": "object", "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "input": { "type": "string" } }, "additionalProperties": false }
Here is another function:
3] _rendered_func.children[
{ "type": "object", "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "input": { "type": "string" } }, "additionalProperties": false }
render_llm_output
render_llm_output (run, width='100%', height='250px')
Render the LLM output as an editable text box.
Below is a demonstration of using render_llm_output
to produce an editable text box component. The goal is to allow the user to edit the output for fine tuning to correct errors.
render_llm_output(_tst_run)
invoke_later
invoke_later (delaySecs:int, callback:<built-infunctioncallable>)
Execute code in a shiny app with a time delay of delaySecs
asynchronously.
Footnotes
We tried other similar frameworks like Gradio, Streamlit, and Panel, but found Shiny to fit our needs the best.↩︎