-
Notifications
You must be signed in to change notification settings - Fork 325
Support for privateGPT, including support for RAG functions like rspecting context and parsing of sources #312
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
Conversation
@Aquan1412 Thanks for the PR. I had a look at the code, It uses free/global variables and uses some Could you run |
Thanks for cleaning up the code, I'm unfortunately not very experienced writing elisp code. I ran the command you asked for, however, the output is quite large, which is why I appended it as a file to this comment. The user query and the expected response are as follows:
|
From what I can see, you're not actually buffering the sources from each response.
|
As far as I'm aware,the list of sources is the same across all chunks. I didn't find an explicit confirmation in the privateGPT API description, but in all my tests it was like that. |
Wow, that's really wasteful API design. It's sending about 200-1000x as
much JSON as required then.
…On Sun, May 19, 2024, 1:43 AM Aquan1412 ***@***.***> wrote:
As far as I'm aware,the list of sources is the same across all chunks. I
didn't find an explicit confirmation in the privateGPT API description, but
in all my tests it was like that.
Therefore I only always reset the chunk, to avoid parsing the list of
sources for each chunk.
—
Reply to this email directly, view it on GitHub
<#312 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACBVOLFKQJT7U5NVMPR7YQ3ZDBQ4JAVCNFSM6AAAAABHSVGPXWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJZGE2TIOJRGI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I cleaned up the code and pushed a couple of commits to your branch. I also made "use_context" and "include_sources" configurable. Please check if this introduced any bugs, as I can't test it. |
Great, thanks! Unfortunately, I'm currently travelling and won't have access to my computer for the next two weeks. But afterwards I'll test it as soon as possible. |
I finally found some time to test your changes. There are currently two issues:
This should be straight forward enough to fix,I think, as soon as I find a bit of time.
Here, I'm not sure what the reason is. Any idea? |
03f3b69
to
6e8b701
Compare
Can you generate a log for this case? |
Made a couple of changes based on guesses. Please test again and try to use the gptel log buffer to get more details on the errors. |
(models '("private-gpt")) | ||
(endpoint "/v1/chat/completions") | ||
(context t) (sources t)) | ||
"Register an Privategpt API-compatible backend for gptel with NAME. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not about the code but just noticed a typo : "a PrivateGPT" . Probably because of "API"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will fix this before merging.
With these new changes I get an "empty response". I attached the output of the gptel-log-buffer, as it is once again quite lengthy. |
I also went back and reran the command while generating a log. Here the output was quite short:
|
Are you sure the changes were applied? {
"model": "private-gpt",
"messages": [
{
"role": "system",
"content": "You are a large language model living in Emacs and a helpful assistant. Respond concisely."
},
{
"role": "user",
"content": "What are the Navier-Stokes equations?"
}
],
"use_context": true,
"include_sources": null,
"stream": true,
"temperature": 1.0
} In this request, |
I made a dummy privategpt backend and tested it, and |
Sorry, I wasn't clear enough: I went back to the previous commit and ran the command with logging turned on, in case it would help. |
Also, I found (and fixed, I hope) an error in your latest commit. Now it is possible to correctly toggle |
It looks like you reverted a change I made, to use the
|
I'm confused about "previous commit" now. As per the latest commit, when |
It is set to |
Now I also fixed the problem that the |
gptel-privategpt.el
Outdated
(push sources-string content-strs)) | ||
(let ((response (gptel--json-read))) | ||
(unless (or (plist-get info :sources) | ||
(not (gptel-privategpt-sources gptel-backend))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use the passed argument backend
(renamed from _backend
), not gptel-backend
, for reasons explained in the main thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment in the main thread.
gptel-privategpt.el
Outdated
|
||
(cl-defmethod gptel--parse-response ((_backend gptel-privategpt) response _info) | ||
(let ((response-string (map-nested-elt response '(:choices 0 :message :content))) | ||
(sources-string (and (gptel-privategpt-sources gptel-backend) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use the passed argument backend
(renamed from _backend
), not gptel-backend
, for reasons explained in the main thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment in the main thread.
:use_context ,(or (gptel-privategpt-context gptel-backend) :json-false) | ||
:include_sources ,(or (gptel-privategpt-sources gptel-backend) :json-false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use the passed argument backend
(renamed from _backend
), not gptel-backend
, for reasons explained in the main thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment in the main thread.
The problem with using
This is why I changed it back to The full log output is as follows:
|
Those are errors too, actually, I need to fix that. However, you'll notice that the backend is not used (as either
Anyway, I'm trying to figure out why you're getting that error 🤔 |
bb931ad
to
362cfa6
Compare
I fixed the bug that was causing |
I just checked it, and everything works as intended. Thanks for the effort! |
That's great, we can merge it then. Can you add an entry to the README with instructions for using PrivateGPT? You can copy the text from one of the other sections (like Perplexity or OpenRouter) and modify it, with additional notes on using |
Done. I added the usage instructions and also included a link to the privateGPT repository for reference. |
gptel-privategpt.el (gptel-privategpt, gptel--privategpt-parse-sources, gptel-make-privategpt, gptel--parse-response, gptel-curl--parse-stream): Add support for privateGPT based on the openai-API, including support for context and parsing of sources.
README: Add instructions for using PrivateGPT.
17a8071
to
e69193c
Compare
Cheers @Aquan1412! Thanks for the PR. |
Hi, as suggested in our recent discussion #305, here's a PR that adds support for interacting with privateGPT. Its based on the openai-backend, with some additions. The focus was to enable the use of two specific key words, as described in the API reference:
use_context
: directs the LLM to use the context of documents that have been "ingested"include_sources
: directs the LLM to also return information about the sources of the context (so far: file name and page number, if appropriate).I changed the code of
gptel-openai.el
to send the additional keywords to the llm server, and to correctly parse the answer if sources are provided.I tested the code with different queries, and so far it works for my use case. However, there is at least one missing feature: currently, the two new keywords
use_context
andinclude_sources
are hardcoded tot
. It would probably be better to make them configurable when creating the backend. Unfortunately, I'm not sure how to do that correctly.