alexrudall / ruby-openai

OpenAI API + Ruby! 🤖❤️ NEW: Assistant Vector Stores
MIT License
2.61k stars 302 forks source link

Support other vendors compatible with OpenAI chat completions API #428

Open pasilastbot opened 5 months ago

pasilastbot commented 5 months ago

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

eichert12 commented 4 months ago

+1 to this idea!

atestu commented 3 months ago

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

alexrudall commented 3 months ago

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

etewiah commented 2 months ago

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...

pasilastbot commented 2 months ago

@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.

mgomes commented 1 month ago

@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.