ruby-openai icon indicating copy to clipboard operation
ruby-openai copied to clipboard

Support other vendors compatible with OpenAI chat completions API

Open pasilastbot opened this issue 2 years ago • 6 comments

There are a lot of other AI vendors that have provided OpenAI compatible chat completions API. It would be nice if we could utilise this library to use them as well. Vendors include e.g.:

Anthropic claude: https://docs.anthropic.com/claude/reference/messages_post Mistral AI: https://docs.mistral.ai/api/ Perplexity AI: https://docs.perplexity.ai/reference/post_chat_completions Only thing we would need to change is to add custom_path parameter to configuration, that would allow setting custom API path not /v1/chat/completions.

I have implemented and tested this change in our own fork, can create a pull request if this fits the scope of this Gem.

https://github.com/LastBotInc/ruby-openai?tab=readme-ov-file#other-chat-completion-apis

pasilastbot avatar Jan 28 '24 09:01 pasilastbot

+1 to this idea!

eichert12 avatar Mar 02 '24 19:03 eichert12

This would be great, especially following today's announcement https://www.anthropic.com/news/claude-3-family

atestu avatar Mar 04 '24 20:03 atestu

Thanks @pasilastbot - this would be really cool - definitely welcome your PR

alexrudall avatar Mar 31 '24 20:03 alexrudall

My 2 cents:

I just found out today that the awesome @obie has created this:

https://github.com/OlympiaAI/open_router

It makes use of the OpenRouter API which is a single unified interface for all LLMs

Perhaps incorporating open_router with ruby-openai would be a good way forward...

etewiah avatar Apr 07 '24 11:04 etewiah

@etewiah I think these are separate needs. OpenRouter is an excellent service, suitable for smaller personal usage. For larger scale production and enterprise data, I (and my clients) prefer that data would not flow via 3rd party web service or use somebody elses AI instances. And to my understanding, ruby-openai would already work with OpenRouter by setting custom domain?

I have also developed a ruby service class on top of ruby-openai, which actually does mapping of system and user messages, function calls, rag documents and images for various AI services. It also calculates the prices and handles rate-limits. It allows me to switch models between OpenAI, Anthropic, Cohere, Google Gemini, Mistral and many others. Right now has some proprietary stuff, but I could think of making it more generic and opensource.

@alexrudall I will make a PR later this week, once have some time for coding.

pasilastbot avatar Apr 08 '24 07:04 pasilastbot

@alexrudall would you be open to a PR that adds support for the Claude models? I have a standalone implementation that handles streaming and non-streaming requests. I would need to port it over.

mgomes avatar May 16 '24 23:05 mgomes