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

Create new & manage Assistants #334

Merged
merged 88 commits into from
May 28, 2024

Conversation

stephan-buckmaster
Copy link
Contributor

@stephan-buckmaster stephan-buckmaster commented May 8, 2024

Want to get some feedback where to take this. No tests included.

When adding an assistant, it is tied to a model ... But I didn't want to hard-code the entries in the drop-down. So it seemed like a good time to store the "models" in a table. Can't really call a model just, model. So I added an ai_api_models table.

To reach the new feature with this change, go to "Settings," Then there will be a "New Assistant" link on the left. Save/Cancel work. Editing existing work too.

After one has added a nice collection of Assistants, this is not going to work anymore. The column will become too long, both on the settings pages, and on the regular pages. I suggest to do a "top 5", after which to show a link "more", which will open up a new page with a table of the assistants, which can be paged as needed.

Also haven't looked into the delete part

(To fix #308

stephan-buckmaster and others added 27 commits April 16, 2024 06:44
…crypted_data setting and use update! instead of update in tests
@krschacht
Copy link
Contributor

@stephan-buckmaster thanks for taking this on! I did a super quick skim on my phone and I think you’re on the right track.

The new table/model name is long. How about just LLM? You’d need to add that to the special rails config file that lets you adjust capitalization, inflections is maybe what it’s called?. We already did that once for “AI” so you can search. But LLM feels like the right concept since an Assistant subsumes it as a higher level concept. Plus, we may eventually have a table for image generation models.

I couldn’t tell if Assistant now has a foreign key to LLM table, but let’s do that so thinks are officially linked up. We should be able to do assistant.llm and llm.assistants for the basic two way association.

I forget the other notes on the issue but this is definitely looking good!

@krschacht
Copy link
Contributor

I just re-read your notes and had one more thought: regarding the problems of too many assistants in the left nav, I think a decent approach for v1 would be:

  • Let the page loading select all assistants
  • If there are more than 5 then they are hidden via CSS and a “See more” link is present
  • Clicking “see more” simply unhides the rest of them and they appear inline, pushing the conversations further down

It’s not the perfect long-term solution, but that’ll hold us for awhile. It saves having to create a new page or do any kind of pagination or anything like that. Plus, all that has to be solved for conversations long before it’ll be a problem for assistants. :)

@stephan-buckmaster
Copy link
Contributor Author

The issue of #335 would suggest a different UI: One would choose the system prompt together with entering the present question. Might be better. Of the schema of the assistants table only the name, model and instructions are of interest, at least to me. So 335 may be a better solution, and makes this one obsolete. Unless there are other kinds of configurations planned

@stephan-buckmaster
Copy link
Contributor Author

Yes, when regenerating responses with an assistant that doesn't support images, it is pretty transparent, the popup really works. When I use an assistant that doesn't support images it has responded with

I tried to retrieve some information to help answer your question, but I encountered an unexpected error. Could you provide more details regarding the image you mentioned as "ABC"?

So I dropped the validation on model/assistants. But added migration to populate the assistant-id for documents if possible.

I looked through the exchange above, and I think I covered all feedback. (Plan to continue with the 341 issue)

@krschacht
Copy link
Contributor

@stephan-buckmaster great, thanks! so just be sure: this PR should be ready for me to give one final pass and then merge in?

@stephan-buckmaster
Copy link
Contributor Author

Yes; hope all is covered.

@krschacht
Copy link
Contributor

@stephan-buckmaster can you explain the "allow_deleted_assistant" flag? What is the case where we need to still support updating messages which are part of an assistant which has been deleted?

@stephan-buckmaster
Copy link
Contributor Author

This is the versions navigation thing. Without the flag, when it is commented out,

 errors.add(:assistant, 'has been deleted') if assistant.deleted? ######## && !allow_deleted_assistant`

this test fails:

MessagesControllerTest#test_even_when_assistant_is_deleted_update_succeeds_for_a_new_version_in_the_URL

@krschacht
Copy link
Contributor

@stephan-buckmaster Oh shoot... as I'm going through the code in detail, it just occurred to me why some documents are not associated with assistants.

