MCPcopy Create free account
hub / github.com/LangGraph-GUI/LangGraph-GUI-backend / get_llm

Function get_llm

src/llm.py:22–48  ·  view source on GitHub ↗
(llm_model, api_key)

Source from the content-addressed store, hash-verified

20 return history
21
22def get_llm(llm_model, api_key):
23
24 # openai case
25 if "gpt" in llm_model.lower(): # If the llm contains 'gpt', use ChatOpenAI
26 from langchain_community.chat_models import ChatOpenAI
27 os.environ["OPENAI_API_KEY"] = api_key
28 llm = ChatOpenAI(temperature=0, model="gpt-4o-mini").bind(response_format={"type": "json_object"})
29 logger("Using gpt-4o-mini")
30
31 return llm
32 # cannot work now, need langchain fix error
33 if "google" in llm_model.lower():
34 logger("no suport google LLM")
35 return None
36
37 # ollama case
38 if llm_model:
39 from langchain_ollama import ChatOllama
40 ollama_base_url = os.environ.get("OLLAMA_BASE_URL", "http://ollama:11434") # Default value if envvar is not set
41 llm = ChatOllama(
42 model=llm_model,
43 base_url=ollama_base_url,
44 format="json",
45 temperature=0)
46
47 logger(f"Using {llm_model}")
48 return llm
49
50
51

Callers 2

mainFunction · 0.90
process_stringFunction · 0.85

Calls 1

loggerFunction · 0.90

Tested by

no test coverage detected