-
Notifications
You must be signed in to change notification settings - Fork 40
Add contrib. prompt library #927
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
Signed-off-by: Claudio Spiess <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>
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.
Nitpick: line 31, you could write with: \n\n
and remove those newlines from line 29. Also remove text from line 23 (the body is simply a call).
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.
Hi @claudiosv, thanks for the PR! It looks great to me. The only comment is with regards to the shape of schemas for tool calling. We have a different format in examples/tools/calc.pdl. Also if you look at this: https://github.com/ibm-granite-community/granite-snack-cookbook/blob/main/recipes/Function-Calling/Function_Calling.ipynb
They are getting a different format for the schema I believe...
(?)
Signed-off-by: Claudio Spiess <[email protected]>
Thanks for the feedbacks! I checked the format in tools:
data:
- name: calc
description: Calculator function
arguments:
expr:
type: string
description: Arithmetic expression to calculate Following the example in the notebook you linked, just before def calculator(expr: str):
"""
Calculator function
Args:
expr: Arithmetic expression to calculate
"""
from transformers.utils import get_json_schema
tools = [get_json_schema(tool)["function"] for tool in (calculator,)]
tools Produces: [{'name': 'calculator',
'description': 'Calculator function',
'parameters': {'type': 'object',
'properties': {'expr': {'type': 'string',
'description': 'Arithmetic expression to calculate'}},
'required': ['expr']}}] It seems like the "arguments" version in
I think it makes sense to remove the first layer of the dictionaries i.e. |
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.
LGTM
* Initial prompt library Signed-off-by: Claudio Spiess <[email protected]> * Documentation and fixes Signed-off-by: Claudio Spiess <[email protected]> * Finish prompt lib docs Signed-off-by: Claudio Spiess <[email protected]> * Address feedback Signed-off-by: Claudio Spiess <[email protected]> --------- Signed-off-by: Claudio Spiess <[email protected]>
* feat: remove tauri cli support for running python interpreter This also updates the tauri cli to rename runr -> run (run previously invoked the python interpreter). And adds stub support for --data, --data-file, --trace command line options (not implemented yet). Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * chore: bump rust dependencies to resolve alert Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * test: tauri github actions test should apt install the deb This also removes the beeai compiler test in that workflow, as we now cover that in the core rust interpreter tests. Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * feat: support for --data and --data-file in rust interpreter Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * Add optimizer module Signed-off-by: Claudio Spiess <[email protected]> * Remove BAM Signed-off-by: Claudio Spiess <[email protected]> * Initial prompt library Signed-off-by: Claudio Spiess <[email protected]> * Clean up & bring in changes Signed-off-by: Claudio Spiess <[email protected]> * AST dump fixes Signed-off-by: Claudio Spiess <[email protected]> * Documentation and fixes Signed-off-by: Claudio Spiess <[email protected]> * Finish prompt lib docs Signed-off-by: Claudio Spiess <[email protected]> * Address feedback Signed-off-by: Claudio Spiess <[email protected]> * Lint Signed-off-by: Claudio Spiess <[email protected]> * fix: begin phasing in Metadata (common defs, etc. attrs) into rust AST Rather than duplicating this "metadata" logic -- the stuff common to all non-literal blocks. This just starts the migration. The main trick is to use the serde `flatten` capability, so that we can maintain a separate Metadata struct in Rust, but have it flattened into the enclosing object for serde. Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * chore: update granite-io dependency (#896) Signed-off-by: Louis Mandel <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * refactor: move def attr into Metadata (rust interpreter) Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * feat: introduce Expr typing and apply it to IfBlock.condition Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * feat: update rust Call AST to use Expr for condition attr Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * chore: bump to rust 2024 edition Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * feat: continue to flesh out block metadata structure in rust Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * refactor: add metadata attr to remaining rust block asts This also adds initial scaffolding for timing, and adds a ModelBlock and ArrayBlockBuilder. Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * feat: update rust Repeat AST to use Expr for `for` attr (#904) Signed-off-by: Louis Mandel <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * refactor: introduce Advanced enum to rust AST Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * refactor: refactor rust ast to place metadata in common struct And start populating the timing info (incomplete). Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * fix: improve deserialization of python-generated model block traces Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * fix: in rust ast, allow ModelBlock model to be an expr Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * feat: initial pdl__id and --trace support for rust interpreter Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * fix: update rust interpreter to create Data blocks for expr eval, and model_input trace field Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * fix: populate trace context field in rust interpreter Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * Update stop sequences in parameters (#861) * Stop sequence parameter update to align with ollama Signed-off-by: Jing Chen <[email protected]> * Update results Signed-off-by: Jing Chen <[email protected]> --------- Signed-off-by: Jing Chen <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * refactor: extract platform-generic logic from run_ollama_model() handler Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * fix: rust interpreter was not handling pdl__context for re-runs of traces This only covers the run_model code path, but it's a start. Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * feat: improve support for importing stdlib in python code blocks Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * skeleton-of-thought example (#919) Signed-off-by: Mandana Vaziri <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * Bump litellm and openai versions (#920) Signed-off-by: Mandana Vaziri <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * fix: improve support for rust interpreter python imports from venv Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * chore: bump tauri and npm dependencies And leverage the new prevent overflow feature of tauri. Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * chore: bump ui to 0.6.1 (#921) Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * fix: rust ast support for gsm8k, including jsonl parser The program may not run 100% yet, but it parses now. Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * chore: bump rust dependencies Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * feat: improve support for tool calling in ollama-rs We need to send a system prompt to some models. Plus add some stubs for pydantic for python tool execution. This also includes nascent support for openai-rs (not fully funcitonal yet). Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * Fully qualify import (#930) Signed-off-by: Ed Snible <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * feat: some regex parser support for rust interpreter Split mode TODO! Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * Change to sys.path for python code block (#931) Signed-off-by: Mandana Vaziri <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * granite-io hallucination demo example and notebook (#932) Signed-off-by: Mandana Vaziri <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * Lint Signed-off-by: Claudio Spiess <[email protected]> * Refactor Signed-off-by: Claudio Spiess <[email protected]> * Tests Signed-off-by: Claudio Spiess <[email protected]> * Formatting Signed-off-by: Claudio Spiess <[email protected]> * Lint Signed-off-by: Claudio Spiess <[email protected]> * Skip tests for now Signed-off-by: Claudio Spiess <[email protected]> * Update schema Signed-off-by: Claudio Spiess <[email protected]> * Add contrib. prompt library (#927) * Initial prompt library Signed-off-by: Claudio Spiess <[email protected]> * Documentation and fixes Signed-off-by: Claudio Spiess <[email protected]> * Finish prompt lib docs Signed-off-by: Claudio Spiess <[email protected]> * Address feedback Signed-off-by: Claudio Spiess <[email protected]> --------- Signed-off-by: Claudio Spiess <[email protected]> * Fixed the bug where pdl.__version__ was not set (#882) It wasn't set previously because importlib searches for the distribution name and not the module's top-level name. Fallbacks are in place to revert to searching for 'pdl', and if that fails, it fallsback to the hardcoded version in _version.py Signed-off-by: Abi Ullattil <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * chore: update pre-commit tools (#937) Signed-off-by: Louis Mandel <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * Use granite-io async interface (#936) Signed-off-by: Louis Mandel <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * Lint Signed-off-by: Claudio Spiess <[email protected]> * chore: bump ui dependences Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * fix: skip failing execution tests (#938) Signed-off-by: Louis Mandel <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * independent implementation (#934) * independent implementation Signed-off-by: Mandana Vaziri <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * feat: add a `parse_dict` function to `pdl_parser` (#943) Signed-off-by: Louis Mandel <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> * Address feedback 1 Signed-off-by: Claudio Spiess <[email protected]> * Address feedback 2 Signed-off-by: Claudio Spiess <[email protected]> * Lint & fix mypy module warning Signed-off-by: Claudio Spiess <[email protected]> * Skip tests again Signed-off-by: Claudio Spiess <[email protected]> * Try to resolve wikipedia package in ci Signed-off-by: Claudio Spiess <[email protected]> * Fix rebase Signed-off-by: Claudio Spiess <[email protected]> * Fix pyproject Signed-off-by: Claudio Spiess <[email protected]> * Move multiprocess to optional Signed-off-by: Claudio Spiess <[email protected]> * Add ipython to pdl-live Signed-off-by: Claudio Spiess <[email protected]> * Fix trace metadata Signed-off-by: Claudio Spiess <[email protected]> * Add documentation Signed-off-by: Claudio Spiess <[email protected]> * Add optimizer test PDL Signed-off-by: Claudio Spiess <[email protected]> * Add config and expand docs Signed-off-by: Claudio Spiess <[email protected]> --------- Signed-off-by: Nick Mitchell <[email protected]> Signed-off-by: Claudio Spiess <[email protected]> Signed-off-by: Louis Mandel <[email protected]> Signed-off-by: Jing Chen <[email protected]> Signed-off-by: Mandana Vaziri <[email protected]> Signed-off-by: Ed Snible <[email protected]> Signed-off-by: Abi Ullattil <[email protected]> Co-authored-by: Nick Mitchell <[email protected]> Co-authored-by: Louis Mandel <[email protected]> Co-authored-by: Jing Chen <[email protected]> Co-authored-by: Mandana Vaziri <[email protected]> Co-authored-by: Nick Mitchell <[email protected]> Co-authored-by: Ed Snible <[email protected]> Co-authored-by: Abi Ullattil <[email protected]>
* Initial prompt library Signed-off-by: Claudio Spiess <[email protected]> * Documentation and fixes Signed-off-by: Claudio Spiess <[email protected]> * Finish prompt lib docs Signed-off-by: Claudio Spiess <[email protected]> * Address feedback Signed-off-by: Claudio Spiess <[email protected]> --------- Signed-off-by: Claudio Spiess <[email protected]>
* Initial prompt library Signed-off-by: Claudio Spiess <[email protected]> * Documentation and fixes Signed-off-by: Claudio Spiess <[email protected]> * Finish prompt lib docs Signed-off-by: Claudio Spiess <[email protected]> * Address feedback Signed-off-by: Claudio Spiess <[email protected]> --------- Signed-off-by: Claudio Spiess <[email protected]>
This PR introduces a prompt library in the
contrib/
folder. Examples are provided inexamples/prompt_library
. Extensive documentation provided indocs/tutorial.md
.The contributed modules can be imported via: