Download examples/openai_tool_flow.py from OkeyMetaLtd/Reframr-RFM-v2-Base: direct link, hf CLI and curl.
- Browser
- Download file 2.09 kB
-
https://huggingface.co/OkeyMetaLtd/Reframr-RFM-v2-Base/resolve/main/examples/openai_tool_flow.py
- Command line
-
hf download hf://OkeyMetaLtd/Reframr-RFM-v2-Base/examples/openai_tool_flow.py
-
curl -L -o openai_tool_flow.py https://huggingface.co/OkeyMetaLtd/Reframr-RFM-v2-Base/resolve/main/examples/openai_tool_flow.py
2.09 kB
| from __future__ import annotations | |
| import json | |
| import sys | |
| from pathlib import Path | |
| REPO_ROOT = Path(__file__).resolve().parents[1] | |
| if str(REPO_ROOT) not in sys.path: | |
| sys.path.insert(0, str(REPO_ROOT)) | |
| from reframr.cli import compose_generation_context | |
| from reframr.model import ReframrModel | |
| def main() -> None: | |
| model = ReframrModel.load(REPO_ROOT / "model.safetensors") | |
| messages = [ | |
| { | |
| "role": "system", | |
| "content": ( | |
| "Answer from tool evidence when it is provided. " | |
| "If the question needs fresh information and no source is available, say what is missing." | |
| ), | |
| }, | |
| { | |
| "role": "user", | |
| "content": "Who won the Rivergate mayoral runoff, and what number should I cite?", | |
| }, | |
| { | |
| "role": "assistant", | |
| "tool_calls": [ | |
| { | |
| "id": "call_1", | |
| "type": "function", | |
| "function": { | |
| "name": "web.search", | |
| "arguments": json.dumps({"query": "Rivergate mayoral runoff result vote share"}), | |
| }, | |
| } | |
| ], | |
| }, | |
| { | |
| "role": "tool", | |
| "tool_call_id": "call_1", | |
| "name": "web.search", | |
| "content": json.dumps( | |
| { | |
| "ok": True, | |
| "source": { | |
| "title": "Local Civic Wire", | |
| "url": "https://example.org/rivergate-runoff", | |
| "snippet": "Mara Ibekwe won the Rivergate mayoral runoff with 52.4 percent of the vote.", | |
| }, | |
| } | |
| ), | |
| }, | |
| ] | |
| context = compose_generation_context("", messages=messages) | |
| print( | |
| model.generate_text( | |
| context, | |
| max_tokens=90, | |
| temperature=0.58, | |
| top_k=64, | |
| top_p=0.92, | |
| repetition_penalty=1.25, | |
| ) | |
| ) | |
| if __name__ == "__main__": | |
| main() | |