Skip to content

Commit

Permalink
[fix] description for chatbot not set. [chore] update cf_internal
Browse files Browse the repository at this point in the history
  • Loading branch information
yashbonde committed Oct 10, 2023
1 parent 092d28a commit eab734a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cf_internal
19 changes: 0 additions & 19 deletions chainfury/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,25 +297,6 @@ def get_fe_chain_from_chain(chain: Chain) -> Dict[str, Any]:
dragging=False,
)

# out, err = stub.fury.actions(
# "post",
# trailing="/",
# json={
# "name": node["name"],
# "description": "",
# "fn": {
# "model_id": node["fn"]["model"]["id"],
# "model_params": node["fn"]["model_params"],
# "fn": node["fn"]["fn"],
# },
# "outputs": node["outputs"],
# },
# )
# if err:
# raise ValueError(f"Could not create node: {out}")
# logger.info(f"Created new action with ID: {out['id']}")
# _node_data.cf_id = out["id"]

# in this case the entire action is stored with the DAG object
_node_data.cf_id = node.id
_node_data.cf_data = FENode.CFData(
Expand Down
33 changes: 33 additions & 0 deletions chainfury/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
from uuid import uuid4
from urllib.parse import quote
from datetime import datetime, timezone
from typing import Any, Dict, List, Union, Tuple, Optional

from concurrent.futures import ThreadPoolExecutor, as_completed, Future
Expand Down Expand Up @@ -282,3 +283,35 @@ def from_json(fp: str = "") -> Dict[str, Any]:
return json.load(f)
else:
return json.loads(fp)


class SimplerTimes:
"""
A class that provides a simpler interface to datetime and time modules.
"""

tz = timezone.utc

def get_now_datetime() -> datetime: # type: ignore
"""Get the current datetime in UTC timezone"""
return datetime.now(SimplerTimes.tz)

def get_now_float() -> float: # type: ignore
"""Get the current datetime in UTC timezone as a float"""
return SimplerTimes.get_now_datetime().timestamp()

def get_now_i64() -> int: # type: ignore
"""Get the current datetime in UTC timezone as a int"""
return int(SimplerTimes.get_now_datetime().timestamp())

def get_now_str() -> str: # type: ignore
"""Get the current datetime in UTC timezone as a string"""
return SimplerTimes.get_now_datetime().strftime("%Y-%m-%d %H:%M:%S.%f")

def i64_to_datetime(i64: int) -> datetime: # type: ignore
"""Convert an int to datetime in UTC timezone"""
return datetime.fromtimestamp(i64, SimplerTimes.tz)

def get_now_human() -> str: # type: ignore
"""Get the current datetime in UTC timezone as a human readable string"""
return SimplerTimes.get_now_datetime().strftime("%A %d %B, %Y at %I:%M %p")
7 changes: 6 additions & 1 deletion server/chainfury_server/api/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def create_chatbot(
resp.status_code = 400
return {"message": f"Invalid engine should be one of {ChatBotTypes.all()}"}

if len(chatbot_data.description) > 1024:
resp.status_code = 400
return {"message": "Description too long"}

# actually create
dag = chatbot_data.dag.dict() if chatbot_data.dag else {}
chatbot = ChatBot(
Expand All @@ -61,7 +65,8 @@ def create_chatbot(
dag=dag,
engine=chatbot_data.engine,
created_at=datetime.now(),
)
description=chatbot_data.description,
) # type: ignore
db.add(chatbot)
db.commit()
db.refresh(chatbot)
Expand Down

0 comments on commit eab734a

Please sign in to comment.