MCPcopy Create free account
hub / github.com/ScienciaLAB/document-qa / init_qa

Function init_qa

streamlit_app.py:137–158  ·  view source on GitHub ↗

Initialise the Q/A engine with the selected LLM and embedding models. Args: model_name: Key from ``API_MODELS`` selecting the LLM. embeddings_name: Key from ``API_EMBEDDINGS`` selecting the embedding model. Returns: DocumentQAEngine: Ready-to-use engine

(model_name, embeddings_name)

Source from the content-addressed store, hash-verified

135
136# @st.cache_resource
137def init_qa(model_name, embeddings_name):
138 """Initialise the Q/A engine with the selected LLM and embedding models.
139
140 Args:
141 model_name: Key from ``API_MODELS`` selecting the LLM.
142 embeddings_name: Key from ``API_EMBEDDINGS`` selecting the
143 embedding model.
144
145 Returns:
146 DocumentQAEngine: Ready-to-use engine instance.
147 """
148 st.session_state["memory"] = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
149 chat = ChatOpenAI(model=model_name, temperature=0.0, base_url=API_MODELS[model_name], api_key=os.environ.get("API_KEY"))
150
151 embeddings = ModalEmbeddings(
152 url=API_EMBEDDINGS[embeddings_name], model_name=embeddings_name, api_key=os.environ.get("EMBEDS_API_KEY")
153 )
154
155 storage = DataStorage(embeddings)
156 return DocumentQAEngine(
157 chat, storage, grobid_url=os.environ["GROBID_URL"], memory=st.session_state["memory"], ping_grobid_server=False
158 )
159
160
161@st.cache_resource

Callers 1

streamlit_app.pyFile · 0.85

Calls 4

ModalEmbeddingsClass · 0.90
DataStorageClass · 0.90
DocumentQAEngineClass · 0.90
getMethod · 0.80

Tested by

no test coverage detected