Spaces:
Sleeping
Sleeping
File size: 1,792 Bytes
ac2020e b087f3c ac2020e b087f3c ac2020e b087f3c ac2020e b087f3c ac2020e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
"""LLM provider implementations for LegisQA"""
import streamlit as st
from langchain_openai import ChatOpenAI
from langchain_anthropic import ChatAnthropic
from langchain_together import ChatTogether
from langchain_google_genai import ChatGoogleGenerativeAI
from legisqa_local.config.settings import get_secret
def get_llm(gen_config: dict):
"""Get LLM instance based on configuration"""
match gen_config["provider"]:
case "OpenAI":
llm = ChatOpenAI(
model=gen_config["model_name"],
temperature=gen_config["temperature"],
api_key=get_secret("OPENAI_API_KEY"),
max_tokens=gen_config["max_output_tokens"],
)
case "Anthropic":
llm = ChatAnthropic(
model_name=gen_config["model_name"],
temperature=gen_config["temperature"],
api_key=get_secret("ANTHROPIC_API_KEY"),
max_tokens_to_sample=gen_config["max_output_tokens"],
)
case "Together":
llm = ChatTogether(
model=gen_config["model_name"],
temperature=gen_config["temperature"],
max_tokens=gen_config["max_output_tokens"],
api_key=get_secret("TOGETHER_API_KEY"),
)
case "Google":
llm = ChatGoogleGenerativeAI(
model=gen_config["model_name"],
temperature=gen_config["temperature"],
api_key=get_secret("GOOGLE_API_KEY"),
max_output_tokens=gen_config["max_output_tokens"],
)
case _:
raise ValueError(f"Unknown provider: {gen_config['provider']}")
return llm
|