Skip to content

Commit b21ba0b

Browse files
authored
Merge pull request #17 from emilrueh/dev
Allow OpenAI compatible model providers
2 parents 02063c9 + b5d1c72 commit b21ba0b

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

README.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,23 @@ A developer-friendly Lua interface for working with various generative AI provid
1414
- Stream output for real-time responses
1515
- Structured JSON response abstraction layer
1616
- Token usage tracking with cost calculation
17+
- Open-source models via OpenAI compatibility
1718

1819
### Providers
1920

20-
- [OpenAI](https://platform.openai.com/docs/overview)
21+
- OpenAI: https://platform.openai.com/docs/overview
2122

22-
- [Anthropic](https://docs.anthropic.com/en/home)
23+
- Anthropic: https://docs.anthropic.com/en/home
24+
25+
- Anything OpenAI compatible e.g. **Perplexity, Together AI, etc.** by prefixing endpoint with openai and double colon: `"openai::https://api.perplexity.ai/chat/completions"`
2326

2427
### Roadmap
2528

26-
1. Advanced error handling
27-
2. Google Gemini integration
28-
3. Audio models
29-
4. Image models
30-
5. Open-Source model integration
31-
6. Video models
29+
- [ ] Audio models
30+
31+
- [ ] Image models
32+
33+
- [ ] Video models
3234

3335
## Installation
3436

src/genai/genai.lua

+11-1
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,23 @@ end
2727
---@return table? provider_module Collection of functions determining input and output structure
2828
function GenAI:_determine_provider(providers)
2929
local provider = nil
30+
local endpoint = self._endpoint
3031
for provider_name, provider_module in pairs(providers) do
31-
if self._endpoint:find(provider_name) then provider = provider_module end
32+
if endpoint:find(provider_name) then provider = provider_module end
3233
end
3334
assert(provider, "GenAI provider could not be determined from provided endpoint")
35+
self._endpoint = self:check_if_openai_compatible(endpoint)
3436
return provider
3537
end
3638

39+
---Check if the endpoint starts with 'openai::' for API compatibility
40+
---@param endpoint string
41+
---@return string endpoint
42+
function GenAI:check_if_openai_compatible(endpoint)
43+
local prefix, url = endpoint:match("^(.-)::(.+)$")
44+
return (prefix == "openai") and url or endpoint
45+
end
46+
3747
---Prepare streaming requirements if set to stream
3848
---@param processor function? Display of streamed text chunks
3949
---@return table? accumulator Schema storing full streamed response

0 commit comments

Comments
 (0)