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

[FEATURE] provide the option to use a self hosted AI (e.g. ollama) #3037

Closed
speedyconzales opened this issue Jun 8, 2024 · 28 comments
Closed

Comments

@speedyconzales
Copy link

I am happy to see support for AI integration. But I do would prefer an option for self hosted AI

@pbek
Copy link
Owner

pbek commented Jun 9, 2024

Yes, that would be the next logical step. 😉 As long they are OpenAI API compatible...

@pbek
Copy link
Owner

pbek commented Jun 9, 2024

Which self-hosted AI did you have in mind?

pbek added a commit that referenced this issue Jun 9, 2024
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
@speedyconzales
Copy link
Author

@pbek
Copy link
Owner

pbek commented Jun 10, 2024

Ok, thank you. I'm currently struggling to get this into the script engine. I may need to rewrite some parts of the AI service handling...

pbek added a commit that referenced this issue Jun 10, 2024
…penAiBackendsHook

Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
pbek added a commit that referenced this issue Jun 12, 2024
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
pbek added a commit that referenced this issue Jun 14, 2024
…mentation, example script additions, changelog entry and settings information

Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
@pbek
Copy link
Owner

pbek commented Jun 14, 2024

I had to rewrite and rearrange a lot of stuff to make this happen. 😅

24.6.2

  • A new scripting hook openAiBackendsHook was added, that is called when the OpenAI
    service config is reloaded (for #3037)
    • For example, this is also done when the script engine is reloaded
    • You can use it to provide config for custom OpenAI backends, like your own OpenAI API compatible LLMs
    • Please take a look at the
      openAiBackendsHook documentation
      for more information

pbek added a commit that referenced this issue Jun 14, 2024
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
@pbek
Copy link
Owner

pbek commented Jun 14, 2024

There now is a new release, could you please test it and report if it works for you?

@pbek
Copy link
Owner

pbek commented Jun 14, 2024

I've already found some small issues (like you need to set an apiKey, but there is none in ollama and you still need to reload the script engine manually after adding the script so the OpenAI UI reloads). But the main issue with ollama seems to be that the API result doesn't seem to be compatible with the API result from OpenAI. I'm currently looking into what's different. I didn't have this issue with Groq...

@pbek
Copy link
Owner

pbek commented Jun 14, 2024

Hm, I only got an empty result back from ollama over the API. 🤔 What is your experience?

@pbek
Copy link
Owner

pbek commented Jun 14, 2024

I added a script ollama-integration to the script repository for you to test.

pbek added a commit that referenced this issue Jun 14, 2024
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
@pbek
Copy link
Owner

pbek commented Jun 14, 2024

The requests are the same with the OpenAI API and Ollama, but what Ollama returns with https://github.com/ollama/ollama?tab=readme-ov-file#chat-with-a-model is not at all what is returned at https://platform.openai.com/docs/api-reference/chat/create!

@eljamm
Copy link

eljamm commented Jun 14, 2024

Hey, I'd like to thank you for the amazing program and the continuous improvements.

I was curious to try this new feature with llama-cpp since I don't use ollama and it seems to be working:

What do you call a pineapple that lives under the sea? <ctrl+space>
What do you call a pineapple that lives under the sea? An under-pine in an a-peeling disguise! 

With an API base URL: http://localhost:3030/v1/chat/completions

Is there anything specific you'd like me to test?

@eljamm
Copy link

eljamm commented Jun 14, 2024

It seems that in Ollama, you also need to append the /v1/chat/completions endpoint to the hostname, according to the OpenAI compatibility · Ollama Blog.

@pbek
Copy link
Owner

pbek commented Jun 15, 2024

Nice! Thank you very much for the hint. I'll try that then!

@pbek
Copy link
Owner

pbek commented Jun 15, 2024

Hey, I'd like to thank you for the amazing program and the continuous improvements.

Thank you! 😉 This feature took longer than anticipated (and will take some more tweaking)!

@pbek
Copy link
Owner

pbek commented Jun 15, 2024

It seems that in Ollama, you also need to append the /v1/chat/completions endpoint to the hostname

Works perfectly, thank you very much! http://127.0.0.1:11434/v1/chat/completions works perfectly!

@pbek
Copy link
Owner

pbek commented Jun 15, 2024

@eljamm, if you want to contribute a script for llama-cpp to https://github.com/qownnotes/scripts it would be great. 😉
Would be almost the same as https://github.com/qownnotes/scripts/tree/master/ollama-integration anyway 😊

@eljamm
Copy link

eljamm commented Jun 15, 2024

@pbek Glad I could help and I don't mind writing the script for llama-cpp, but in my opinion it would it be better if the script was written for any local AI server in general since they more than likely support the OpenAI endpoint and it would be redundant to re-write the script for each one every time.

What do you think?

@eljamm
Copy link

eljamm commented Jun 15, 2024

Wrote a PR in qownnotes/scripts#237

@pbek
Copy link
Owner

pbek commented Jun 15, 2024

Please see qownnotes/scripts#237 (comment). One script only supporting one endpoint will not do it if you have multiple backends...

@pbek
Copy link
Owner

pbek commented Jun 15, 2024

Plus, you need to find out the correct endpoints yourself...

@eljamm
Copy link

eljamm commented Jun 15, 2024

Well, as far as I know, all OpenAI-compatible backends support the /v1/chat/completions endpoint, so the only thing that will change will be the server address.

In this regard, I thought a general script would be better as it's like a template which users can use to make their own scripts.

This means that we only have to maintain one script and the users won't think only the ollama or llama-cpp backends are supported.

@eljamm
Copy link

eljamm commented Jun 15, 2024

Is something like qownnotes/scripts#238 what you had in mind?

@speedyconzales
Copy link
Author

speedyconzales commented Jun 15, 2024

it is already working with ollama. I could test it now. Thank you for your effort including this.
From the user perspective I have the following expectations:

  1. since you only need the endpoint to the ollama instance. I would expect I have to set my specific local URL on the same section (settings page -> AI) where the user sets the API keys for the other AI backends. Not a new script I have to include. That is also the case for other backends like llama-cpp. I would just expect a new input field in the AI section. If I set it then it will be available to choose from the "enable AI support" menu.
  2. I don't want to remember the models I have available on my ollama instance and then have to set them as a variable in qownnotes. I would expect that after setting my endpoint it automatically gets/reads all available models. So that I can choose from them, as I would with the Groq or the OpenAI backend.

But like I said, it is working for me and again thank you for adding this. Those expectations are just improvements for the usability that I wanted to share. It did confuse me for a second why I had to add another script to add my own AI endpoint, although there is a dedicated AI settings page.

@pbek
Copy link
Owner

pbek commented Jun 16, 2024

since you only need the endpoint to the ollama instance. I would expect I have to set my specific local URL on the same section (settings page -> AI) where the user sets the API keys for the other AI backends. Not a new script I have to include. That is also the case for other backends like llama-cpp. I would just expect a new input field in the AI section. If I set it then it will be available to choose from the "enable AI support" menu.

I didn't want to go through the hassle of implementing a UI for adding multiple backends. Doing that in scripts turned out to be a hassle too, but at least it's more flexible now. There can be scripts preconfigured for certain backends, so you don't need to research the endpoint URL.

I don't want to remember the models I have available on my ollama instance and then have to set them as a variable in qownnotes. I would expect that after setting my endpoint it automatically gets/reads all available models. So that I can choose from them, as I would with the Groq or the OpenAI backend.

In the 3rd party OpenAI UIs I worked with, you were supposed to configure them too, because maybe you don't want to pay for an expensive one.

Is there even an OpenAI API to get the models?

But since the custom ones have script now those network requests to fetch the models (even to non-OpenAI APIs) could be done in those scripts! 🥳🎉

pbek added a commit that referenced this issue Jun 16, 2024
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
pbek added a commit that referenced this issue Jun 16, 2024
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
pbek added a commit that referenced this issue Jun 16, 2024
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
pbek added a commit that referenced this issue Jun 16, 2024
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
@pbek
Copy link
Owner

pbek commented Jun 16, 2024

24.6.3

  • Improvements to the new scripting hook openAiBackendsHook were made
    (for #3037)
    • The OpenAI UI elements will now be reloaded properly, when the script-engine
      is reloaded after a script was installed
    • The apiKey attribute in the scripting hook is now optional, because local
      APIs don't need it
    • There now is a script ollama-integration in the script repository that
      allows integration with Ollama
    • There now is a script llama-cpp-integration in the script repository that
      allows integration with llama.cpp (for #238, thank you, @eljamm)
    • In the AI settings there now also is the script-repository mentioned

There now is a new release, could you please test it and report if it works for you?

@pbek pbek closed this as completed Jun 16, 2024
@eljamm
Copy link

eljamm commented Jun 17, 2024

Tested again and everything is working as expected.

@pbek
Copy link
Owner

pbek commented Jun 17, 2024

Thanks for testing!

@pbek
Copy link
Owner

pbek commented Jun 18, 2024

@speedyconzales, you might like this: qownnotes/scripts@93735c6 (ollama-integration: fetch installed models automatically)

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

No branches or pull requests

3 participants