camel-ai 0.2.71a3__py3-none-any.whl → 0.2.71a4__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.
Potentially problematic release.
This version of camel-ai might be problematic. Click here for more details.
- camel/__init__.py +1 -1
- camel/interpreters/docker_interpreter.py +3 -2
- camel/loaders/base_loader.py +85 -0
- camel/societies/workforce/workforce.py +144 -33
- camel/toolkits/__init__.py +5 -2
- camel/toolkits/craw4ai_toolkit.py +2 -2
- camel/toolkits/file_write_toolkit.py +6 -6
- camel/toolkits/hybrid_browser_toolkit/hybrid_browser_toolkit.py +9 -3
- camel/toolkits/hybrid_browser_toolkit/unified_analyzer.js +31 -8
- camel/toolkits/note_taking_toolkit.py +90 -0
- camel/toolkits/openai_image_toolkit.py +292 -0
- camel/toolkits/slack_toolkit.py +4 -4
- camel/toolkits/terminal_toolkit.py +223 -73
- camel/utils/mcp_client.py +37 -1
- {camel_ai-0.2.71a3.dist-info → camel_ai-0.2.71a4.dist-info}/METADATA +43 -4
- {camel_ai-0.2.71a3.dist-info → camel_ai-0.2.71a4.dist-info}/RECORD +18 -16
- camel/toolkits/dalle_toolkit.py +0 -175
- {camel_ai-0.2.71a3.dist-info → camel_ai-0.2.71a4.dist-info}/WHEEL +0 -0
- {camel_ai-0.2.71a3.dist-info → camel_ai-0.2.71a4.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
camel/__init__.py,sha256=
|
|
1
|
+
camel/__init__.py,sha256=mjhy_f4Jhn7jqAvNkKqu_NA6u45-Xd606dBIlFEvECY,901
|
|
2
2
|
camel/generators.py,sha256=JRqj9_m1PF4qT6UtybzTQ-KBT9MJQt18OAAYvQ_fr2o,13844
|
|
3
3
|
camel/human.py,sha256=Xg8x1cS5KK4bQ1SDByiHZnzsRpvRP-KZViNvmu38xo4,5475
|
|
4
4
|
camel/logger.py,sha256=rZVeOVYuQ9RYJ5Tqyv0usqy0g4zaVEq4qSfZ9nd2640,5755
|
|
@@ -132,7 +132,7 @@ camel/extractors/base.py,sha256=3jvuZpq27nlADDCX3GfubOpeb_zt-E9rzxF3x4lYm8s,1040
|
|
|
132
132
|
camel/extractors/python_strategies.py,sha256=zHAkshnO9o-uvLtCuVOCKoA2PzetBTnkNx1Qy_3j_pE,8113
|
|
133
133
|
camel/interpreters/__init__.py,sha256=NOQUsg7gR84zO8nBXu4JGUatsxSDJqZS6otltjXfop4,1265
|
|
134
134
|
camel/interpreters/base.py,sha256=J3DVt_dGzq1v09-gn8j2XRgEM2WoPrhKFyH9koAjkCU,2281
|
|
135
|
-
camel/interpreters/docker_interpreter.py,sha256=
|
|
135
|
+
camel/interpreters/docker_interpreter.py,sha256=h5BLl6Hs6GIH1teAFfax2OBOMvs7lpBY1zzXP9S0JM8,11372
|
|
136
136
|
camel/interpreters/e2b_interpreter.py,sha256=lNtIsVJWdSdqLoILZS8f5_7WlHI3n457RzLjmeOqH-A,5319
|
|
137
137
|
camel/interpreters/internal_python_interpreter.py,sha256=HjCIfB-HYv2cJz6nUg_8w53zHFB7DwSycqr7H22O_RI,24806
|
|
138
138
|
camel/interpreters/interpreter_error.py,sha256=uEhcmHmmcajt5C9PLeHs21h1fE6cmyt23tCAGie1kTA,880
|
|
@@ -142,6 +142,7 @@ camel/interpreters/docker/Dockerfile,sha256=n3oXzcJhELuN2oYzOyEItICga6RqtwRyjPtS
|
|
|
142
142
|
camel/loaders/__init__.py,sha256=NfXLr0gQUhfyMeB5KpU9EUvhhFLp3X5KNinDs2WO0Q0,1548
|
|
143
143
|
camel/loaders/apify_reader.py,sha256=oaVjKyNhJhG-hTuIwrpZ2hsB4XTL0M-kUksgSL2R0ck,7952
|
|
144
144
|
camel/loaders/base_io.py,sha256=zsbdBPHgSPFyQrtiUgAsHvy39QHWUObRYNaVvr-pPk0,10190
|
|
145
|
+
camel/loaders/base_loader.py,sha256=sZd-fHDNav1U0b2C3IKl4nX42OzrqRioCgRLajb6VdE,3080
|
|
145
146
|
camel/loaders/chunkr_reader.py,sha256=LC2zZvq2BiT1j2ukWPCttgo8a3RlOhFDfijYsEEQ_9I,6452
|
|
146
147
|
camel/loaders/crawl4ai_reader.py,sha256=ugfGMpWhfLnKf_XEOyDGI2ekpViDnSATg9eSxHyWX7M,7653
|
|
147
148
|
camel/loaders/firecrawl_reader.py,sha256=whHBhixQkCtJZYhhr7TgU7aMcbnfDR8LXx5If5Ci_kg,5687
|
|
@@ -278,7 +279,7 @@ camel/societies/workforce/single_agent_worker.py,sha256=-TJZtRBSUWhu9sGLwbaxHzRm
|
|
|
278
279
|
camel/societies/workforce/task_channel.py,sha256=uqQQI67Tr4awbR4bjZXdx8_4gL6-ON5IjQk_H_ryqT4,7431
|
|
279
280
|
camel/societies/workforce/utils.py,sha256=Gjlz7pLo4r1b6iNHtlIMxeEuat4d6tEEQMI40JAU3kY,6190
|
|
280
281
|
camel/societies/workforce/worker.py,sha256=36tkOyz4G2wfBdrFjt9NBPXsx4UbE6uL5on8sP2aoqk,6414
|
|
281
|
-
camel/societies/workforce/workforce.py,sha256=
|
|
282
|
+
camel/societies/workforce/workforce.py,sha256=kw8RkSi3bTxqjE7prVN92ajAXlydaF4AMn6RgWtVBGM,115738
|
|
282
283
|
camel/societies/workforce/workforce_logger.py,sha256=ihBS0NMigFWjNS3GatFYq_ViPnmYSr2jznOe4VjvxVk,24817
|
|
283
284
|
camel/storages/__init__.py,sha256=RwpEyvxpMbJzVDZJJygeBg4AzyYMkTjjkfB53hTuqGo,2141
|
|
284
285
|
camel/storages/graph_storages/__init__.py,sha256=G29BNn651C0WTOpjCl4QnVM-4B9tcNh8DdmsCiONH8Y,948
|
|
@@ -314,7 +315,7 @@ camel/terminators/__init__.py,sha256=t8uqrkUnXEOYMXQDgaBkMFJ0EXFKI0kmx4cUimli3Ls
|
|
|
314
315
|
camel/terminators/base.py,sha256=xmJzERX7GdSXcxZjAHHODa0rOxRChMSRboDCNHWSscs,1511
|
|
315
316
|
camel/terminators/response_terminator.py,sha256=n3G5KP6Oj7-7WlRN0yFcrtLpqAJKaKS0bmhrWlFfCgQ,4982
|
|
316
317
|
camel/terminators/token_limit_terminator.py,sha256=YWv6ZR8R9yI2Qnf_3xES5bEE_O5bb2CxQ0EUXfMh34c,2118
|
|
317
|
-
camel/toolkits/__init__.py,sha256=
|
|
318
|
+
camel/toolkits/__init__.py,sha256=3GFRwtjqrNYRf8yUiv0bJdyw6B-E30y9d6V7AfqOQtc,5555
|
|
318
319
|
camel/toolkits/aci_toolkit.py,sha256=39AsXloBb16hHB7DKi6mFU6NPZ3iVpM2FZgaP4o4eLE,16060
|
|
319
320
|
camel/toolkits/arxiv_toolkit.py,sha256=mw629nIN_ozaAxNv3nbvhonJKNI2-97ScRCBS3gVqNo,6297
|
|
320
321
|
camel/toolkits/ask_news_toolkit.py,sha256=WfWaqwEo1Apbil3-Rb5y65Ws43NU4rAFWZu5VHe4los,23448
|
|
@@ -325,13 +326,12 @@ camel/toolkits/bohrium_toolkit.py,sha256=453t-m0h0IGjurG6tCHUejGzfRAN2SAkhIoY8V-
|
|
|
325
326
|
camel/toolkits/browser_toolkit.py,sha256=Ntn_LmCrhqqIBWq9HtiIKw-M0cL5ebn74Ej1GBoZiC8,44400
|
|
326
327
|
camel/toolkits/browser_toolkit_commons.py,sha256=uuc1V5tN3YJmTSe6NHAVJqwsL4iYD7IiSZWxPLYW67A,22196
|
|
327
328
|
camel/toolkits/code_execution.py,sha256=ptexsx8t9teGse8ROnAHCYaLlDg843p-9p1ek-8JpWU,5620
|
|
328
|
-
camel/toolkits/craw4ai_toolkit.py,sha256=
|
|
329
|
-
camel/toolkits/dalle_toolkit.py,sha256=GSnV7reQsVmhMi9sbQy1Ks_5Vs57Dlir_AbT2PPCZwo,6153
|
|
329
|
+
camel/toolkits/craw4ai_toolkit.py,sha256=av8mqY68QgMSm27htnSdq0aqE6z3yWMVDSrNafQ6ORw,3298
|
|
330
330
|
camel/toolkits/dappier_toolkit.py,sha256=OEHOYXX_oXhgbVtWYAy13nO9uXf9i5qEXSwY4PexNFg,8194
|
|
331
331
|
camel/toolkits/data_commons_toolkit.py,sha256=aHZUSL1ACpnYGaf1rE2csVKTmXTmN8lMGRUBYhZ_YEk,14168
|
|
332
332
|
camel/toolkits/edgeone_pages_mcp_toolkit.py,sha256=1TFpAGHUNLggFQeN1OEw7P5laijwnlrCkfxBtgxFuUY,2331
|
|
333
333
|
camel/toolkits/excel_toolkit.py,sha256=9Uk5GLWl719c4W-NcGPJTNMtodAbEE5gUgLsFkIInbk,32564
|
|
334
|
-
camel/toolkits/file_write_toolkit.py,sha256=
|
|
334
|
+
camel/toolkits/file_write_toolkit.py,sha256=3fDx24XxHerPyH68Z1YvPxc34Y7yY1xp9ACOlqMpAoE,19828
|
|
335
335
|
camel/toolkits/function_tool.py,sha256=xCDzjxTRCVj_kmbnMFBuwK-3NuzM4JNe_kv9HLtjnIA,33644
|
|
336
336
|
camel/toolkits/github_toolkit.py,sha256=iUyRrjWGAW_iljZVfNyfkm1Vi55wJxK6PsDAQs9pOag,13099
|
|
337
337
|
camel/toolkits/google_calendar_toolkit.py,sha256=E-sdgdbtNBs_CXbhht9t1dsVr4DsTr5NguHkx4fvSmc,15410
|
|
@@ -350,9 +350,11 @@ camel/toolkits/memory_toolkit.py,sha256=TeKYd5UMwgjVpuS2orb-ocFL13eUNKujvrFOruDC
|
|
|
350
350
|
camel/toolkits/meshy_toolkit.py,sha256=NbgdOBD3FYLtZf-AfonIv6-Q8-8DW129jsaP1PqI2rs,7126
|
|
351
351
|
camel/toolkits/mineru_toolkit.py,sha256=vRX9LholLNkpbJ6axfEN4pTG85aWb0PDmlVy3rAAXhg,6868
|
|
352
352
|
camel/toolkits/networkx_toolkit.py,sha256=C7pUCZTzzGkFyqdkrmhRKpAHmHWfLKeuzYHC_BHPtbk,8826
|
|
353
|
+
camel/toolkits/note_taking_toolkit.py,sha256=LBJ-_zZriSmmb4PKiT1z7P0uFcRAYLuOOpdf3kTdpXI,3389
|
|
353
354
|
camel/toolkits/notion_toolkit.py,sha256=jmmVWk_WazRNWnx4r9DAvhFTAL-n_ige0tb32UHJ_ik,9752
|
|
354
355
|
camel/toolkits/open_api_toolkit.py,sha256=Venfq8JwTMQfzRzzB7AYmYUMEX35hW0BjIv_ozFMiNk,23316
|
|
355
356
|
camel/toolkits/openai_agent_toolkit.py,sha256=hT2ancdQigngAiY1LNnGJzZeiBDHUxrRGv6BdZTJizc,4696
|
|
357
|
+
camel/toolkits/openai_image_toolkit.py,sha256=-7_3utTx3T2GgDSW5Sdz4yBDzUcBMimC2QUaXXvDWXg,11168
|
|
356
358
|
camel/toolkits/openbb_toolkit.py,sha256=8yBZL9E2iSgskosBQhD3pTP56oV6gerWpFjIJc_2UMo,28935
|
|
357
359
|
camel/toolkits/page_script.js,sha256=mXepZPnQNVLp_Wgb64lv7DMQIJYl_XIHJHLVt1OFZO4,13146
|
|
358
360
|
camel/toolkits/playwright_mcp_toolkit.py,sha256=TRweKatFu-7UzfiuXrud2D_4OQjbf4tdP_sCBJ69FG8,3018
|
|
@@ -365,11 +367,11 @@ camel/toolkits/retrieval_toolkit.py,sha256=BKjEyOqW3cGEPTS5yHPYb-Qg795iNNPIs1wjo
|
|
|
365
367
|
camel/toolkits/search_toolkit.py,sha256=5BOBQS5LV33mpRwO9vnnexn9Lsqu6MkO3IgaXJBp7ZQ,43742
|
|
366
368
|
camel/toolkits/searxng_toolkit.py,sha256=a2GtE4FGSrmaIVvX6Yide-abBYD1wsHqitnDlx9fdVg,7664
|
|
367
369
|
camel/toolkits/semantic_scholar_toolkit.py,sha256=Rh7eA_YPxV5pvPIzhjjvpr3vtlaCniJicrqzkPWW9_I,11634
|
|
368
|
-
camel/toolkits/slack_toolkit.py,sha256=
|
|
370
|
+
camel/toolkits/slack_toolkit.py,sha256=4Bj8P2ardLwfiyUz3ha5QobSvziV54E9zipysCg9GuI,11208
|
|
369
371
|
camel/toolkits/stripe_toolkit.py,sha256=07swo5znGTnorafC1uYLKB4NRcJIOPOx19J7tkpLYWk,10102
|
|
370
372
|
camel/toolkits/sympy_toolkit.py,sha256=BAQnI8EFJydNUpKQWXBdleQ1Cm-srDBhFlqp9V9pbPQ,33757
|
|
371
373
|
camel/toolkits/task_planning_toolkit.py,sha256=Ttw9fHae4omGC1SA-6uaeXVHJ1YkwiVloz_hO-fm1gw,4855
|
|
372
|
-
camel/toolkits/terminal_toolkit.py,sha256=
|
|
374
|
+
camel/toolkits/terminal_toolkit.py,sha256=fvFE-VJl5dgAmp27pplxc1y1Bw1KlkUjCU5jlnrdWKA,50543
|
|
373
375
|
camel/toolkits/thinking_toolkit.py,sha256=nZYLvKWIx2BM1DYu69I9B5EISAG7aYcLYXKv9663BVk,8000
|
|
374
376
|
camel/toolkits/twitter_toolkit.py,sha256=Px4N8aUxUzy01LhGSWkdrC2JgwKkrY3cvxgMeJ2XYfU,15939
|
|
375
377
|
camel/toolkits/video_analysis_toolkit.py,sha256=Wh08MAVvs3PtgXN88Sk0TXYaGfVmQAol8FPCXMPPpIM,23375
|
|
@@ -382,9 +384,9 @@ camel/toolkits/hybrid_browser_toolkit/__init__.py,sha256=vxjWhq7GjUKE5I9RGQU_Goi
|
|
|
382
384
|
camel/toolkits/hybrid_browser_toolkit/actions.py,sha256=687NtNdjkx8MfXQRSY7hSUAshZnVBxCbYYHZjnal_Go,8746
|
|
383
385
|
camel/toolkits/hybrid_browser_toolkit/agent.py,sha256=nYTNeLEaPg1bhzl65IcG9JkjiS9cRNV3bjsyct4pzM8,10881
|
|
384
386
|
camel/toolkits/hybrid_browser_toolkit/browser_session.py,sha256=ZbPTKoRJaA4kcd-i9B9J98MEaAgPZ3FGjNzs3IJdoWs,11034
|
|
385
|
-
camel/toolkits/hybrid_browser_toolkit/hybrid_browser_toolkit.py,sha256=
|
|
387
|
+
camel/toolkits/hybrid_browser_toolkit/hybrid_browser_toolkit.py,sha256=4RoVnodjIEUNg64Qz9gOQdqWT2Exh0l5Cz7XyZqV5wo,38188
|
|
386
388
|
camel/toolkits/hybrid_browser_toolkit/snapshot.py,sha256=0gVhOsGujUmv-LdQ5FZGfRNmKaECmJah5W-FOAOu64Q,8489
|
|
387
|
-
camel/toolkits/hybrid_browser_toolkit/unified_analyzer.js,sha256=
|
|
389
|
+
camel/toolkits/hybrid_browser_toolkit/unified_analyzer.js,sha256=FXzbnjjXRRaMo5PBFgxa84UFWLn5jymBnFvW_yHdzCM,17378
|
|
388
390
|
camel/toolkits/open_api_specs/security_config.py,sha256=ZVnBa_zEifaE_ao2xsvV5majuJHpn2Tn7feMDOnj-eo,898
|
|
389
391
|
camel/toolkits/open_api_specs/biztoc/__init__.py,sha256=OKCZrQCDwaWtXIN_2rA9FSqEvgpQRieRoHh7Ek6N16A,702
|
|
390
392
|
camel/toolkits/open_api_specs/biztoc/ai-plugin.json,sha256=IJinQbLv5MFPGFwdN7PbOhwArFVExSEZdJspe-mOBIo,866
|
|
@@ -425,7 +427,7 @@ camel/utils/deduplication.py,sha256=UHikAtOW1TTDunf2t_wa2kFbmkrXWf7HfOKwLvwCxzo,
|
|
|
425
427
|
camel/utils/filename.py,sha256=HYNc1wbSCgNR1CN21cwHxdAhpnsf5ySJ6jUDfeqOK20,2532
|
|
426
428
|
camel/utils/langfuse.py,sha256=OowR6A790XG-b0UHiTYduYvS18PvSGFdmqki2Poogo0,8578
|
|
427
429
|
camel/utils/mcp.py,sha256=iuthL8VuUXIRU34Nvx8guq7frfglpZoxewUKuAg3e1s,5077
|
|
428
|
-
camel/utils/mcp_client.py,sha256
|
|
430
|
+
camel/utils/mcp_client.py,sha256=-EIUj6v2hXB75Xvj2FyEedwUMEpUUVXzXWNLLYGrJfE,37305
|
|
429
431
|
camel/utils/message_summarizer.py,sha256=7AvPDlevle5uU3mXtfvSFS--nDjp9yqfrf546qTe9rE,5939
|
|
430
432
|
camel/utils/response_format.py,sha256=xZcx6xBxeg3A0e7R0JCMJdNm2oQ1-diqVLs0JsiCkZU,5319
|
|
431
433
|
camel/utils/token_counting.py,sha256=apkERzNoVc4sgvJvWVosvepX3KH8pVypVjrL4AA7RB4,17521
|
|
@@ -440,7 +442,7 @@ camel/verifiers/math_verifier.py,sha256=tA1D4S0sm8nsWISevxSN0hvSVtIUpqmJhzqfbuMo
|
|
|
440
442
|
camel/verifiers/models.py,sha256=GdxYPr7UxNrR1577yW4kyroRcLGfd-H1GXgv8potDWU,2471
|
|
441
443
|
camel/verifiers/physics_verifier.py,sha256=c1grrRddcrVN7szkxhv2QirwY9viIRSITWeWFF5HmLs,30187
|
|
442
444
|
camel/verifiers/python_verifier.py,sha256=ogTz77wODfEcDN4tMVtiSkRQyoiZbHPY2fKybn59lHw,20558
|
|
443
|
-
camel_ai-0.2.
|
|
444
|
-
camel_ai-0.2.
|
|
445
|
-
camel_ai-0.2.
|
|
446
|
-
camel_ai-0.2.
|
|
445
|
+
camel_ai-0.2.71a4.dist-info/METADATA,sha256=3CoGV8F81-m6rHNRF3x6avCTCHP_T20FC3hge3w-fWQ,49893
|
|
446
|
+
camel_ai-0.2.71a4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
447
|
+
camel_ai-0.2.71a4.dist-info/licenses/LICENSE,sha256=id0nB2my5kG0xXeimIu5zZrbHLS6EQvxvkKkzIHaT2k,11343
|
|
448
|
+
camel_ai-0.2.71a4.dist-info/RECORD,,
|
camel/toolkits/dalle_toolkit.py
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
2
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
# you may not use this file except in compliance with the License.
|
|
4
|
-
# You may obtain a copy of the License at
|
|
5
|
-
#
|
|
6
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
#
|
|
8
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
# See the License for the specific language governing permissions and
|
|
12
|
-
# limitations under the License.
|
|
13
|
-
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
|
-
|
|
15
|
-
# Enables postponed evaluation of annotations (for string-based type hints)
|
|
16
|
-
from __future__ import annotations
|
|
17
|
-
|
|
18
|
-
import base64
|
|
19
|
-
import os
|
|
20
|
-
import uuid
|
|
21
|
-
from io import BytesIO
|
|
22
|
-
from typing import List, Optional
|
|
23
|
-
|
|
24
|
-
from openai import OpenAI
|
|
25
|
-
from PIL import Image
|
|
26
|
-
|
|
27
|
-
from camel.logger import get_logger
|
|
28
|
-
from camel.toolkits import FunctionTool
|
|
29
|
-
from camel.toolkits.base import BaseToolkit
|
|
30
|
-
from camel.utils import MCPServer
|
|
31
|
-
|
|
32
|
-
logger = get_logger(__name__)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
@MCPServer()
|
|
36
|
-
class DalleToolkit(BaseToolkit):
|
|
37
|
-
r"""A class representing a toolkit for image generation using OpenAI's
|
|
38
|
-
DALL-E model.
|
|
39
|
-
"""
|
|
40
|
-
|
|
41
|
-
def __init__(
|
|
42
|
-
self,
|
|
43
|
-
timeout: Optional[float] = None,
|
|
44
|
-
):
|
|
45
|
-
r"""Initializes a new instance of the DalleToolkit class.
|
|
46
|
-
|
|
47
|
-
Args:
|
|
48
|
-
timeout (Optional[float]): The timeout value for API requests
|
|
49
|
-
in seconds. If None, no timeout is applied.
|
|
50
|
-
(default: :obj:`None`)
|
|
51
|
-
"""
|
|
52
|
-
super().__init__(timeout=timeout)
|
|
53
|
-
|
|
54
|
-
def base64_to_image(self, base64_string: str) -> Optional[Image.Image]:
|
|
55
|
-
r"""Converts a base64 encoded string into a PIL Image object.
|
|
56
|
-
|
|
57
|
-
Args:
|
|
58
|
-
base64_string (str): The base64 encoded string of the image.
|
|
59
|
-
|
|
60
|
-
Returns:
|
|
61
|
-
Optional[Image.Image]: The PIL Image object or None if conversion
|
|
62
|
-
fails.
|
|
63
|
-
"""
|
|
64
|
-
try:
|
|
65
|
-
# Decode the base64 string to get the image data
|
|
66
|
-
image_data = base64.b64decode(base64_string)
|
|
67
|
-
# Create a memory buffer for the image data
|
|
68
|
-
image_buffer = BytesIO(image_data)
|
|
69
|
-
# Open the image using the PIL library
|
|
70
|
-
image = Image.open(image_buffer)
|
|
71
|
-
return image
|
|
72
|
-
except Exception as e:
|
|
73
|
-
error_msg = (
|
|
74
|
-
f"An error occurred while converting base64 to image: {e}"
|
|
75
|
-
)
|
|
76
|
-
logger.error(error_msg)
|
|
77
|
-
return None
|
|
78
|
-
|
|
79
|
-
def image_path_to_base64(self, image_path: str) -> str:
|
|
80
|
-
r"""Converts the file path of an image to a Base64 encoded string.
|
|
81
|
-
|
|
82
|
-
Args:
|
|
83
|
-
image_path (str): The path to the image file.
|
|
84
|
-
|
|
85
|
-
Returns:
|
|
86
|
-
str: A Base64 encoded string representing the content of the image
|
|
87
|
-
file.
|
|
88
|
-
"""
|
|
89
|
-
try:
|
|
90
|
-
with open(image_path, "rb") as image_file:
|
|
91
|
-
return base64.b64encode(image_file.read()).decode('utf-8')
|
|
92
|
-
except Exception as e:
|
|
93
|
-
error_msg = (
|
|
94
|
-
f"An error occurred while converting image path to base64: {e}"
|
|
95
|
-
)
|
|
96
|
-
logger.error(error_msg)
|
|
97
|
-
return error_msg
|
|
98
|
-
|
|
99
|
-
def image_to_base64(self, image: Image.Image) -> str:
|
|
100
|
-
r"""Converts an image into a base64-encoded string.
|
|
101
|
-
|
|
102
|
-
This function takes an image object as input, encodes the image into a
|
|
103
|
-
PNG format base64 string, and returns it.
|
|
104
|
-
If the encoding process encounters an error, it prints the error
|
|
105
|
-
message and returns None.
|
|
106
|
-
|
|
107
|
-
Args:
|
|
108
|
-
image: The image object to be encoded, supports any image format
|
|
109
|
-
that can be saved in PNG format.
|
|
110
|
-
|
|
111
|
-
Returns:
|
|
112
|
-
str: A base64-encoded string of the image.
|
|
113
|
-
"""
|
|
114
|
-
try:
|
|
115
|
-
with BytesIO() as buffered_image:
|
|
116
|
-
image.save(buffered_image, format="PNG")
|
|
117
|
-
buffered_image.seek(0)
|
|
118
|
-
image_bytes = buffered_image.read()
|
|
119
|
-
base64_str = base64.b64encode(image_bytes).decode('utf-8')
|
|
120
|
-
return base64_str
|
|
121
|
-
except Exception as e:
|
|
122
|
-
error_msg = f"An error occurred: {e}"
|
|
123
|
-
logger.error(error_msg)
|
|
124
|
-
return error_msg
|
|
125
|
-
|
|
126
|
-
def get_dalle_img(self, prompt: str, image_dir: str = "img") -> str:
|
|
127
|
-
r"""Generate an image using OpenAI's DALL-E model.
|
|
128
|
-
The generated image is saved to the specified directory.
|
|
129
|
-
|
|
130
|
-
Args:
|
|
131
|
-
prompt (str): The text prompt based on which the image is
|
|
132
|
-
generated.
|
|
133
|
-
image_dir (str): The directory to save the generated image.
|
|
134
|
-
Defaults to 'img'.
|
|
135
|
-
|
|
136
|
-
Returns:
|
|
137
|
-
str: The path to the saved image.
|
|
138
|
-
"""
|
|
139
|
-
|
|
140
|
-
dalle_client = OpenAI()
|
|
141
|
-
response = dalle_client.images.generate(
|
|
142
|
-
model="dall-e-3",
|
|
143
|
-
prompt=prompt,
|
|
144
|
-
size="1024x1792",
|
|
145
|
-
quality="standard",
|
|
146
|
-
n=1, # NOTE: now dall-e-3 only supports n=1
|
|
147
|
-
response_format="b64_json",
|
|
148
|
-
)
|
|
149
|
-
if response.data is None or len(response.data) == 0:
|
|
150
|
-
error_msg = "No image data returned from DALL-E API."
|
|
151
|
-
logger.error(error_msg)
|
|
152
|
-
return error_msg
|
|
153
|
-
image_b64 = response.data[0].b64_json
|
|
154
|
-
image = self.base64_to_image(image_b64) # type: ignore[arg-type]
|
|
155
|
-
|
|
156
|
-
if image is None:
|
|
157
|
-
error_msg = "Failed to convert base64 string to image."
|
|
158
|
-
logger.error(error_msg)
|
|
159
|
-
return error_msg
|
|
160
|
-
|
|
161
|
-
os.makedirs(image_dir, exist_ok=True)
|
|
162
|
-
image_path = os.path.join(image_dir, f"{uuid.uuid4()}.png")
|
|
163
|
-
image.save(image_path)
|
|
164
|
-
|
|
165
|
-
return image_path
|
|
166
|
-
|
|
167
|
-
def get_tools(self) -> List[FunctionTool]:
|
|
168
|
-
r"""Returns a list of FunctionTool objects representing the
|
|
169
|
-
functions in the toolkit.
|
|
170
|
-
|
|
171
|
-
Returns:
|
|
172
|
-
List[FunctionTool]: A list of FunctionTool objects
|
|
173
|
-
representing the functions in the toolkit.
|
|
174
|
-
"""
|
|
175
|
-
return [FunctionTool(self.get_dalle_img)]
|
|
File without changes
|
|
File without changes
|