https://github.com/tyler-dodge/org-assistant Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} tyler-dodge / org-assistant Public * Notifications * Fork 2 * Star 30 Org babel extension for Chat Assistant APIs such as ChatGPT License GPL-3.0 license 30 stars 2 forks Star Notifications * Code * Issues 1 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights tyler-dodge/org-assistant This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 1 branch 5 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/t] Use Git or checkout with SVN using the web URL. [gh repo clone tyler-] Work fast with our official CLI. Learn more about the CLI. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @tyler-dodge tyler-dodge Add section describing introspecting the conversation. ... a30938b May 1, 2023 Add section describing introspecting the conversation. a30938b Git stats * 80 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time screenshots test .ert-runner .gitignore .travis.yml LICENSE README.md default.nix org-assistant.el runbook.org shell.nix View code [ ] org-assistant.el - Org babel extension for Chat Assistant APIs Installation Usage Conversation Evaluation Rules Example Comparison With Other AI Packages org-assistant.el and org-ai.el org-assistant.el and gptel Feel free to add a pull request detailing the differences if there is a package I missed Commands org-assistant org-babel-execute:assistant org-babel-execute:? org-assistant-explain-function org-assistant-write-docstring Customization Contributing README.md org-assistant.el - License MELPA Version Org babel extension for Chat Assistant APIs --------------------------------------------------------------------- org-assistant provides support for accessing chat APIs such as ChatGPT in the context of an org notebook. example Installation Org-assistant is available on MELPA M-x package-install [RET] org-assistant [RET] Usage It provides a function named org-assistant that serves as entrypoint for displaying an org assistant buffer. Also, it can be used in any org file by using a src block like #+BEGIN_SRC assistant or # +BEGIN_SRC ?. The API Key is looked up via org-assistant-auth-function, which has meen tested using the MacOS Keychain. Alternatively, org-assistant-auth-function can be a string and directly set to your API key. (setq org-assistant-auth-function "") Calling org-assistant interactively will generate an org-assistant buffer for you. It can be set to a keybinding for quick use like below: (global-set-key (kbd "C-x C-o") #'org-assistant) Conversation Evaluation Rules * The org tree is traversed up in order to generate the message list when sending information to the chat endpoint. * It will only use messages from the branch of the tree that the block that initiated the request is in. * It does not include example blocks or source blocks that appear later in the org buffer than the initiating block. * noweb support is enabled for all blocks in the conversation based on the initiating block having the :noweb flag set. * Example blocks are treated as being responses from the assistant by default if they occur after user messages. * If the example block is before any user source block, they are treated as system messages to the assistant instead. See org-babel-execute:assistant for more details. Example * Chat User Question #+BEGIN_SRC ? Hi #+END_SRC AI Response #+BEGIN_EXAMPLE Hello! How can I assist you today? #+END_EXAMPLE When the output is set to png file, the image generation APIs are called instead. * Image Generation User Question #+BEGIN_SRC ? :file sphere.png Generate a sphere #+END_SRC AI Response #+RESULTS: file:sphere.png You can introspect the sent conversation using the :echo flag. * Branching Echo #+BEGIN_SRC ? This is the user. Repeat verbatim only: "This is the system" #+END_SRC #+RESULTS: #+BEGIN_EXAMPLE "This is the system" #+END_EXAMPLE ** Branch A #+BEGIN_SRC ? :echo Response A #+END_SRC #+RESULTS: #+BEGIN_EXAMPLE (user . "This is the user. Repeat verbatim only: \"This is the system\"") (assistant . "\"This is the system\"") (user . "Response A") #+END_EXAMPLE ** Branch B #+BEGIN_SRC ? :echo Response B #+END_SRC #+RESULTS: #+BEGIN_EXAMPLE (user . "This is the user. Repeat verbatim only: \"This is the system\"") (assistant . "\"This is the system\"") (user . "Response B") #+END_EXAMPLE Comparison With Other AI Packages org-assistant.el and org-ai.el * org-ai.el is focused more on runtime interaction with AI * org-assistant.el is focused more on reproducible sessions via org babel * org-assistant.el supports branching conversations * org-assistant.el is not meant to be used downstream as a library for AI endpoint interactions. * In org-assistant.el, all interaction is async using org-babel, which allows for notebook style prompt development * In org-ai.el, interaction is synchronous and inline, which is better for in-editor use cases * org-ai.el supports a lot of other AI use cases like text to speech org-assistant.el and gptel * Most of the same differences and similarities apply from org-assistant.el and org-ai.el Feel free to add a pull request detailing the differences if there is a package I missed Commands org-assistant Prompt the user for an initial prompt for the assistant. Then display a window with the buffer containing the response. org-babel-execute:assistant Execute an 'org-assistant' in an org-babel context. PARAMS is used to enable noweb mode. If :echo is set, return the conversation that would be sent to the endpoint instead of evaluating. If :list-models is set, the 'org-assistant-models-endpoint' will be called instead. TEXT must be empty if :list-models is set. This is intended to be called via org babel in a src block with Ctrl-C Ctrl-C like: #+BEGIN_SRC assistant Hi #+END_SRC The response from the assistant will be in the example block following: #+BEGIN_EXAMPLE Response #+END_EXAMPLE All of the messages that are in the same branch of the org tree are included in the request to the assistant. * Question #+BEGIN_SRC assistant Hi #+END_SRC #+BEGIN_EXAMPLE Response #+END_EXAMPLE #+BEGIN_SRC assistant What's up? #+END_SRC Running babel on the second assistant block will send the conversation: User: Hi Assistant: Response User: What's up? Running babel on the first assistant block will only include the messages before it: User: Hi Only messages in the same branch will be included: * Question #+BEGIN_SRC assistant Hi #+END_SRC #+BEGIN_EXAMPLE Response #+END_EXAMPLE ** Branch A #+BEGIN_SRC assistant Branch A #+END_SRC #+BEGIN_EXAMPLE Branch A Response #+END_EXAMPLE ** Branch B #+BEGIN_SRC assistant Branch B #+END_SRC #+BEGIN_EXAMPLE Branch B Response #+END_EXAMPLE If you ran Ctrl-C Ctrl-C on Branch B's src block the conversation sent to the endpoint would be: User: Hi Assistant: Response User: Branch B Assistant: Branch B Response 'org-assistant' also supports image generation. If the :file attribute is set, the image API will be used. The following is an example of using the image endpoint: #+BEGIN_SRC assistant :file output.png An image of the GNU mascot #+END_SRC org-babel-execute:? See 'org-babel-execute:assistant'. ARGS is routed as is. org-assistant-explain-function Ask the assistant to explain the function at point. org-assistant-write-docstring Ask the assistant to generate a docstring for the function at point. Customization * org-assistant-auth-function: Function used to get the secret key. Optionally can be set directly to a string, in which case it will be used as the OpenAI key. * org-assistant-mode-visual-line-enabled: When non-nil, visual-line-mode is enabled with org-assistant-mode. * org-assistant-buffer-name: The buffer name used for the org-assistant buffer. * org-assistant-mode-line-format: The mode-line-format used by the org-assistant buffer. Set to nil to use mode-line-format instead. * org-assistant-model: The model used for the assistant. * org-assistant-curl-command: The path to the curl command used to run requests. * org-assistant-endpoint: The endpoint used for the assistant. org-assistant-endpoint-path-chat and org-assistant-endpoint-path-image contain the paths for the respective APIs. * org-assistant-endpoint-path-chat: The path used for the chat API. See org-assistant-endpoint for the domain. * org-assistant-endpoint-path-models: The path used for the list models API. See org-assistant-endpoint for the domain. * org-assistant-endpoint-path-image: The endpoint used for the assistant. * org-assistant-parallelism: The max inflight requests to send with org-assistant at once. Contributing Contributions welcome, but forking preferred. I plan to actively maintain this, but I will be prioritizing features that impact me first. I'll look at most pull requests eventually, but there is no SLA on those being accepted. Also, I will only respond to pull requests on a case by case basis. I have no obligation to comment on, justify not accepting, or accept any given pull request. Feel free to start a fork that has more support in that area. If there's a great pull request that I'm slow on accepting, feel free to fork and rename the project. About Org babel extension for Chat Assistant APIs such as ChatGPT Resources Readme License GPL-3.0 license Stars 30 stars Watchers 3 watching Forks 2 forks Report repository Releases 5 1.0 Latest May 1, 2023 + 4 releases Packages 0 No packages published Languages * Emacs Lisp 98.6% * Nix 1.4% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. 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.