pfrankov / obsidian-local-gpt

Local Ollama and OpenAI-like GPT's assistance for maximum privacy and offline access
MIT License
325 stars 22 forks source link

[BUG] Multiple API calls are performed instead of one #26

Closed martineliascz closed 1 month ago

martineliascz commented 2 months ago

Hi Pavel,

I appreciate the Local GPT plugin for its immense productivity boost! 🔥

However, I've seen that each action makes two API calls instead of just one, which unnecessarily increases credit usage. It's critical to address this bug with a single API call to reduce these costs.

Proposed adjustment: Make only one API request per action to preserve credits.

Observing the issue involves: Performing any action needing an API request - basically any prompt action.

Observations show two requests are made instead of only one. This issue happens only when using Local GPT plugin for Obsidian.

Fixing this will make the plugin more economically feasible, ensuring I'm eager to use it daily.

Thank you for considering this change and fix.

Br, Martin

image

pfrankov commented 2 months ago

Thank you for the feedback! Unfortunately preflight request is unavoidable in browser (which Obsidian actually is). It should be excluded by the AI provider that you use. Try to reach the support and ask them to exclude OPTIONS (Preflight) requests from the tariff.

martineliascz commented 2 months ago

Hi @pfrankov,

Thank you so much for taking the time to respond to my previous message; your assistance is greatly appreciated. I wanted to update you on some tests I carried out recently regarding various plugins in Obsidian, particularly focusing on the Local GPT plugin.

After extensively retesting 8 other Obsidian plugins, I have observed that the issue seems to be isolated to the Local GPT plugin. I am currently using a custom API proxy that has consistently demonstrated compatibility across numerous other AI tools, plugins, and services without any hitch. Hence, this leads me to believe that the underlying problem might be unique to the Local GPT plugin.

The specific issue I am encountering with Local GPT is that it generates two requests instead of the expected one. I am curious to know if there is a possibility to address this discrepancy directly within the plugin’s configuration or code to ensure it performs optimally.

I'm puzzled as to why this issue only manifests with the Local GPT plugin, especially considering that all other AI-related plugins in Obsidian seem to function perfectly without any complications. Could this be an indication of a more intricate problem that doesn't affect the other plugins?

Your insights or any potential solutions you might have would be invaluable. Thank you once again for your help and attention to this matter, and I look forward to any advice you can provide.

Br, Martin

screenshot

martineliascz commented 2 months ago

Hi @pfrankov, have you had the opportunity to look into the issue? Do you need any additional input from me to move forward with the fix? The Local GPT plugin is the top Obsidian plugin, but it's not advisable to use it because it consumes double the credits, at least for me.. I haven't encountered this issue with other less popular plugins.. Thanks!

pfrankov commented 2 months ago

@martineliascz Sadly I can not reproduce any difference between Text Generator and Local GPT — I have only one request each time. Please provide the data.json for both plugins located in {{PATH_TO_YOUR_OBSIDIAN_VAULT}}/.obsidian/plugins

martineliascz commented 1 month ago

Hi @pfrankov - here are the files you requested:

obsidian-companion - sends only one request as all other plugins

{
  "provider": "ollama",
  "model": "OpenAI: GPT-4o - New (Aug-06)",
  "enable_by_default": true,
  "keybind": "Tab",
  "delay_ms": 2000,
  "stream": false,
  "accept": {
    "splitter_regex": " ",
    "display_splitter_regex": "[.?!:;]",
    "completion_completeness_regex": ".*(?!p{L})[^d]$",
    "min_accept_length": 4,
    "min_display_length": 50,
    "retrigger_threshold": 48
  },
  "provider_settings": {
    "ollama": {
      "settings": "{\"endpoint\":\"http://10.66.66.1:9669\"}",
      "models": {}
    }
  },
  "presets": [],
  "fallback": null
}

obsidian-local-gpt - sends two requests for no reason, tested by my colleagues as well

{
  "providers": {
    "ollama": {
      "ollamaUrl": "http://10.66.66.1:9669",
      "defaultModel": "OpenAI: GPT-4o - New (Aug-06)",
      "type": "ollama",
      "embeddingModel": ""
    },
    "ollama_fallback": {
      "ollamaUrl": "http://localhost:11434",
      "defaultModel": "qwen2",
      "type": "ollama",
      "embeddingModel": ""
    },
    "openaiCompatible": {
      "url": "http://10.66.66.1:9669",
      "apiKey": "",
      "type": "openaiCompatible",
      "defaultModel": "openai/gpt-4o-2024-08-06",
      "embeddingModel": ""
    },
    "openaiCompatible_fallback": {
      "url": "http://localhost:8080",
      "apiKey": "",
      "type": "openaiCompatible",
      "embeddingModel": ""
    }
  },
  "defaults": {
    "provider": "ollama",
    "fallbackProvider": "",
    "creativity": "low"
  },
  "actions": [
    {
      "name": "🧠 General help",
      "prompt": "",
      "system": "You are an assistant helping a user write more content in a document based on a prompt. Output in markdown format. Do not use links. Do not include literal content from the original document."
    },
    {
      "name": "✍️ Continue writing",
      "prompt": "Act as a professional editor with many years of experience as a writer. Carefully finalize the following text, add details, use facts and make sure that the meaning and original style are preserved. Purposely write in detail, with examples, so that your reader is comfortable, even if they don't understand the specifics. Don't use clericalisms, evaluations without proof with facts, passive voice. Use Markdown markup language for formatting. Answer only content and nothing else, no introductory words, only substance.",
      "system": "You are an AI assistant that follows instruction extremely well. Help as much as you can."
    },
    {
      "name": "🍭 Summarize",
      "prompt": "Make a concise summary of the key points of the following text.",
      "system": "You are an AI assistant that follows instruction extremely well. Help as much as you can."
    },
    {
      "name": "📖 Fix spelling and grammar",
      "prompt": "Proofread the below for spelling and grammar.",
      "system": "You are an AI assistant that follows instruction extremely well. Help as much as you can.",
      "replace": true
    },
    {
      "name": "✅ Find action items",
      "prompt": "Act as an assistant helping find action items inside a document. An action item is an extracted task or to-do found inside of an unstructured document. Use Markdown checkbox format: each line starts with \"- [ ] \"",
      "system": "You are an AI assistant that follows instruction extremely well. Help as much as you can."
    }
  ],
  "_version": 5
}

Any ideas how to fix this bug? This issue prevents us from using your plugin..

Thanks much!

martineliascz commented 1 month ago

Hi @pfrankov, Thanks for the Local GPT v1.12.0 - I can confirm that this version fixes the issue with multiple API calls. Starting from Local GPT v1.12.0 - only ONE API call is performed. Thank you!