Skip to content

Commit

Permalink
Merge branch 'langgenius:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
warren830 authored Jan 1, 2025
2 parents 4701439 + b218df6 commit abf9729
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 50 deletions.
4 changes: 4 additions & 0 deletions api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def is_db_command():
# grpc gevent
grpc_gevent.init_gevent()

import psycogreen.gevent # type: ignore

psycogreen.gevent.patch_psycopg()

from app_factory import create_app

app = create_app()
Expand Down
1 change: 1 addition & 0 deletions api/core/app/apps/workflow/app_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ def single_iteration_generate(
single_iteration_run=WorkflowAppGenerateEntity.SingleIterationRunEntity(
node_id=node_id, inputs=args["inputs"]
),
workflow_run_id=str(uuid.uuid4()),
)
contexts.tenant_id.set(application_generate_entity.app_config.tenant_id)

Expand Down
2 changes: 1 addition & 1 deletion api/core/app/entities/app_invoke_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class WorkflowAppGenerateEntity(AppGenerateEntity):

# app config
app_config: WorkflowUIBasedAppConfig
workflow_run_id: Optional[str] = None
workflow_run_id: str

class SingleIterationRunEntity(BaseModel):
"""
Expand Down
3 changes: 2 additions & 1 deletion api/core/app/task_pipeline/workflow_cycle_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def _handle_workflow_run_start(
inputs = dict(WorkflowEntry.handle_special_values(inputs) or {})

# init workflow run
workflow_run_id = str(self._workflow_system_variables.get(SystemVariableKey.WORKFLOW_RUN_ID, uuid4()))
# TODO: This workflow_run_id should always not be None, maybe we can use a more elegant way to handle this
workflow_run_id = str(self._workflow_system_variables.get(SystemVariableKey.WORKFLOW_RUN_ID) or uuid4())

workflow_run = WorkflowRun()
workflow_run.id = workflow_run_id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from os.path import abspath, dirname, join
from threading import Lock
from typing import Any
from typing import Any, cast

import gevent.threadpool # type: ignore
from transformers import GPT2Tokenizer as TransformerGPT2Tokenizer # type: ignore

_tokenizer: Any = None
_lock = Lock()
_pool = gevent.threadpool.ThreadPool(1)


class GPT2Tokenizer:
Expand All @@ -20,7 +22,9 @@ def _get_num_tokens_by_gpt2(text: str) -> int:

@staticmethod
def get_num_tokens(text: str) -> int:
return GPT2Tokenizer._get_num_tokens_by_gpt2(text)
future = _pool.spawn(GPT2Tokenizer._get_num_tokens_by_gpt2, text)
result = future.get(block=True)
return cast(int, result)

@staticmethod
def get_encoder() -> Any:
Expand Down
5 changes: 4 additions & 1 deletion api/core/workflow/nodes/http_request/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ def _init_body(self):
if len(data) != 1:
raise RequestBodyError("json body type should have exactly one item")
json_string = self.variable_pool.convert_template(data[0].value).text
json_object = json.loads(json_string, strict=False)
try:
json_object = json.loads(json_string, strict=False)
except json.JSONDecodeError as e:
raise RequestBodyError(f"Failed to parse JSON: {json_string}") from e
self.json = json_object
# self.json = self._parse_object_contains_variables(json_object)
case "binary":
Expand Down
4 changes: 4 additions & 0 deletions api/core/workflow/workflow_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ def mapping_user_inputs_to_variable_pool(
):
raise ValueError(f"Variable key {node_variable} not found in user inputs.")

# environment variable already exist in variable pool, not from user inputs
if variable_pool.get(variable_selector):
continue

# fetch variable node id from variable selector
variable_node_id = variable_selector[0]
variable_key_list = variable_selector[1:]
Expand Down
3 changes: 2 additions & 1 deletion api/libs/oauth_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ def notion_block_parent_page_id(self, access_token: str, block_id: str):
response = requests.get(url=f"{self._NOTION_BLOCK_SEARCH}/{block_id}", headers=headers)
response_json = response.json()
if response.status_code != 200:
raise ValueError(f"Error fetching block parent page ID: {response_json.message}")
message = response_json.get("message", "unknown error")
raise ValueError(f"Error fetching block parent page ID: {message}")
parent = response_json["parent"]
parent_type = parent["type"]
if parent_type == "block_id":
Expand Down
56 changes: 12 additions & 44 deletions api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ openai = "~1.52.0"
openpyxl = "~3.1.5"
pandas = { version = "~2.2.2", extras = ["performance", "excel"] }
pandas-stubs = "~2.2.3.241009"
psycogreen = "~1.0.2"
psycopg2-binary = "~2.9.6"
pycryptodome = "3.19.1"
pydantic = "~2.9.2"
Expand Down

0 comments on commit abf9729

Please sign in to comment.