Whinchat (LLM assistant)
ChatBlock
¶
ChatBlock(item_id: str | None = None, collection_id: str | None = None, init_data: dict | None = None, unique_id: str | None = None)
Bases: DataBlock
This block uses API calls to external LLMs via Langchain to provide a conversational interface to a user's data.
Implemented models include:
- the GPT series of models from OpenAI
- Claude from Anthropic
Each needs the server to be configured with the corresponding API keys:
OPENAI_API_KEY,ANTHROPIC_API_KEY.
A discussion of this block can be found in:
Jablonka et al, Digital Discovery, 2023,2, 1233-1250, DOI: 10.1039/d3dd00113j
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id
|
str | None
|
The item to which the block is attached, or |
None
|
collection_id
|
str | None
|
The collection to which the block is attached. |
None
|
init_data
|
dict | None
|
A dictionary of data to initialise the block with. |
None
|
unique_id
|
str | None
|
A unique id for the block, used in the DOM and database. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
accepted_file_extensions |
|
|
block_db_model |
|
|
block_id |
|
|
blocktype |
|
|
data |
|
|
defaults |
dict
|
|
description |
|
|
multi_file |
bool
|
Whether this block can accept multiple files as input. |
name |
|
|
plot_functions |
|
|
version |
str
|
The implementation version of this particular block. |
data
¶
data = {'item_id': item_id, 'collection_id': collection_id, 'blocktype': blocktype, 'block_id': block_id, None: defaults}
defaults
¶
defaults: dict = {'system_prompt': 'You are whinchat (lowercase w), a virtual data managment assistant that helps materials chemists manage their experimental data and plan experiments. You are deployed in the group of Professor Clare Grey in the Department of Chemistry at the University of Cambridge.\nYou are embedded within the program datalab, where you have access to JSON describing an ‘item’, or a collection of items, with connections to other items. These items may include experimental samples, starting materials, and devices (e.g. battery cells made out of experimental samples and starting materials).\nAnswer questions in markdown. Specify the language for all markdown code blocks. You can make diagrams by writing a mermaid code block or an svg code block. When writing mermaid code, you must use quotations around each of the labels (e.g. A["label1"] --> B["label2"])\nBe as concise as possible. When saying your name, type a bird emoji right after whinchat 🐦.\n ', 'temperature': 0.2, 'model': 'gpt-4o', 'available_models': AVAILABLE_MODELS}
continue_conversation
¶
continue_conversation(prompt: str | None) -> None
Continues the conversation based on the passed user prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str | None
|
The textual response from the user. |
required |
events_by_name
¶
Returns a dict of registered events for this block.
from_web
¶
from_web(data: dict)
Initialise the block state from data passed via web request with a given item, collection and block ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
The block data to initialiaze the block with. |
required |
null_event
¶
null_event(**kwargs)
A null debug event that does nothing but logs its kwargs and overwrites the data dict with the args.
process_events
¶
Handle any supported events passed to the block.
start_conversation
¶
Starts a new conversation with the system prompt, embedding the current item or collection data.
to_db
¶
to_db() -> dict
returns a dictionary with the data for this block, ready to be input into mongodb
to_web
¶
Returns a JSON serializable dictionary to render the data block on the web.
update_from_web
¶
update_from_web(data: dict)
Update the block with validated data received from a web request. Will strip any fields that are "computed" or otherwise not controllable by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
A dictionary of data to update the block with. |
required |