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

Update main_controller.rb to support 3 LLMs #9

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
28 changes: 27 additions & 1 deletion controllers/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,36 @@ def format_role(role)
end
end

def llm

def openai_llm
Langchain::LLM::OpenAI.new(
api_key: ENV["OPENAI_API_KEY"],
default_options: { chat_completion_model_name: "gpt-4o-mini" }
)
end

def gemini_llm
Langchain::LLM::GoogleGemini.new(
api_key: ENV["GOOGLE_GEMINI_API_KEY"],
default_options: { chat_completion_model_name: "gemini-1.5-pro" }
)
end

def anthropic_llm
Langchain::LLM::Anthropic.new(
api_key: ENV["ANTHROPIC_API_KEY"],
default_options: { chat_completion_model_name: "claude-2" }
)
end

# Auto-choosing LLM based on ENV variables being available.
def llm
Langchain.logger.level = Logger::INFO

return openai_llm if ENV.fetch 'OPENAI_API_KEY', false
return gemini_llm if ENV.fetch 'GOOGLE_GEMINI_API_KEY', false
return anthropic_llm if ENV.fetch 'ANTHROPIC_API_KEY', false
raise "I need at least one key among OPENAI_API_KEY, GOOGLE_GEMINI_API_KEY, and ANTHROPIC_API_KEY"
end

end