Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make llm service and options configurable from environnment variables #1258

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions app/services/llm_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ def make_user_prompt query_doc_pair
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def get_llm_response user_prompt, system_prompt
conn = Faraday.new(url: 'https://api.openai.com') do |f|
llm_service_url = ENV['LLM_SERVICE_URL'] || 'https://api.openai.com'
llm_model = ENV['LLM_MODEL'] || 'gpt-4o'
llm_key = ENV['LLM_KEY'] || @openai_key
llm_timeout = ENV['LLM_TIMEOUT'] || 30
conn = Faraday.new(
url: llm_service_url,
request: {
timeout: llm_timeout,
open_timeout: llm_timeout
} ) do |f|
f.request :json
f.response :json
f.adapter Faraday.default_adapter
Expand All @@ -62,7 +71,7 @@ def get_llm_response user_prompt, system_prompt
end

body = {
model: 'gpt-4o',
model: llm_model,
response_format: { type: 'json_object' },
messages: [
{ role: 'system', content: system_prompt },
Expand All @@ -71,7 +80,7 @@ def get_llm_response user_prompt, system_prompt
}

response = conn.post('/v1/chat/completions') do |req|
req.headers['Authorization'] = "Bearer #{@openai_key}"
req.headers['Authorization'] = "Bearer #{llm_key}"
req.headers['Content-Type'] = 'application/json'
req.body = body
end
Expand Down