From 9226a6d1ab3fed233d2925427de4dba9d22866fa Mon Sep 17 00:00:00 2001 From: LJ Date: Wed, 25 Jun 2025 00:13:32 -0700 Subject: [PATCH] fix: execute local future correctly --- docs/docs/ai/llm.mdx | 2 +- docs/docs/ops/functions.md | 1 - docs/sidebars.ts | 2 +- src/builder/flow_builder.rs | 16 ++++++++++------ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/docs/ai/llm.mdx b/docs/docs/ai/llm.mdx index 804b50805..b69a83650 100644 --- a/docs/docs/ai/llm.mdx +++ b/docs/docs/ai/llm.mdx @@ -52,7 +52,7 @@ It has the following fields: Embedding means converting text into a vector space, usually for similarity matching. -We provide a builtin function [`EmbedText`](/docs/ops/functions#embedtext) that converts a given text into a vector space. +We provide a builtin function [`EmbedText`](/docs/ops/functions#embedtext) that converts a given text into a vector space. The spec takes the following fields: * `api_type` (type: `cocoindex.LlmApiType`, required) diff --git a/docs/docs/ops/functions.md b/docs/docs/ops/functions.md index 2e5e76d88..e1417044d 100644 --- a/docs/docs/ops/functions.md +++ b/docs/docs/ops/functions.md @@ -133,4 +133,3 @@ Input data: * `text` (type: `str`, required): The text to embed. Return type: `vector[float32; N]`, where `N` is the dimension of the embedding vector determined by the model. - diff --git a/docs/sidebars.ts b/docs/sidebars.ts index 4bb8dd428..bf645bdd6 100644 --- a/docs/sidebars.ts +++ b/docs/sidebars.ts @@ -61,4 +61,4 @@ const sidebars: SidebarsConfig = { ], }; -export default sidebars; \ No newline at end of file +export default sidebars; diff --git a/src/builder/flow_builder.rs b/src/builder/flow_builder.rs index b985d0d14..041b1c5f6 100644 --- a/src/builder/flow_builder.rs +++ b/src/builder/flow_builder.rs @@ -3,6 +3,7 @@ use crate::{prelude::*, py::Pythonized}; use pyo3::{exceptions::PyException, prelude::*}; use pyo3_async_runtimes::tokio::future_into_py; use std::{collections::btree_map, ops::Deref}; +use tokio::task::LocalSet; use super::analyzer::{ AnalyzerContext, CollectorBuilder, DataScopeBuilder, OpScope, build_flow_instance_context, @@ -622,14 +623,17 @@ impl FlowBuilder { }; let py_ctx = crate::py::PythonExecutionContext::new(py, py_event_loop); - future_into_py(py, async move { - let analyzed_flow = tokio::task::spawn_local( + let analyzed_flow = get_runtime().spawn_blocking(|| { + let local_set = LocalSet::new(); + local_set.block_on( + get_runtime(), super::AnalyzedTransientFlow::from_transient_flow(spec, Some(py_ctx)), ) - .await - .into_py_result()? - .into_py_result()?; - Ok(py::TransientFlow(Arc::new(analyzed_flow))) + }); + future_into_py(py, async move { + Ok(py::TransientFlow(Arc::new( + analyzed_flow.await.into_py_result()?.into_py_result()?, + ))) }) }