di-sukharev / opencommit

Generate conventional git commit messages with AI in 1 second 🤯🔫
https://www.npmjs.com/package/opencommit
MIT License
6.15k stars 328 forks source link

[Bug]: Ollama provider error: Invalid URL (version 3.2.2) #416

Open roeniss opened 2 months ago

roeniss commented 2 months ago

Opencommit Version

3.2.2

Node Version

20.11.1

NPM Version

10.8.3

What OS are you seeing the problem on?

Mac

What happened?

❯❯❯ oco
┌  open-commit
│
◇  1 staged files:
  src/main/kotlin/[REDACTED].kt
│
◇  ✖ Failed to generate the commit message
Error: Ollama provider error: Invalid URL
    at OllamaEngine.generateCommitMessage (/Users/roeniss/.nvm/versions/node/v20.11.1/lib/node_modules/opencommit/out/cli.cjs:40212:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async generateCommitMessageByDiff (/Users/roeniss/.nvm/versions/node/v20.11.1/lib/node_modules/opencommit/out/cli.cjs:45082:27)
    at async generateCommitMessageFromGitDiff (/Users/roeniss/.nvm/versions/node/v20.11.1/lib/node_modules/opencommit/out/cli.cjs:45293:25)
    at async trytm (/Users/roeniss/.nvm/versions/node/v20.11.1/lib/node_modules/opencommit/out/cli.cjs:45261:18)
    at async commit (/Users/roeniss/.nvm/versions/node/v20.11.1/lib/node_modules/opencommit/out/cli.cjs:45458:35)
│
└  ✖ Ollama provider error: Invalid URL
❯❯❯ oco --version
3.2.2
❯❯❯ cat ~/.opencommit
OCO_AI_PROVIDER=ollama
OCO_MODEL=llama3:latest
OCO_API_URL=undefined
OCO_API_KEY=undefined
OCO_TOKENS_MAX_INPUT=40960
OCO_TOKENS_MAX_OUTPUT=4096
OCO_DESCRIPTION=false
OCO_EMOJI=false
OCO_LANGUAGE=en
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=$msg
OCO_PROMPT_MODULE=conventional-commit
OCO_ONE_LINE_COMMIT=false
OCO_TEST_MOCK_TYPE=commit-message
OCO_GITPUSH=true
OCO_WHY=false
❯❯❯ cat ~/.opencommit_migrations
[
  "00_use_single_api_key_and_url",
  "01_remove_obsolete_config_keys_from_global_file",
  "02_set_missing_default_values"
]%

Expected Behavior

.

Current Behavior

.

Possible Solution

No response

Steps to Reproduce

No response

Relevant log output

No response

di-sukharev commented 2 months ago

API_URL should not be undefined

see https://github.com/di-sukharev/opencommit?tab=readme-ov-file#running-locally-with-ollama

bjornsnoen commented 2 months ago

API_URL should not be undefined

see https://github.com/di-sukharev/opencommit?tab=readme-ov-file#running-locally-with-ollama

According to the section you linked to, OCO_API_URL is optional and only needs to be set if ollama isn't running on the localhost. In the past this default value worked, now it's suddenly necessary to set it explicitly, and again, this isn't mentioned in the readme.

di-sukharev commented 2 months ago

ohh yeah.. you are correct, my apologies :) i will then look into it, looks like it's kinda mandatory, but should have been kept optional for OCO_AI_PROVIDER=ollama

di-sukharev commented 2 months ago

hmm.. but it looks like we handle this case https://github.com/di-sukharev/opencommit/blob/master/src/engine/ollama.ts#L16 so it needs a deeper look

anyway @bjornsnoen if you feel like opening the PR with a fix— please do. i will myself get to it ~weekend

rchouinard commented 2 months ago

I think any fix should take into account the OLLAMA_HOST env var as well. To me, the order should be:

  1. configured OCO_API_URL
  2. OLLAMA_HOST + endpoint path
  3. default localhost + endpoint path
roeniss commented 2 months ago

I'm not sure i'm following you guys. Even after remove those API_URL lines I get error as same.

❯❯❯ cat ~/.opencommit
OCO_AI_PROVIDER=ollama
OCO_MODEL=llama3:latest
OCO_TOKENS_MAX_INPUT=40960
OCO_TOKENS_MAX_OUTPUT=4096
OCO_DESCRIPTION=false
OCO_EMOJI=false
OCO_LANGUAGE=en
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=$msg
OCO_PROMPT_MODULE=conventional-commit
OCO_ONE_LINE_COMMIT=false
OCO_TEST_MOCK_TYPE=commit-message
OCO_GITPUSH=true
OCO_WHY=false
❯❯❯ cat ~/.opencommit_migrations
[
  "00_use_single_api_key_and_url",
  "01_remove_obsolete_config_keys_from_global_file",
  "02_set_missing_default_values"
]%
❯❯❯ oco
┌  open-commit
│
◇  1 staged files:
  build.gradle.kts
│
◇  ✖ Failed to generate the commit message
Error: Ollama provider error: Invalid URL
    at OllamaEngine.generateCommitMessage (/Users/roeniss/.nvm/versions/node/v20.11.1/lib/node_modules/opencommit/out/cli.cjs:40212:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async generateCommitMessageByDiff (/Users/roeniss/.nvm/versions/node/v20.11.1/lib/node_modules/opencommit/out/cli.cjs:45082:27)
    at async generateCommitMessageFromGitDiff (/Users/roeniss/.nvm/versions/node/v20.11.1/lib/node_modules/opencommit/out/cli.cjs:45293:25)
    at async trytm (/Users/roeniss/.nvm/versions/node/v20.11.1/lib/node_modules/opencommit/out/cli.cjs:45261:18)
    at async commit (/Users/roeniss/.nvm/versions/node/v20.11.1/lib/node_modules/opencommit/out/cli.cjs:45458:35)
│
└  ✖ Ollama provider error: Invalid URL
roeniss commented 2 months ago

it worked after I added OCO_API_URL=http://localhost:11434/api/chat to ~/.opencommit

di-sukharev commented 2 months ago

@roeniss you can add it like oco config set OCO_API_URL=http://localhost:11434/api/chat, lets consider this as a workaround until we fix this