Skip to content

Commit

Permalink
[fix] lazy importing client so chains can run on server
Browse files Browse the repository at this point in the history
  • Loading branch information
yashbonde committed Oct 13, 2023
1 parent f01b0b6 commit 7a90ee6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions chainfury/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,11 +1122,8 @@ def from_dag(cls, dag: T.Dag, check_server: bool = True):
Args:
dag (T.Dag): The dag object to load from
"""
from chainfury.client import get_client
from chainfury.agent import programatic_actions_registry, ai_actions_registry

stub = get_client()

# convert to dag and checks
nodes = []
edges = []
Expand Down Expand Up @@ -1159,6 +1156,9 @@ def from_dag(cls, dag: T.Dag, check_server: bool = True):
cf_action = programatic_actions_registry.get(node.cf_id) # check if present in the programatic registry
if check_server and not cf_action:
# check available on the API
from chainfury.client import get_client

stub = get_client()
action, err = stub.fury.actions.u(node.cf_id)()
if err:
raise ValueError(f"Action {node.cf_id} not loaded: {action}")
Expand Down
2 changes: 2 additions & 0 deletions server/chainfury_server/api/chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ def run_chain(
engine = engine_registry.get(chatbot.engine)
if engine is None:
raise HTTPException(status_code=400, detail=f"Invalid engine {chatbot.engine}")

#
if as_task:
result = engine.submit(chatbot=chatbot, prompt=prompt, db=db, start=time.time())
return result
Expand Down

0 comments on commit 7a90ee6

Please sign in to comment.