fix: missing parenthesis

This commit is contained in:
LUIS NOVO 2025-10-18 13:22:39 -03:00
parent 8b5daa86bc
commit a51bb9d792

View file

@ -26,11 +26,10 @@ class ThreadState(TypedDict):
def call_model_with_messages(state: ThreadState, config: RunnableConfig) -> dict: def call_model_with_messages(state: ThreadState, config: RunnableConfig) -> dict:
system_prompt = Prompter(prompt_template="chat").render(data=state) # type: ignore[arg-type] system_prompt = Prompter(prompt_template="chat").render(data=state) # type: ignore[arg-type]
payload = [SystemMessage(content=system_prompt)] + state.get("messages", []) payload = [SystemMessage(content=system_prompt)] + state.get("messages", [])
model_id = ( model_id = config.get("configurable", {}).get("model_id") or state.get(
config.get("configurable", {}).get("model_id") "model_override"
or state.get("model_override")
) )
# Handle async model provisioning from sync context # Handle async model provisioning from sync context
def run_in_new_loop(): def run_in_new_loop():
"""Run the async function in a new event loop""" """Run the async function in a new event loop"""
@ -39,20 +38,19 @@ def call_model_with_messages(state: ThreadState, config: RunnableConfig) -> dict
asyncio.set_event_loop(new_loop) asyncio.set_event_loop(new_loop)
return new_loop.run_until_complete( return new_loop.run_until_complete(
provision_langchain_model( provision_langchain_model(
str(payload), str(payload), model_id, "chat", max_tokens=8192
model_id, )
"chat",
max_tokens=8192
) )
finally: finally:
new_loop.close() new_loop.close()
asyncio.set_event_loop(None) asyncio.set_event_loop(None)
try: try:
# Try to get the current event loop # Try to get the current event loop
asyncio.get_running_loop() asyncio.get_running_loop()
# If we're in an event loop, run in a thread with a new loop # If we're in an event loop, run in a thread with a new loop
import concurrent.futures import concurrent.futures
with concurrent.futures.ThreadPoolExecutor() as executor: with concurrent.futures.ThreadPoolExecutor() as executor:
future = executor.submit(run_in_new_loop) future = executor.submit(run_in_new_loop)
model = future.result() model = future.result()
@ -66,7 +64,7 @@ def call_model_with_messages(state: ThreadState, config: RunnableConfig) -> dict
max_tokens=8192, max_tokens=8192,
) )
) )
ai_message = model.invoke(payload) ai_message = model.invoke(payload)
return {"messages": ai_message} return {"messages": ai_message}