pycoze 0.1.73__py3-none-any.whl → 0.1.75__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pycoze/{gpu → ai}/__init__.py +1 -1
- pycoze/{gpu → ai}/gpu_reserve.py +31 -20
- pycoze/bot/agent/agent_types/openai_func_call_agent.py +11 -6
- pycoze/ui/base.py +1 -6
- {pycoze-0.1.73.dist-info → pycoze-0.1.75.dist-info}/METADATA +1 -1
- {pycoze-0.1.73.dist-info → pycoze-0.1.75.dist-info}/RECORD +9 -9
- {pycoze-0.1.73.dist-info → pycoze-0.1.75.dist-info}/LICENSE +0 -0
- {pycoze-0.1.73.dist-info → pycoze-0.1.75.dist-info}/WHEEL +0 -0
- {pycoze-0.1.73.dist-info → pycoze-0.1.75.dist-info}/top_level.txt +0 -0
    
        pycoze/{gpu → ai}/__init__.py
    RENAMED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            from .gpu_reserve import reserve_gpu_retry, release_gpu,  | 
| 1 | 
            +
            from .gpu_reserve import reserve_gpu_retry, release_gpu, reserve_gpu
         | 
    
        pycoze/{gpu → ai}/gpu_reserve.py
    RENAMED
    
    | @@ -29,7 +29,7 @@ def initialize_db(): | |
| 29 29 | 
             
                    f"""
         | 
| 30 30 | 
             
                    CREATE TABLE IF NOT EXISTS {TABLE_NAME} (
         | 
| 31 31 | 
             
                        id INTEGER PRIMARY KEY,
         | 
| 32 | 
            -
                         | 
| 32 | 
            +
                        uid TEXT NOT NULL,
         | 
| 33 33 | 
             
                        reserved_gb REAL NOT NULL
         | 
| 34 34 | 
             
                    )
         | 
| 35 35 | 
             
                """
         | 
| @@ -48,7 +48,12 @@ def get_gpu_resources(): | |
| 48 48 | 
             
                        text=True,
         | 
| 49 49 | 
             
                    )
         | 
| 50 50 | 
             
                    free_memory = result.stdout.strip().split("\n")
         | 
| 51 | 
            -
                    total_free_memory =  | 
| 51 | 
            +
                    total_free_memory = 0
         | 
| 52 | 
            +
                    for mem in free_memory:
         | 
| 53 | 
            +
                        try:
         | 
| 54 | 
            +
                            total_free_memory += float(mem)
         | 
| 55 | 
            +
                        except:
         | 
| 56 | 
            +
                            pass
         | 
| 52 57 |  | 
| 53 58 | 
             
                    # 获取正在使用GPU的进程信息
         | 
