Skip to content
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

feat: AI #1035

Merged
merged 67 commits into from
Oct 2, 2024
Merged

feat: AI #1035

merged 67 commits into from
Oct 2, 2024

Conversation

nikkothari22
Copy link
Member

@nikkothari22 nikkothari22 commented Aug 29, 2024

We can call it the "Three Eyed Raven" if we want it to be cringe.

This PR allows end users to create AI agents/assistants. It's based on OpenAI's Assistants in ChatGPT and supports function calling.

The idea is that we can create an AI assistant with some instructions - these instructions will have useful context like the current user's employee ID / company / department - embedded via Jinja tags. Custom apps can add additional variables that could be used in the instruction. Whenever the bot is called, these instructions are sent to it.

Adding instructions via Jinja:

image

Each Bot could also have a set of "functions" - where they can call any function in the system. Some standard functions like get_list, get_doc etc will be available, but you could create a "Raven AI Function" and define it's path (get that from commit) and it's function schema in the JSON Schema format.

Example (still WIP):
Function to get the retirement age for a given date of birth (pretty simple to begin with - will add more complex examples later)
image

When you send a DM to an AI bot, it automatically creates a thread with a response. Note here how it knew my name and department even though the end user did not send any instruction directly:

image

Finally, it can parse data that it gets from the user, and then call your custom functions (note how it converts the date from a long string to YYYY-MM-DD format). In this case, it just calls the custom function (hrms.overrides.employee_master.get_retirement_date) that we provided.

image

This PR needs #1017 to be complete first - threads is what allows the assistant to have conversations with context.

Checklist:

  • OpenAI Settings
  • Threads marked as "AI" threads
  • Bots create a ChatGPT assistant
  • Bots can have dynamic instructions using Jinja. A standard list of variables to be available out of the box from Raven for apps like ERPNext (company, department, company list) and Frappe HR (employee ID etc). Other apps like LMS can extend these variables for things like Course and Batch ID (these are just jinja variables so this feature already exists in Frappe)
  • Sending a DM to a bot creates a thread and maintains context via thread conversations.
  • Ability to send files to the assistant
  • Only bots with write permissions can write to the database. Else the functions called are rolled back.
  • Response from bots to be structured to include document links which we can then show on the Raven interface. (Future scope: Might also be possible to use custom JSON formats to render buttons etc in the chat interface)
  • Allow users to create these Bots and Functions from the Raven interface (and without using JSON).
  • Allow users to set default values for certain variables when calling functions

@nikkothari22
Copy link
Member Author

Closes #753

@nikkothari22 nikkothari22 self-assigned this Aug 29, 2024
@nikkothari22 nikkothari22 added the ✨ Feature Created by Linear-GitHub Sync label Aug 29, 2024
@nikkothari22 nikkothari22 marked this pull request as ready for review October 1, 2024 18:02
@nikkothari22 nikkothari22 merged commit 8ea706a into develop Oct 2, 2024
3 checks passed
@nikkothari22 nikkothari22 deleted the three-eyed-raven branch October 2, 2024 14:24
@nikkothari22 nikkothari22 restored the three-eyed-raven branch October 2, 2024 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend ✨ Feature Created by Linear-GitHub Sync UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant