n8n icon indicating copy to clipboard operation
n8n copied to clipboard

feat: add openrouter as an LLM node and LLM chat node

Open Korayem opened this issue 10 months ago • 1 comments

Summary

Add support for OpenRouter as LLM Node and LLM Chat Node

Review / Merge checklist

  • [x] PR title and summary are descriptive. Remember, the title automatically goes into the changelog. Use (no-changelog) otherwise. (conventions)
  • [x] Docs updated or follow-up ticket created: https://github.com/n8n-io/n8n-docs/pull/2076
  • [x] ~~Tests included.~~ Couldnt find any tests for Gemini, Antrhopic, Mistral....etc

    A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests.

Korayem avatar Apr 30 '24 12:04 Korayem

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 30 '24 12:04 CLAassistant

Hi @Korayem, thank you for this, and I'm sorry it took so long! It seems like Langchain doesn't export ChatRouterAI anymore. This makes sense since this provider is using the standard OpenAI API interface. That means it should already be possible to use it with n8n by using OpenAI node with baseURL override. Here's an example with OpenAI chat node using google/gemma-2-9b-it via OpenRouter: CleanShot 2024-07-08 at 16 19 25@2x

For this reason, I'm going to close the PR, but I hope we'll see more contributions from you in the future! :-)

OlegIvaniv avatar Jul 08 '24 14:07 OlegIvaniv

@OlegIvaniv The reason I created this PR is because when I add OpenAI credentials to n8n, there is no exposed base_url field to add openrouter's url. If I enter OpenRouter Key, it fails because n8n verifies the key with openai servers which fails, hence I can't add the credential.

image What do I need to do to add the credential then change the `base url` as you've shown? ![image](https://private-user-images.githubusercontent.com/198332/346866587-8cbfe13e-4db6-497a-ae3b-5df8583da920.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA1MTE5MzIsIm5iZiI6MTcyMDUxMTYzMiwicGF0aCI6Ii8xOTgzMzIvMzQ2ODY2NTg3LThjYmZlMTNlLTRkYjYtNDk3YS1hZTNiLTVkZjg1ODNkYTkyMC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzA5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcwOVQwNzUzNTJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1lMTY5YzRmNWQwYjg0ZDFjZmMyNjJmZTUwZjY1Zjk4MWEyZGVjNTBhMDMzYTU4Y2YwMGY2ZTgxYTc4YzU0Nzg0JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.aUHacc9LnATMj4t_J0zB9hYBSpQqVqc1TnuDcXHiCHU)

PS: I have latest n8n 1.48.3

The "Base URL" override is inside the node's options, not the credential. The credential test would still fail as it's using OpenAI endpoint but you can ignore it

OlegIvaniv avatar Jul 09 '24 07:07 OlegIvaniv

Yeah. I just realized, the credential gets saved even if it fails. I am not sure that was the same case when I started the PR. I remember I couldn't do it before.

Anyways, thanks a ton!!

Korayem avatar Jul 09 '24 08:07 Korayem