| 54 59 | 
             
                    process_result = subprocess.run(
         | 
| @@ -67,8 +72,12 @@ def get_gpu_resources(): | |
| 67 72 | 
             
                    for process in process_info:
         | 
| 68 73 | 
             
                        pid, process_name, used_memory = process.split(", ")
         | 
| 69 74 | 
             
                        if "python" in process_name.lower():
         | 
| 70 | 
            -
                             | 
| 71 | 
            -
             | 
| 75 | 
            +
                            try:
         | 
| 76 | 
            +
                                python_memory_usage += float(used_memory)
         | 
| 77 | 
            +
                            except:
         | 
| 78 | 
            +
                                pass
         | 
| 79 | 
            +
                    print("total_free_gpu_memory: ", total_free_memory)
         | 
| 80 | 
            +
                    print("python_gpu_memory_usage: ", python_memory_usage)
         | 
| 72 81 | 
             
                    # 计算排除python进程后的总空闲内存
         | 
| 73 82 | 
             
                    total_free_memory -= python_memory_usage
         | 
| 74 83 | 
             
                    return round(total_free_memory / 1024, 2)
         | 
| @@ -78,8 +87,9 @@ def get_gpu_resources(): | |
| 78 87 |  | 
| 79 88 |  | 
| 80 89 | 
             
            # 预留GPU资源
         | 
| 81 | 
            -
            def reserve_gpu(gb):
         | 
| 82 | 
            -
                 | 
| 90 | 
            +
            def reserve_gpu(gb, uid=None):
         | 
| 91 | 
            +
                if uid is None:
         | 
| 92 | 
            +
                    uid = f"pid:{os.getpid()}"
         | 
| 83 93 | 
             
                with sqlite3.connect(DATABASE_PATH) as conn:
         | 
| 84 94 | 
             
                    cursor = conn.cursor()
         | 
| 85 95 | 
             
                    cursor.execute(f"SELECT SUM(reserved_gb) FROM {TABLE_NAME}")
         | 
| @@ -89,8 +99,8 @@ def reserve_gpu(gb): | |
| 89 99 | 
             
                    available_gb = get_gpu_resources() - total_reserved
         | 
| 90 100 | 
             
                    if available_gb >= gb:
         | 
| 91 101 | 
             
                        cursor.execute(
         | 
| 92 | 
            -
                            f"INSERT INTO {TABLE_NAME} ( | 
| 93 | 
            -
                            ( | 
| 102 | 
            +
                            f"INSERT INTO {TABLE_NAME} (uid, reserved_gb) VALUES (?, ?)",
         | 
| 103 | 
            +
                            (uid, gb),
         | 
| 94 104 | 
             
                        )
         | 
| 95 105 | 
             
                        conn.commit()
         | 
| 96 106 | 
             
                        print(f"预留成功,剩余GPU大小: {available_gb - gb} GB")
         | 
| @@ -100,7 +110,7 @@ def reserve_gpu(gb): | |
| 100 110 | 
             
                        return False
         | 
| 101 111 |  | 
| 102 112 |  | 
| 103 | 
            -
            def reserve_gpu_retry(gb, retry=None):
         | 
| 113 | 
            +
            def reserve_gpu_retry(gb, retry=None, uid=None):
         | 
| 104 114 | 
             
                if retry is None:
         | 
| 105 115 | 
             
                    # 接近无限重试,python中允许无限大的整数,尽管sys.maxsize不是真正的无限大,但足够大
         | 
| 106 116 | 
             
                    retry = sys.maxsize
         | 
| @@ -108,17 +118,18 @@ def reserve_gpu_retry(gb, retry=None): | |
| 108 118 | 
             
                    time.sleep(1)
         | 
| 109 119 | 
             
                    if i % 10 == 0 or i < 10:
         | 
| 110 120 | 
             
                        print(f"重试第{i}次")
         | 
| 111 | 
            -
                    if reserve_gpu(gb):
         | 
| 121 | 
            +
                    if reserve_gpu(gb, uid):
         | 
| 112 122 | 
             
                        return True
         | 
| 113 123 | 
             
                return False
         | 
| 114 124 |  | 
| 115 125 |  | 
| 116 126 | 
             
            # 释放GPU资源
         | 
| 117 | 
            -
            def release_gpu():
         | 
| 118 | 
            -
                 | 
| 127 | 
            +
            def release_gpu(uid=None):
         | 
| 128 | 
            +
                if uid is None:
         | 
| 129 | 
            +
                    uid = f"pid:{os.getpid()}"
         | 
| 119 130 | 
             
                with sqlite3.connect(DATABASE_PATH) as conn:
         | 
| 120 131 | 
             
                    cursor = conn.cursor()
         | 
| 121 | 
            -
                    cursor.execute(f"DELETE FROM {TABLE_NAME} WHERE  | 
| 132 | 
            +
                    cursor.execute(f"DELETE FROM {TABLE_NAME} WHERE uid = ?", (uid,))
         | 
| 122 133 | 
             
                    conn.commit()
         | 
| 123 134 | 
             
                    # 计算释放后的剩余GPU大小
         | 
| 124 135 | 
             
                    cursor.execute(f"SELECT SUM(reserved_gb) FROM {TABLE_NAME}")
         | 
| @@ -139,19 +150,19 @@ def initialize_and_check(): | |
| 139 150 | 
             
                initialize_db()
         | 
| 140 151 | 
             
                with sqlite3.connect(DATABASE_PATH) as conn:
         | 
| 141 152 | 
             
                    cursor = conn.cursor()
         | 
| 142 | 
            -
                    cursor.execute(f"SELECT  | 
| 153 | 
            +
                    cursor.execute(f"SELECT uid, reserved_gb FROM {TABLE_NAME}")
         | 
| 143 154 | 
             
                    rows = cursor.fetchall()
         | 
| 144 155 | 
             
                    for row in rows:
         | 
| 145 | 
            -
                         | 
| 156 | 
            +
                        uid, reserved_gb = row
         | 
| 146 157 | 
             
                        try:
         | 
| 147 158 | 
             
                            # 检查进程是否存在
         | 
| 148 | 
            -
                             | 
| 159 | 
            +
                            if uid.startswith("pid:"):
         | 
| 160 | 
            +
                                pid = int(uid.split(":")[1])
         | 
| 161 | 
            +
                                psutil.Process(pid)
         | 
| 149 162 | 
             
                        except psutil.NoSuchProcess:
         | 
| 150 163 | 
             
                            # 进程不存在,删除对应的记录
         | 
| 151 | 
            -
                            cursor.execute(
         | 
| 152 | 
            -
             | 
| 153 | 
            -
                            )
         | 
| 154 | 
            -
                            print(f"进程 {process_id} 不存在,已删除对应的预留记录")
         | 
| 164 | 
            +
                            cursor.execute(f"DELETE FROM {TABLE_NAME} WHERE uid = ?", (uid,))
         | 
| 165 | 
            +
                            print(f"进程 {uid} 不存在,已删除对应的预留记录")
         | 
| 155 166 | 
             
                    conn.commit()
         | 
| 156 167 |  | 
| 157 168 |  | 
| @@ -150,16 +150,21 @@ def create_openai_func_call_agent_executor( | |
| 150 150 | 
             
                    # We call the tool_executor and get back a response
         | 
| 151 151 | 
             
                    responses = await tool_executor.abatch(actions, **kwargs)
         | 
| 152 152 | 
             
                    # We use the response to create a ToolMessage
         | 
| 153 | 
            -
                    tool_messages = [
         | 
| 154 | 
            -
             | 
| 153 | 
            +
                    tool_messages = []
         | 
| 154 | 
            +
                    for tool_call, response in zip(
         | 
| 155 | 
            +
                        last_message.additional_kwargs["tool_calls"], responses
         | 
| 156 | 
            +
                    ):
         | 
| 157 | 
            +
                        if not isinstance(response, (str, int, float, bool, list, tuple)):
         | 
| 158 | 
            +
                            response = repr(
         | 
| 159 | 
            +
                                response
         | 
| 160 | 
            +
                            )  # 不支持其他类型,包括dict也不支持,因此需要转换为字符串
         | 
| 161 | 
            +
             | 
| 162 | 
            +
                        message = ToolMessage(
         | 
| 155 163 | 
             
                            tool_call_id=tool_call["id"],
         | 
| 156 164 | 
             
                            content=response,
         | 
| 157 165 | 
             
                            additional_kwargs={"name": tool_call["function"]["name"]},
         | 
| 158 166 | 
             
                        )
         | 
| 159 | 
            -
                         | 
| 160 | 
            -
                            last_message.additional_kwargs["tool_calls"], responses
         | 
| 161 | 
            -
                        )
         | 
| 162 | 
            -
                    ]
         | 
| 167 | 
            +
                        tool_messages.append(message)
         | 
| 163 168 | 
             
                    return tool_messages
         | 
| 164 169 |  | 
| 165 170 | 
             
                workflow = MessageGraph()
         | 
    
        pycoze/ui/base.py
    CHANGED
    
    | @@ -40,12 +40,7 @@ def get_ui(): | |
| 40 40 | 
             
                                return json.load(f)
         | 
| 41 41 | 
             
                        else:
         | 
| 42 42 | 
             
                            assert by == "workflow"
         | 
| 43 | 
            -
                             | 
| 44 | 
            -
                            node_id = params["uiData"]["nodeId"]
         | 
| 45 | 
            -
                            with open(workflow_file, "r", encoding="utf-8") as f:
         | 
| 46 | 
            -
                                cells = json.load(f)["graph"]["cells"]
         | 
| 47 | 
            -
                                node = [cell for cell in cells if cell["id"] == node_id][0]
         | 
| 48 | 
            -
                                return json.loads(node["data"]["ui"])
         | 
| 43 | 
            +
                            return params["uiData"]["uiRecord"][match_ui_file]
         | 
| 49 44 | 
             
                    except Exception as e:
         | 
| 50 45 | 
             
                        if i == 9:
         | 
| 51 46 | 
             
                            raise e
         | 
| @@ -2,6 +2,8 @@ pycoze/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 | |
| 2 2 | 
             
            pycoze/module.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
         | 
| 3 3 | 
             
            pycoze/access/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
         | 
| 4 4 | 
             
            pycoze/access/tool_for_bot.py,sha256=Nv6XlxcqaLaMVQNDkpcthlqaSxyfHoOfWiTScQXO22Y,2656
         | 
| 5 | 
            +
            pycoze/ai/__init__.py,sha256=wUiH-Oy_YbaoiqJN2f9ZvFuRCv9oEDP-oNs5Q8y9IzA,69
         | 
| 6 | 
            +
            pycoze/ai/gpu_reserve.py,sha256=WcD3-K9TsapSXCNVUZFm0k-GHZxznWdFBcljA41dMp8,5764
         | 
| 5 7 | 
             
            pycoze/bot/__init__.py,sha256=6HHMxDQVOyZM9dtSjQm9tjGnhj4h7CixD0JOvEwTi48,41
         | 
| 6 8 | 
             
            pycoze/bot/bot.py,sha256=iJ60C5YOiiAwADQAdWlD15uAgPUuSap5O7gaiJaXQ-U,2769
         | 
| 7 9 | 
             
            pycoze/bot/agent/__init__.py,sha256=YR9vpkEQn1e4937r_xFPJXUCPBEJ0SFzEQDBe2x3-YA,157
         | 
| @@ -9,21 +11,19 @@ pycoze/bot/agent/agent.py,sha256=7xnz4a8LDyAVU0O3tS6n7_jSnr_lukQxfNR2znCWoV4,461 | |
| 9 11 | 
             
            pycoze/bot/agent/assistant.py,sha256=QLeWaPi415P9jruYOm8qcIbC94cXXAhJYmLTkyC9NTQ,1267
         | 
| 10 12 | 
             
            pycoze/bot/agent/chat.py,sha256=kc0qgcrBSXdiMy49JwThZTV-0PAvzAhiUvbI5ILiSnU,571
         | 
| 11 13 | 
             
            pycoze/bot/agent/agent_types/__init__.py,sha256=W2jTNMLqUMqgCMG0Tw0d8n7WpsbsnIonqaPR-YLegLU,210
         | 
| 12 | 
            -
            pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256= | 
| 14 | 
            +
            pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=_nhlgmV_158fUEOtvB_R3my7Sz5FnCAhLZ1iuY1okOU,8270
         | 
| 13 15 | 
             
            pycoze/bot/agent/agent_types/react_agent.py,sha256=AnjHwHXVwLAm77ndglJGi4rQhqDGWaLuUfl46uZVSzM,6749
         | 
| 14 16 | 
             
            pycoze/bot/agent/agent_types/react_prompt.py,sha256=jyovokGaPzNIe5bvTRvn0gmsWLx5kpDIPmRwmEMCl-M,2142
         | 
| 15 | 
            -
            pycoze/gpu/__init__.py,sha256=cuxwDdz2Oo-VcwZ50FtFtEIJXdqoz2el-n0QpSt_NMc,75
         | 
| 16 | 
            -
            pycoze/gpu/gpu_reserve.py,sha256=JEyYh38v_RHolsqcIBoCjI8P-K-Ew3FsEyGhoISYmCQ,5415
         | 
| 17 17 | 
             
            pycoze/ui/__init__.py,sha256=7xAfL2lfG7-jllPJEZUJO89xUE9sNzvo1y0WmBswjBI,458
         | 
| 18 | 
            -
            pycoze/ui/base.py,sha256= | 
| 18 | 
            +
            pycoze/ui/base.py,sha256=SCXVDK7PpMaBv6ovvabHcfRq_d2AWM0BRyxpNhuJN5A,1285
         | 
| 19 19 | 
             
            pycoze/ui/color.py,sha256=cT9Ib8uNzkOKxyW0IwVj46o4LwdB1xgNCj1_Rou9d_4,854
         | 
| 20 20 | 
             
            pycoze/ui/typ.py,sha256=NpT0FrbHvByOszBZMFtroRp7I7pN-38tYz_zPOPejF4,1723
         | 
| 21 21 | 
             
            pycoze/ui/ui_def.py,sha256=UhhU_yB3GV9ISbvTWT48hsHPHI250BhMILh6bu5Uioo,4206
         | 
| 22 22 | 
             
            pycoze/utils/__init__.py,sha256=TNJhFfY7JYdLlzuP9GvgxfNXUtbgH_NUUJSqHXCxJn4,78
         | 
| 23 23 | 
             
            pycoze/utils/arg.py,sha256=kA3KBQzXc2WlH5XbF8kfikfpqljiKaW7oY_GE4Qyffc,753
         | 
| 24 24 | 
             
            pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
         | 
| 25 | 
            -
            pycoze-0.1. | 
| 26 | 
            -
            pycoze-0.1. | 
| 27 | 
            -
            pycoze-0.1. | 
| 28 | 
            -
            pycoze-0.1. | 
| 29 | 
            -
            pycoze-0.1. | 
| 25 | 
            +
            pycoze-0.1.75.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
         | 
| 26 | 
            +
            pycoze-0.1.75.dist-info/METADATA,sha256=whsTD8FRG8nXKTOU3RrlInnqBx73vvRt21FNcMJ4qOw,719
         | 
| 27 | 
            +
            pycoze-0.1.75.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
         | 
| 28 | 
            +
            pycoze-0.1.75.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
         | 
| 29 | 
            +
            pycoze-0.1.75.dist-info/RECORD,,
         | 
| 
            File without changes
         | 
| 
            File without changes
         | 
| 
            File without changes
         |