Documents can either belong to messages -or- assistants, according to the OpenAI domain model. https://platform.openai.com/docs/api-reference/files (I had to rename "File" to "Document" since file is a reserved word in Ruby).

I set up these models to reflect the domain model of OpenAI. However, we aren't fully utilizing this domain model yet since I haven't implemented the Assistants API. I think I need to unwind a little bit of this.

I can handle this on the branch, it's a small change. However, I didn't fully understand what problem it was causing when you discovered that assistant_id was nil on some documents? I too thought it was a bug, when originally discovered, but did you wire that up just because you caught the oversight or because there was something odd that was happening by having those not connected?

@stephan-buckmaster
Copy link
Contributor Author

Interesting. If the message has an assistant, then the document belongs to a message doesn't really need an assistant column. So it looked redundant to me, so I assumed it was for optimization. But if it is not always populated, then it looked like a gap.

Are you saying an assistant can respond, and include documents which will then be tied to the message? Again, the message's role (being assistant) would tell the same thing then, making the assistant-id column in documents redundant.

So yes, if it is not helpful, might as well remove commits e49eef9 and ea07426. It almost seems like the test assertions should be negated

@krschacht
Copy link
Contributor

In the OpenAI universe, you can create an Assistant (they call it a GPT). You can configure this with custom instructions, give it access to tools, and optionally give it access to files/documents. When a document is associated with an assistant, than any conversation you have with that assistant, it may choose to reference the document when formulating a reply. Whereas when a document is associated with a message, then it's only in the context of that message history (i.e. conversation) that the assistant would reference the document. Again, HostedGPT doesn't have this capability built yet to reference assistant's documents but when I was creating those models and reading through the API docs I thought: "that makes sense! we should support that too." :)

I went ahead and reverted a couple of the small assertions and pushed a new commit. I'll continue working my way through the PR, and cleaning up a couple things here and there, and ultimately merge it into main soon (probably not today but hopefully tomorrow). But lots in those two commits of yours is still good code, like creating a Message with an associated Document — I never had that test case in there, and I should have. But I just flip the bit on a couple assertions around document.assistant.

Onward! This PR has tons of good stuff and I'm excited to get it in so I can continue building upon it, since I'm doing so much with tools and I want to start letting people give different tools to different assistantas.

@krschacht
Copy link
Contributor

krschacht commented May 27, 2024

@stephan-buckmaster in this PR you've added ENV variables for the development & test database names. However, rails has a built-in way to override the database: DATABASE_URL.

The format is: postgres://username:password@localhost:5432/custom_database_name"

Local often has no username & password and default port so so it looks like this (note the three slashes)
DATABASE_URL="postgres:///custom_database_name"

Of course, if you are overriding for development and test you'd want to do this in each environment:

DATABASE_URL="postgres:///development_database_name" bin/rails server
DATABASE_URL="postgres:///test_database_name" bin/rails test

Would this work for you or do you think you still need a custom ENV variable for your use case? I'd probably put my dev one into my bash profile so that it's always present in my shell and then have a bash alias for running tests which does that whole test command with a different database_url

@krschacht krschacht changed the title Manage Assistants Create new & manage Assistants May 28, 2024
@stephan-buckmaster
Copy link
Contributor Author

It would be a 80% solution to just use DATABASE_URL (usually I have the git branch logic inside database.yml)

I don't quite understand your reluctance, to me it looks quite transparent. In terms of security there is alreay ENV evaluation in the file. What could go wrong? Someone who doesn't set the var will not notice any difference. And for prod there is no change.

@krschacht
Copy link
Contributor

I’m good with it! I’ll leave it in. It sounds like DATABASE_URL doesn’t work for your context so happy to have the extra ENV.

@krschacht krschacht merged commit ca13237 into AllYourBot:main May 28, 2024
6 checks passed
@stephan-buckmaster
Copy link
Contributor Author

Thanks for all the feedback above, @krschacht !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow creating (and deleting) your own Assistant & the ability to set the specific model that is being used
2 participants