opencommit icon indicating copy to clipboard operation
opencommit copied to clipboard

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

Open roeniss opened this issue 1 year ago β€’ 11 comments

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

roeniss avatar Sep 12 '24 12:09 roeniss

API_URL should not be undefined

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

di-sukharev avatar Sep 12 '24 12:09 di-sukharev

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.

bjornsnoen avatar Sep 12 '24 13:09 bjornsnoen

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 avatar Sep 12 '24 13:09 di-sukharev

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

di-sukharev avatar Sep 12 '24 13:09 di-sukharev

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

rchouinard avatar Sep 12 '24 16:09 rchouinard

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 avatar Sep 12 '24 18:09 roeniss

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

roeniss avatar Sep 12 '24 18:09 roeniss

@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

di-sukharev avatar Sep 16 '24 17:09 di-sukharev

I have encountered the same problem. ~~I think you need to put this command in the README.~~

$ oco config set OCO_API_URL=http://localhost:11434/api/chat

Sorry, it was already listed. I must have missed it.

frauniki avatar Mar 05 '25 12:03 frauniki

Even though I did not manually configure OCO_API_URL, it defaults to undefined and causes an error.

Here’s my current configuration:

OCO_AI_PROVIDER=ollama
OCO_MODEL=kimjk/llama3.2-korean: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_OMIT_SCOPE=false
OCO_GITPUSH=true
OCO_WHY=fals

DrumRobot avatar Apr 09 '25 04:04 DrumRobot

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

config.baseURL may not be of type undefined, but rather a string with the value "undefined". This case should be handled explicitly, or the setGlobalConfig function should be updated to avoid writing "undefined" as a value in the configuration.

Before:

https://github.com/di-sukharev/opencommit/blob/60a7650e1c1ae37679609d764af6cfae48729c47/src/commands/config.ts#L486-L491

After (Updated to sanitize undefined values):

export const setGlobalConfig = (
  config: ConfigType,
  configPath: string = defaultConfigPath
) => {
  const sanitizedConfig = Object.fromEntries(
    Object.entries(config).map(([key, value]) => [key, value === undefined ? '' : value])
  );

  writeFileSync(configPath, iniStringify(sanitizedConfig), 'utf8');
};

This change ensures that undefined values are replaced with an empty string before being written to the config file, preventing unwanted string "undefined" values from showing up.

DrumRobot avatar Apr 09 '25 05:04 DrumRobot