FEATURE: Support srv records for OpenAI compatible LLMs (#865)

This commit is contained in:
Rafael dos Santos Silva 2024-10-24 15:47:12 -03:00 committed by GitHub
parent c1fa84ad29
commit 3022d34613
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 1 deletions

View File

@ -48,7 +48,14 @@ module DiscourseAi
private private
def model_uri def model_uri
URI(llm_model.url) if llm_model.url.to_s.starts_with?("srv://")
service = DiscourseAi::Utils::DnsSrv.lookup(llm_model.url.sub("srv://", ""))
api_endpoint = "https://#{service.target}:#{service.port}/v1/chat/completions"
else
api_endpoint = llm_model.url
end
@uri ||= URI(api_endpoint)
end end
def prepare_payload(prompt, model_params, dialect) def prepare_payload(prompt, model_params, dialect)