You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"text": "Gists\n\nsource\n\nload_gist\n\n load_gist (gist_id:str)\n\nRetrieve a gist\n\ngistid = 'jph00/e7cfd4ded593e8ef6217e78a0131960c'\ngist = load_gist(gistid)\ngist.html_url\n\n'https://gist.github.com/jph00/e7cfd4ded593e8ef6217e78a0131960c'\n\n\n\nsource\n\n\ngist_file\n\n gist_file (gist_id:str)\n\nGet the first file from a gist\n\ngfile = gist_file(gistid)\nprint(gfile.content[:100]+\"…\")\n\n\"This is a test module which makes some simple tools available.\"\n__all__ = [\"hi\",\"whoami\"]\n\ntestfoo=…\n\n\n\nsource\n\n\nimport_string\n\n import_string (code:str, name:str)\n\n\n\n\n\nType\nDetails\n\n\n\n\ncode\nstr\nCode to import as a module\n\n\nname\nstr\nName of module to create\n\n\n\n\nsource\n\n\nis_usable_tool\n\n is_usable_tool (func:<built-infunctioncallable>)\n\nTrue if the function has a docstring and all parameters have types, meaning that it can be used as an LLM tool.\n\ndef hi(who:str):\n \"Say hi to `who`\"\n return f\"Hello {who}\"\n\ndef hi2(who):\n \"Say hi to `who`\"\n return f\"Hello {who}\"\n\ndef hi3(who:str):\n return f\"Hello {who}\"\n\nbye = \"bye\"\n\n\nassert is_usable_tool(hi)\nassert not is_usable_tool(hi2)\nassert not is_usable_tool(hi3)\nassert not is_usable_tool(bye)\n\n\nsource\n\n\nmk_toollist\n\n mk_toollist (syms)\n\n\nMarkdown(mk_toollist([hi]))\n\n\n&hi: Say hi to who\n\n\n\n\nsource\n\n\nimport_gist\n\n import_gist (gist_id:str, mod_name:str=None, add_global:bool=True,\n import_wildcard:bool=False, create_msg:bool=False)\n\nImport gist directly from string without saving to disk\n\n\n\n\n\n\n\n\n\n\nType\nDefault\nDetails\n\n\n\n\ngist_id\nstr\n\nuser/id or just id of gist to import as a module\n\n\nmod_name\nstr\nNone\nmodule name to create (taken from gist filename if not passed)\n\n\nadd_global\nbool\nTrue\nadd module to caller’s globals?\n\n\nimport_wildcard\nbool\nFalse\nimport all exported symbols to caller’s globals\n\n\ncreate_msg\nbool\nFalse\nAdd a message that lists usable tools\n\n\n\n\nimport_gist(gistid)\nimporttest.testfoo\n\n'testbar'\n\n\n\nimport_gist.__doc__\n\n'Import gist directly from string without saving to disk'\n\n\n\nimport_gist(gistid, import_wildcard=True)\nimporttest.testfoo\n\n'testbar'\n\n\n\nhi(\"Sarah\")\n\n'Hello Sarah'\n\n\n\nimporttest.__all__\n\n['hi', 'whoami']",
"text": "Importing and Exporting Dialogs\nWe use json serialization of list[dict] to represent a dialogue where dict is a serialized solveit.db_dc Message.\n\nSupported Fields\n\nfrom dialoghelper.db_dc import Message\n\n\nMessage.__annotations__\n\n{'sid': str | None,\n 'mid': str | None,\n 'content': str | None,\n 'output': str | None,\n 'input_tokens': int | None,\n 'output_tokens': int | None,\n 'msg_type': str | None,\n 'time_run': str | None,\n 'is_exported': int | None,\n 'skipped': int | None,\n 'did': int | None,\n 'i_collapsed': int | None,\n 'o_collapsed': int | None,\n 'header_collapsed': int | None,\n 'pinned': int | None}\n\n\nWhen exporting and importing we intentionally leave out these fields: - sid - to avoid duplicating sids across dialogues - mid - to ensure mid respects ordering in the new dialogue - did - since the dialogue will be imported into a different dialogue - time_run - since a dialogue may be imported/exported to other environments where execution time is not comparable.\nThe following are required: - content - msg_type - output\nAll other fields (i_collapsed, header_collapsed, … etc) are technically optional. By default we read them on import if they are available. However, there may be other dialog-consuming applications (shell sage, discord buddy, others) we want to share dialogues with where these fields are not supported by the interface.\n\n\nAttachments\nFor now attachments are not included in the importing and exporting.\nAttachments could be added as a future enhanement but would add some additional design considerations - if attachments refer to external artifacts, do the artifacts get copied? Do they get bundled as part of the export artifact? Do we create a new artifact entry with a new sid for the new dialogue or do we share artifacts?\n\n\nImplementation\n\nsource\n\n\nexport_dialog\n\n export_dialog (filename:str, did:int=None)\n\nExport dialog messages and optionally attachments to JSON\n\ntry:\n test_path = Path('test.json')\n export_dialog(test_path)\n test_msgs = test_path.read_json()\n print(test_msgs['messages'][1]['content'])\nfinally: test_path.unlink(missing_ok=True)\n\n1+1\n\n\n\nsource\n\n\nimport_dialog\n\n import_dialog (fname, add_header=True)\n\nImport dialog messages from JSON file using add_msg",
28
+
"crumbs": [
29
+
"dialoghelper"
30
+
]
31
+
},
32
+
{
33
+
"objectID": "core.html#tool-info",
34
+
"href": "core.html#tool-info",
35
+
"title": "dialoghelper",
36
+
"section": "Tool info",
37
+
"text": "Tool info\nThis is how we get a superset of tools to include:\n\nfor o in _all:\n s = globals()[o]\n if s.__name__[0]=='_' or not s.__doc__: continue\n print(f'- {s.__name__}: {s.__doc__}')\n\n- find_var: Search for var in all frames of the call stack\n- find_dialog_id: Get the dialog id by searching the call stack for __dialog_id.\n- find_msgs: Find messages in current specific dialog that contain the given information. To refer to a message found later, use its `sid` field (which is the pk).\n- find_msg_id: Get the message id by searching the call stack for __dialog_id.\n- read_msg_ids: Get all ids in current dialog.\n- msg_idx: Get relative index of current message in dialog.\n- read_msg: Get the message indexed in the current dialog.\n- del_msg: Delete a message from the dialog. Be sure to pass a `sid`, not a `mid`.\n- add_msg: Add/update a message to the queue to show after code execution completes. Be sure to pass a `sid` (stable id) not a `mid` (which is used only for sorting, and can change).\n- update_msg: Update an existing message. Provide either `msg` OR field key/values to update.\n Use `content` param to update contents. Be sure to pass a `sid` (stable id -- the pk) not a `mid`\n (which is used only for sorting, and can change).\n Only include parameters to update--missing ones will be left unchanged.\n- load_gist: Retrieve a gist\n- gist_file: Get the first file from a gist\n- is_usable_tool: True if the function has a docstring and all parameters have types, meaning that it can be used as an LLM tool.\n- import_gist: Import gist directly from string without saving to disk\n- export_dialog: Export dialog messages and optionally attachments to JSON\n- import_dialog: Import dialog messages from JSON file using `add_msg`\n- asdict: Convert `o` to a `dict`, supporting dataclasses, namedtuples, iterables, and `__dict__` attrs.\n\n\n\nsource\n\ntool_info\n\n tool_info ()",
38
+
"crumbs": [
39
+
"dialoghelper"
40
+
]
41
+
},
42
+
{
43
+
"objectID": "index.html",
44
+
"href": "index.html",
45
+
"title": "dialoghelper",
46
+
"section": "",
47
+
"text": "This file will become your README and also the index of your documentation.",
48
+
"crumbs": [
49
+
"dialoghelper"
50
+
]
51
+
},
52
+
{
53
+
"objectID": "index.html#developer-guide",
54
+
"href": "index.html#developer-guide",
55
+
"title": "dialoghelper",
56
+
"section": "Developer Guide",
57
+
"text": "Developer Guide\nIf you are new to using nbdev here are some useful pointers to get you started.\n\nInstall dialoghelper in Development mode\n# make sure dialoghelper package is installed in development mode\n$ pip install -e .\n\n# make changes under nbs/ directory\n# ...\n\n# compile to have changes apply to dialoghelper\n$ nbdev_prepare",
58
+
"crumbs": [
59
+
"dialoghelper"
60
+
]
61
+
},
62
+
{
63
+
"objectID": "index.html#usage",
64
+
"href": "index.html#usage",
65
+
"title": "dialoghelper",
66
+
"section": "Usage",
67
+
"text": "Usage\n\nInstallation\nInstall latest from the GitHub repository:\n$ pip install git+https://github.com/AnswerDotAI/dialoghelper.git\nor from conda\n$ conda install -c AnswerDotAI dialoghelper\nor from pypi\n$ pip install dialoghelper\n\n\nDocumentation\nDocumentation can be found hosted on this GitHub repository’s pages. Additionally you can find package manager specific guidelines on conda and pypi respectively.",
68
+
"crumbs": [
69
+
"dialoghelper"
70
+
]
71
+
},
72
+
{
73
+
"objectID": "index.html#how-to-use",
74
+
"href": "index.html#how-to-use",
75
+
"title": "dialoghelper",
76
+
"section": "How to use",
77
+
"text": "How to use\nFill me in please! Don’t forget code examples:\n\n1+1\n\n2",
0 commit comments