agentica 0.2.2__tar.gz → 0.2.3__tar.gz
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.
- {agentica-0.2.2/agentica.egg-info → agentica-0.2.3}/PKG-INFO +5 -6
- {agentica-0.2.2 → agentica-0.2.3}/README.md +4 -5
- {agentica-0.2.2 → agentica-0.2.3}/agentica/__init__.py +3 -1
- {agentica-0.2.2 → agentica-0.2.3}/agentica/agent.py +4 -2
- agentica-0.2.3/agentica/emb/zhipuai_emb.py +15 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/doubao/chat.py +1 -1
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/message.py +4 -3
- agentica-0.2.3/agentica/model/zhipuai/__init__.py +1 -0
- agentica-0.2.3/agentica/model/zhipuai/chat.py +24 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/python_agent.py +5 -0
- agentica-0.2.3/agentica/react_agent.py +195 -0
- agentica-0.2.3/agentica/tools/cogvideo_tool.py +153 -0
- agentica-0.2.3/agentica/tools/cogview_tool.py +127 -0
- agentica-0.2.2/agentica/tools/create_image_tool.py → agentica-0.2.3/agentica/tools/dalle_tool.py +5 -5
- agentica-0.2.3/agentica/tools/string_tool.py +61 -0
- agentica-0.2.3/agentica/tools/web_search_pro_tool.py +81 -0
- agentica-0.2.3/agentica/version.py +1 -0
- {agentica-0.2.2 → agentica-0.2.3/agentica.egg-info}/PKG-INFO +5 -6
- {agentica-0.2.2 → agentica-0.2.3}/agentica.egg-info/SOURCES.txt +9 -1
- agentica-0.2.2/agentica/version.py +0 -1
- {agentica-0.2.2 → agentica-0.2.3}/LICENSE +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/MANIFEST.in +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/agent_session.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/config.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/document.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/emb/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/emb/azure_openai_emb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/emb/base.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/emb/fireworks_emb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/emb/genimi_emb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/emb/hash_emb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/emb/huggingface_emb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/emb/ollama_emb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/emb/openai_emb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/emb/sentence_transformer_emb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/emb/text2vec_emb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/emb/together_emb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/emb/word2vec_emb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/file/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/file/base.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/file/csv.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/file/txt.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/knowledge/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/knowledge/base.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/knowledge/langchain_knowledge.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/knowledge/llamaindex_knowledge.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/memory.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/memorydb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/anthropic/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/anthropic/claude.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/aws/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/aws/api_client.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/aws/bedrock.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/aws/claude.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/azure/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/azure/openai_chat.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/base.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/cohere/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/cohere/chat.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/content.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/deepseek/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/deepseek/chat.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/doubao/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/fireworks/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/fireworks/fireworks.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/google/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/google/gemini.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/google/gemini_openai.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/groq/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/groq/groq.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/huggingface/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/huggingface/hf.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/internlm/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/internlm/chat.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/mistral/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/mistral/mistral.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/moonshot/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/moonshot/chat.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/nvidia/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/nvidia/chat.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/ollama/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/ollama/chat.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/ollama/hermes.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/ollama/tools.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/openai/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/openai/chat.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/openai/like.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/openrouter/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/openrouter/openrouter.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/response.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/sambanova/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/sambanova/sambanova.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/together/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/together/togetherchat.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/vertexai/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/vertexai/gemini.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/xai/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/xai/grok.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/yi/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/model/yi/chat.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/reasoning.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/reranker/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/reranker/base.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/reranker/bge.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/reranker/cohere.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/run_response.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/storage/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/storage/agent/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/storage/agent/base.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/storage/agent/json_file.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/storage/agent/postgres.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/storage/agent/sqlite.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/storage/agent/yaml_file.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/storage/workflow/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/storage/workflow/base.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/storage/workflow/postgres.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/storage/workflow/sqlite.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/template.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/airflow_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/analyze_image_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/apify_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/arxiv_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/baidusearch_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/base.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/calculator_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/dblp_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/duckduckgo_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/file_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/hackernews_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/jina_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/newspaper_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/ocr_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/resend_tools.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/run_nb_code_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/run_python_code_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/search_exa_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/search_serper_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/shell_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/sql_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/text_analysis_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/url_crawler_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/wikipedia_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/tools/yfinance_tool.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/utils/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/utils/console.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/utils/file_parser.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/utils/io.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/utils/json_util.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/utils/log.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/utils/misc.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/utils/shell.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/utils/timer.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/vectordb/__init__.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/vectordb/base.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/vectordb/chromadb_vectordb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/vectordb/lancedb_vectordb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/vectordb/memory_vectordb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/vectordb/pgvectordb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/vectordb/pineconedb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/vectordb/qdrantdb.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/workflow.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica/workflow_session.py +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica.egg-info/dependency_links.txt +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica.egg-info/entry_points.txt +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica.egg-info/not-zip-safe +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica.egg-info/requires.txt +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/agentica.egg-info/top_level.txt +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/setup.cfg +0 -0
- {agentica-0.2.2 → agentica-0.2.3}/setup.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: agentica
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.3
|
4
4
|
Summary: LLM agents
|
5
5
|
Home-page: https://github.com/shibing624/agentica
|
6
6
|
Author: XuMing
|
@@ -49,14 +49,11 @@ Requires-Dist: rich
|
|
49
49
|
[](#Contact)
|
50
50
|
|
51
51
|
|
52
|
-
**Agentica**:
|
52
|
+
**Agentica**: 轻松构建智能、具备反思能力、可协作的多模态AI Agent。
|
53
53
|
|
54
|
-
**Agentica**: 快速打造智能、能反思、协作的AI Agent。
|
55
54
|
|
56
55
|
## 📖 Introduction
|
57
56
|
|
58
|
-
**Agentica** can build AI agent, which have the components of planning, memory, and tool use.
|
59
|
-
|
60
57
|
**Agentica** 可以构建AI Agent,包括规划、记忆和工具使用、执行等组件。
|
61
58
|
|
62
59
|
#### Agent Components
|
@@ -79,6 +76,8 @@ Requires-Dist: rich
|
|
79
76
|
- **Solver**:求解器将所有这些输出整合为最终答案
|
80
77
|
|
81
78
|
## 🔥 News
|
79
|
+
[2024/12/29] v0.2.3版本: 支持了`ZhipuAI`的api调用,包括免费模型和工具使用,详见[Release-v0.2.3](https://github.com/shibing624/agentica/releases/tag/0.2.3)
|
80
|
+
|
82
81
|
[2024/12/25] v0.2.0版本: 支持了多模态模型,输入可以是文本、图片、音频、视频,升级Assistant为Agent,Workflow支持拆解并实现复杂任务,详见[Release-v0.2.0](https://github.com/shibing624/agentica/releases/tag/0.2.0)
|
83
82
|
|
84
83
|
[2024/07/02] v0.1.0版本:实现了基于LLM的Assistant,可以快速用function call搭建大语言模型助手,详见[Release-v0.1.0](https://github.com/shibing624/agentica/releases/tag/0.1.0)
|
@@ -121,7 +120,7 @@ cd examples
|
|
121
120
|
python web_search_moonshot_demo.py
|
122
121
|
```
|
123
122
|
|
124
|
-
1. 复制[.env.example](https://github.com/shibing624/agentica/blob/main/.env.example)文件为`~/.agentica/.env`,并填写LLM api key(选填DEEPSEEK_API_KEY、MOONSHOT_API_KEY、OPENAI_API_KEY等任一个即可)。或者使用`export`命令设置环境变量:
|
123
|
+
1. 复制[.env.example](https://github.com/shibing624/agentica/blob/main/.env.example)文件为`~/.agentica/.env`,并填写LLM api key(选填DEEPSEEK_API_KEY、MOONSHOT_API_KEY、OPENAI_API_KEY、ZHIPUAI_API_KEY等任一个即可)。或者使用`export`命令设置环境变量:
|
125
124
|
|
126
125
|
```shell
|
127
126
|
export MOONSHOT_API_KEY=your_moonshot_api_key
|
@@ -18,14 +18,11 @@
|
|
18
18
|
[](#Contact)
|
19
19
|
|
20
20
|
|
21
|
-
**Agentica**:
|
21
|
+
**Agentica**: 轻松构建智能、具备反思能力、可协作的多模态AI Agent。
|
22
22
|
|
23
|
-
**Agentica**: 快速打造智能、能反思、协作的AI Agent。
|
24
23
|
|
25
24
|
## 📖 Introduction
|
26
25
|
|
27
|
-
**Agentica** can build AI agent, which have the components of planning, memory, and tool use.
|
28
|
-
|
29
26
|
**Agentica** 可以构建AI Agent,包括规划、记忆和工具使用、执行等组件。
|
30
27
|
|
31
28
|
#### Agent Components
|
@@ -48,6 +45,8 @@
|
|
48
45
|
- **Solver**:求解器将所有这些输出整合为最终答案
|
49
46
|
|
50
47
|
## 🔥 News
|
48
|
+
[2024/12/29] v0.2.3版本: 支持了`ZhipuAI`的api调用,包括免费模型和工具使用,详见[Release-v0.2.3](https://github.com/shibing624/agentica/releases/tag/0.2.3)
|
49
|
+
|
51
50
|
[2024/12/25] v0.2.0版本: 支持了多模态模型,输入可以是文本、图片、音频、视频,升级Assistant为Agent,Workflow支持拆解并实现复杂任务,详见[Release-v0.2.0](https://github.com/shibing624/agentica/releases/tag/0.2.0)
|
52
51
|
|
53
52
|
[2024/07/02] v0.1.0版本:实现了基于LLM的Assistant,可以快速用function call搭建大语言模型助手,详见[Release-v0.1.0](https://github.com/shibing624/agentica/releases/tag/0.1.0)
|
@@ -90,7 +89,7 @@ cd examples
|
|
90
89
|
python web_search_moonshot_demo.py
|
91
90
|
```
|
92
91
|
|
93
|
-
1. 复制[.env.example](https://github.com/shibing624/agentica/blob/main/.env.example)文件为`~/.agentica/.env`,并填写LLM api key(选填DEEPSEEK_API_KEY、MOONSHOT_API_KEY、OPENAI_API_KEY等任一个即可)。或者使用`export`命令设置环境变量:
|
92
|
+
1. 复制[.env.example](https://github.com/shibing624/agentica/blob/main/.env.example)文件为`~/.agentica/.env`,并填写LLM api key(选填DEEPSEEK_API_KEY、MOONSHOT_API_KEY、OPENAI_API_KEY、ZHIPUAI_API_KEY等任一个即可)。或者使用`export`命令设置环境变量:
|
94
93
|
|
95
94
|
```shell
|
96
95
|
export MOONSHOT_API_KEY=your_moonshot_api_key
|
@@ -21,6 +21,7 @@ from agentica.model.doubao.chat import DoubaoChat
|
|
21
21
|
from agentica.model.together.togetherchat import TogetherChat
|
22
22
|
from agentica.model.xai.grok import GrokChat
|
23
23
|
from agentica.model.yi.chat import YiChat
|
24
|
+
from agentica.model.zhipuai.chat import ZhipuAIChat
|
24
25
|
|
25
26
|
# memory
|
26
27
|
from agentica.model.base import Model
|
@@ -72,6 +73,7 @@ from agentica.emb.hash_emb import HashEmb
|
|
72
73
|
from agentica.emb.ollama_emb import OllamaEmb
|
73
74
|
from agentica.emb.together_emb import TogetherEmb
|
74
75
|
from agentica.emb.fireworks_emb import FireworksEmb
|
76
|
+
from agentica.emb.zhipuai_emb import ZhipuAIEmb
|
75
77
|
|
76
78
|
# file
|
77
79
|
from agentica.file.base import File
|
@@ -94,7 +96,7 @@ from agentica.tools.search_serper_tool import SearchSerperTool
|
|
94
96
|
from agentica.tools.run_python_code_tool import RunPythonCodeTool
|
95
97
|
from agentica.tools.analyze_image_tool import AnalyzeImageTool
|
96
98
|
from agentica.tools.calculator_tool import CalculatorTool
|
97
|
-
from agentica.tools.
|
99
|
+
from agentica.tools.dalle_tool import DalleTool
|
98
100
|
from agentica.tools.file_tool import FileTool
|
99
101
|
from agentica.tools.hackernews_tool import HackerNewsTool
|
100
102
|
from agentica.tools.jina_tool import JinaTool
|
@@ -1998,7 +1998,8 @@ class Agent(BaseModel):
|
|
1998
1998
|
logger.warning(f"Failed to convert response to pydantic model: {exc}")
|
1999
1999
|
# Check if response starts with ```json
|
2000
2000
|
if run_response.content.startswith("```json"):
|
2001
|
-
run_response.content = run_response.content.replace(
|
2001
|
+
run_response.content = run_response.content.replace(
|
2002
|
+
"```json\n", "").replace("\n```", "")
|
2002
2003
|
try:
|
2003
2004
|
structured_output = self.response_model.model_validate_json(run_response.content)
|
2004
2005
|
except ValidationError as exc:
|
@@ -2307,7 +2308,8 @@ class Agent(BaseModel):
|
|
2307
2308
|
logger.warning(f"Failed to convert response to pydantic model: {exc}")
|
2308
2309
|
# Check if response starts with ```json
|
2309
2310
|
if run_response.content.startswith("```json"):
|
2310
|
-
run_response.content = run_response.content.replace(
|
2311
|
+
run_response.content = run_response.content.replace(
|
2312
|
+
"```json\n", "").replace("\n```", "")
|
2311
2313
|
try:
|
2312
2314
|
structured_output = self.response_model.model_validate_json(run_response.content)
|
2313
2315
|
except ValidationError as exc:
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"""
|
2
|
+
@author:XuMing(xuming624@qq.com)
|
3
|
+
@description:
|
4
|
+
"""
|
5
|
+
from os import getenv
|
6
|
+
from typing import Optional
|
7
|
+
|
8
|
+
from agentica.emb.openai_emb import OpenAIEmb
|
9
|
+
|
10
|
+
|
11
|
+
class ZhipuAIEmb(OpenAIEmb):
|
12
|
+
model: str = "embedding-3"
|
13
|
+
dimensions: int = 2048
|
14
|
+
api_key: Optional[str] = getenv("ZHIPUAI_API_KEY")
|
15
|
+
base_url: str = "https://open.bigmodel.cn/api/paas/v4"
|
@@ -18,7 +18,7 @@ class DoubaoChat(OpenAILike):
|
|
18
18
|
|
19
19
|
id: str = "ep-20241012172611-btlgr"
|
20
20
|
name: str = "DoubaoChat"
|
21
|
-
provider: str = "
|
21
|
+
provider: str = "ByteDance"
|
22
22
|
|
23
23
|
api_key: Optional[str] = getenv("ARK_API_KEY", None)
|
24
24
|
base_url: str = "https://ark.cn-beijing.volces.com/api/v3"
|
@@ -85,7 +85,8 @@ class Message(BaseModel):
|
|
85
85
|
@param level: The level to log the message at. One of debug, info, warning, or error.
|
86
86
|
Defaults to debug.
|
87
87
|
"""
|
88
|
-
|
88
|
+
level = level or "debug"
|
89
|
+
level = level.lower()
|
89
90
|
if level == "debug":
|
90
91
|
_logger = logger.debug
|
91
92
|
elif level == "info":
|
@@ -94,6 +95,8 @@ class Message(BaseModel):
|
|
94
95
|
_logger = logger.warning
|
95
96
|
elif level == "error":
|
96
97
|
_logger = logger.error
|
98
|
+
else:
|
99
|
+
_logger = logger.debug
|
97
100
|
|
98
101
|
_logger(f"============== {self.role} ==============")
|
99
102
|
if self.name:
|
@@ -120,8 +123,6 @@ class Message(BaseModel):
|
|
120
123
|
_logger("Message contains raw audio data")
|
121
124
|
else:
|
122
125
|
_logger(f"Audio file added: {self.audio}")
|
123
|
-
# if self.model_extra and "images" in self.model_extra:
|
124
|
-
# _logger("images: {}".format(self.model_extra["images"]))
|
125
126
|
|
126
127
|
def content_is_valid(self) -> bool:
|
127
128
|
"""Check if the message content is valid."""
|
@@ -0,0 +1 @@
|
|
1
|
+
from agentica.model.zhipuai.chat import ZhipuAIChat
|
@@ -0,0 +1,24 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
from os import getenv
|
3
|
+
|
4
|
+
from agentica.model.openai.like import OpenAILike
|
5
|
+
|
6
|
+
|
7
|
+
class ZhipuAIChat(OpenAILike):
|
8
|
+
"""
|
9
|
+
A model class for ZhipuAI Chat API.
|
10
|
+
|
11
|
+
Attributes:
|
12
|
+
- id: str: The unique identifier of the model, model_name.
|
13
|
+
- name: str: The name of the class.
|
14
|
+
- provider: str: The provider of the model.
|
15
|
+
- api_key: Optional[str]: The API key for the model.
|
16
|
+
- base_url: str: The base URL for the model.
|
17
|
+
"""
|
18
|
+
|
19
|
+
id: str = "glm-4-flash"
|
20
|
+
name: str = "ZhipuAIChat"
|
21
|
+
provider: str = "ZhipuAI"
|
22
|
+
|
23
|
+
api_key: Optional[str] = getenv("ZHIPUAI_API_KEY", None)
|
24
|
+
base_url: str = "https://open.bigmodel.cn/api/paas/v4"
|
@@ -0,0 +1,195 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
A minimal implementation of a ReACT agent with support for multiple tools.
|
4
|
+
"""
|
5
|
+
import re
|
6
|
+
from loguru import logger
|
7
|
+
from openai import OpenAI
|
8
|
+
|
9
|
+
# Registry to hold available actions
|
10
|
+
action_registry = {}
|
11
|
+
|
12
|
+
|
13
|
+
def register_action(action_name):
|
14
|
+
"""Decorator to register an action in the action registry."""
|
15
|
+
|
16
|
+
def decorator(func):
|
17
|
+
action_registry[action_name] = func
|
18
|
+
return func
|
19
|
+
|
20
|
+
return decorator
|
21
|
+
|
22
|
+
|
23
|
+
def parse_response(response):
|
24
|
+
"""Parse the model's response into thoughts and actions."""
|
25
|
+
thoughts = []
|
26
|
+
actions = []
|
27
|
+
lines = response.split('\n')
|
28
|
+
for line in lines:
|
29
|
+
if line.startswith("Thought:"):
|
30
|
+
thoughts.append(line[len("Thought:"):].strip())
|
31
|
+
elif line.startswith("Action:"):
|
32
|
+
actions.append(line[len("Action:"):].strip())
|
33
|
+
return thoughts, actions
|
34
|
+
|
35
|
+
|
36
|
+
def parse_action(action_str):
|
37
|
+
"""Parse an action string into action name and parameters."""
|
38
|
+
match = re.match(r'^(\w+)\((.*)\)$', action_str)
|
39
|
+
if match:
|
40
|
+
action_name = match.group(1)
|
41
|
+
params = match.group(2)
|
42
|
+
# Remove parameter names and keep only values
|
43
|
+
params = re.sub(r'\w+=', '', params)
|
44
|
+
logger.debug(f"Action name: {action_name}, Params: {params}")
|
45
|
+
return action_name, params
|
46
|
+
else:
|
47
|
+
logger.warning(f"Invalid action string: {action_str}")
|
48
|
+
return None, None
|
49
|
+
|
50
|
+
|
51
|
+
TOOL_DESC = """{name_for_model}: Call this tool to interact with the {name_for_human} API. What is the {name_for_human} API useful for? {description_for_model} Parameters: {parameters}"""
|
52
|
+
|
53
|
+
PROMPT_REACT = """You are an assistant that uses the ReACT framework to answer questions.
|
54
|
+
|
55
|
+
First, describe your thought process in the "Thought:" section, then describe the action you will take in the "Action:" section.
|
56
|
+
Each section should start with its respective label.
|
57
|
+
Adjust your thoughts and actions based on the results of previous actions until you arrive at the final answer.
|
58
|
+
Ensure that each action is described in the format "Action: action_name(parameters)".
|
59
|
+
Available actions include:
|
60
|
+
|
61
|
+
{tools_text}
|
62
|
+
|
63
|
+
Begin!
|
64
|
+
"""
|
65
|
+
|
66
|
+
|
67
|
+
class ReactAgent:
|
68
|
+
"""A ReACT agent that interacts with the OpenAI API to perform actions based on user queries."""
|
69
|
+
|
70
|
+
def __init__(self, model_name="gpt-4o", tools=None):
|
71
|
+
self.model_name = model_name
|
72
|
+
self.tools = tools or []
|
73
|
+
self.action_registry = action_registry
|
74
|
+
self.client = OpenAI()
|
75
|
+
self.logger = logger
|
76
|
+
self.system_prompt = self._generate_system_prompt()
|
77
|
+
|
78
|
+
def _generate_system_prompt(self):
|
79
|
+
tools_text = "\n".join([TOOL_DESC.format(**tool) for tool in self.tools])
|
80
|
+
return PROMPT_REACT.format(tools_text=tools_text)
|
81
|
+
|
82
|
+
def get_model_response(self, messages):
|
83
|
+
"""Get a response from the OpenAI model."""
|
84
|
+
response = self.client.chat.completions.create(
|
85
|
+
model=self.model_name,
|
86
|
+
messages=messages
|
87
|
+
)
|
88
|
+
return response.choices[0].message.content
|
89
|
+
|
90
|
+
def run(self, user_query, max_iterations=5):
|
91
|
+
"""Run the agent with the given user query."""
|
92
|
+
context = []
|
93
|
+
for _ in range(max_iterations):
|
94
|
+
messages = [
|
95
|
+
{"role": "system", "content": self.system_prompt.format(query=user_query)},
|
96
|
+
{"role": "user", "content": user_query},
|
97
|
+
*context
|
98
|
+
]
|
99
|
+
self.logger.info(f"Messages: {messages}")
|
100
|
+
response = self.get_model_response(messages)
|
101
|
+
self.logger.info(f"Model response: {response}")
|
102
|
+
thoughts, actions = parse_response(response)
|
103
|
+
if not actions:
|
104
|
+
break
|
105
|
+
action_str = actions[0]
|
106
|
+
self.logger.info(f"Executing action: {action_str}")
|
107
|
+
action_result = self.execute_action(action_str)
|
108
|
+
if action_result.startswith("Action"):
|
109
|
+
action_result = action_result.split("Result: ")[-1]
|
110
|
+
self.logger.info(f"Action result: {action_result}")
|
111
|
+
context.append({
|
112
|
+
"role": "assistant",
|
113
|
+
"content": f"Thought: {thoughts}\nAction: {action_str}\nResult: {action_result}"
|
114
|
+
})
|
115
|
+
return response
|
116
|
+
|
117
|
+
def execute_action(self, action_str):
|
118
|
+
"""Execute an action based on the action string."""
|
119
|
+
action_name, params = parse_action(action_str)
|
120
|
+
if action_name in self.action_registry:
|
121
|
+
try:
|
122
|
+
self.logger.debug(f"Executing action: {action_name} with params: {params}")
|
123
|
+
result = self.action_registry[action_name](params)
|
124
|
+
self.logger.debug(f"Action '{action_name}' executed successfully, Result: {result}")
|
125
|
+
return f"Action '{action_name}' executed successfully, Result: {result}"
|
126
|
+
except Exception as e:
|
127
|
+
self.logger.warning(f"Action '{action_name}' failed, Error: {str(e)}")
|
128
|
+
return f"Action '{action_name}' failed, Error: {str(e)}"
|
129
|
+
else:
|
130
|
+
return f"Unknown action '{action_name}'"
|
131
|
+
|
132
|
+
|
133
|
+
if __name__ == '__main__':
|
134
|
+
@register_action("calculate")
|
135
|
+
def calculate(expression=""):
|
136
|
+
"""Calculate the result of a mathematical expression."""
|
137
|
+
try:
|
138
|
+
result = eval(expression)
|
139
|
+
return result
|
140
|
+
except Exception as e:
|
141
|
+
return f"Error in calculation: {str(e)}"
|
142
|
+
|
143
|
+
|
144
|
+
@register_action("reverse_string")
|
145
|
+
def reverse_string(s=""):
|
146
|
+
"""Reverse the input string."""
|
147
|
+
try:
|
148
|
+
logger.debug(f"Reversing string: {s}")
|
149
|
+
r = s[::-1]
|
150
|
+
logger.debug(f"Reversed string: {r}")
|
151
|
+
return r
|
152
|
+
except Exception as e:
|
153
|
+
return f"Error in reversing string: {str(e)}"
|
154
|
+
|
155
|
+
|
156
|
+
@register_action("text_length")
|
157
|
+
def text_length(s):
|
158
|
+
"""Calculate the length of the input text string."""
|
159
|
+
try:
|
160
|
+
logger.debug(f"Calculating text length: {s}")
|
161
|
+
r = len(s)
|
162
|
+
logger.debug(f"Text length: {r}")
|
163
|
+
return r
|
164
|
+
except Exception as e:
|
165
|
+
return f"Error in calculating text length: {str(e)}"
|
166
|
+
|
167
|
+
|
168
|
+
tools = [
|
169
|
+
{
|
170
|
+
"name_for_model": "calculate",
|
171
|
+
"name_for_human": "Calculator",
|
172
|
+
"description_for_model": "useful for performing mathematical calculations.",
|
173
|
+
"parameters": "expression: a mathematical expression to evaluate."
|
174
|
+
},
|
175
|
+
{
|
176
|
+
"name_for_model": "reverse_string",
|
177
|
+
"name_for_human": "String Reverser",
|
178
|
+
"description_for_model": "useful for reversing strings.",
|
179
|
+
"parameters": "the string to reverse."
|
180
|
+
},
|
181
|
+
# get text string length
|
182
|
+
{
|
183
|
+
"name_for_model": "text_length",
|
184
|
+
"name_for_human": "Text Length Calculator",
|
185
|
+
"description_for_model": "useful for calculating the length of a text string.",
|
186
|
+
"parameters": "the text string to calculate the length."
|
187
|
+
}
|
188
|
+
]
|
189
|
+
|
190
|
+
agent = ReactAgent(tools=tools)
|
191
|
+
|
192
|
+
# Run the agent with a query that requires both tools
|
193
|
+
response = agent.run(
|
194
|
+
"What is the result of reversing the string '123hello111---232323k23你好,水电费不着调。。。。--23' and then calculating the length of the reversed string, 不要包括引号")
|
195
|
+
logger.info(response)
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
@author:XuMing(xuming624@qq.com)
|
4
|
+
@description:
|
5
|
+
CogVideoX
|
6
|
+
模型编码:cogvideox、cogvideox-flash
|
7
|
+
|
8
|
+
CogVideoX 是由智谱AI开发的视频生成大模型,具备强大的视频生成能力,只需输入文本或图片就可以轻松完成视频制作。
|
9
|
+
"""
|
10
|
+
import hashlib
|
11
|
+
import json
|
12
|
+
import os
|
13
|
+
from os import getenv
|
14
|
+
import time
|
15
|
+
import requests
|
16
|
+
from typing import Optional
|
17
|
+
|
18
|
+
try:
|
19
|
+
from zhipuai import ZhipuAI
|
20
|
+
except ImportError:
|
21
|
+
raise ImportError("`zhipuai` not installed. Please install using `pip install zhipuai`.")
|
22
|
+
|
23
|
+
from agentica.tools.base import Toolkit
|
24
|
+
from agentica.utils.log import logger
|
25
|
+
|
26
|
+
|
27
|
+
class CogVideoTool(Toolkit):
|
28
|
+
"""
|
29
|
+
This class inherits from the Toolkit class.
|
30
|
+
It defines a function for creating an image from a description using ZhipuAI's API.
|
31
|
+
"""
|
32
|
+
|
33
|
+
def __init__(
|
34
|
+
self,
|
35
|
+
api_key: Optional[str] = None,
|
36
|
+
data_dir: Optional[str] = None,
|
37
|
+
|
38
|
+
):
|
39
|
+
super().__init__(name="create_video_from_cogvideo_tool")
|
40
|
+
self.api_key = api_key or getenv("ZHIPUAI_API_KEY")
|
41
|
+
if not self.api_key:
|
42
|
+
logger.error("ZHIPUAI_API_KEY not set. Please set the ZHIPUAI_API_KEY environment variable.")
|
43
|
+
self.client = ZhipuAI(api_key=self.api_key)
|
44
|
+
self.data_dir: str = data_dir or "outputs"
|
45
|
+
self.register(self.create_video)
|
46
|
+
|
47
|
+
def _generate_name(self, prompt: Optional[str] = None) -> str:
|
48
|
+
"""
|
49
|
+
Generates a unique name based on the prompt and the current time.
|
50
|
+
|
51
|
+
:param prompt: The prompt that describes the video.
|
52
|
+
:type prompt: str
|
53
|
+
:return: The name of the video file.
|
54
|
+
:rtype: str
|
55
|
+
"""
|
56
|
+
timestamp = str(time.time())
|
57
|
+
prompt = prompt if prompt else ""
|
58
|
+
file_name = str(hashlib.sha256((prompt + timestamp).encode()).hexdigest())[:16]
|
59
|
+
return file_name + ".mp4"
|
60
|
+
|
61
|
+
def create_video(
|
62
|
+
self,
|
63
|
+
prompt: Optional[str] = None,
|
64
|
+
image_url: Optional[str] = None,
|
65
|
+
model: str = "cogvideox-flash",
|
66
|
+
with_audio: bool = False,
|
67
|
+
size: Optional[str] = None,
|
68
|
+
duration: int = 5,
|
69
|
+
fps: int = 30
|
70
|
+
) -> str:
|
71
|
+
"""Creates a video from a description or image using ZhipuAI API, generates a unique video name based on the prompt or image URL,
|
72
|
+
and saves it to a specified output path.
|
73
|
+
|
74
|
+
Args:
|
75
|
+
prompt (str, optional): The prompt that describes the video.
|
76
|
+
image_url (str, optional): The URL of the image to base the video on.
|
77
|
+
model (str, optional): The model to use for video generation. Defaults to 'cogvideox'.
|
78
|
+
with_audio (bool, optional): Whether to generate AI audio. Defaults to False.
|
79
|
+
size (str, optional): The size of the video. Defaults to '1920x1080'.
|
80
|
+
duration (int, optional): The duration of the video in seconds. Defaults to 5.
|
81
|
+
fps (int, optional): The frame rate of the video. Defaults to 30.
|
82
|
+
|
83
|
+
Example:
|
84
|
+
from agentica.tools.cogvideo_tool import CogVideoTool
|
85
|
+
tool = CogVideoTool()
|
86
|
+
image_path = tool.create_video("A painting of a beautiful sunset over the ocean.")
|
87
|
+
print(image_path)
|
88
|
+
|
89
|
+
Returns:
|
90
|
+
str: The json result for the video generation.
|
91
|
+
"""
|
92
|
+
params = {"model": model}
|
93
|
+
if prompt:
|
94
|
+
params["prompt"] = prompt
|
95
|
+
if image_url:
|
96
|
+
params["image_url"] = image_url
|
97
|
+
if size:
|
98
|
+
params["size"] = size
|
99
|
+
if with_audio:
|
100
|
+
params["with_audio"] = with_audio
|
101
|
+
if duration:
|
102
|
+
params["duration"] = duration
|
103
|
+
if fps:
|
104
|
+
params["fps"] = fps
|
105
|
+
logger.info(f"params: {params}")
|
106
|
+
response = self.client.videos.generations(**params)
|
107
|
+
# 异步接口,轮询获取视频生成结果
|
108
|
+
video_id = response.id
|
109
|
+
while True:
|
110
|
+
result = self.client.videos.retrieve_videos_result(id=video_id)
|
111
|
+
if result.task_status == "SUCCESS":
|
112
|
+
logger.info("Video generation succeeded. URL:", result)
|
113
|
+
break
|
114
|
+
elif result.task_status == "FAIL":
|
115
|
+
logger.debug("Video generation failed.")
|
116
|
+
break
|
117
|
+
elif result.task_status == "PROCESSING":
|
118
|
+
logger.debug("Video generation in progress. Checking again in 10 seconds...")
|
119
|
+
time.sleep(10)
|
120
|
+
video_url = result.video_result[0].url
|
121
|
+
cover_image_url = result.video_result[0].cover_image_url
|
122
|
+
video_path = f"{self.data_dir}/{self._generate_name(prompt)}"
|
123
|
+
self._download_and_save_video(video_url, video_path)
|
124
|
+
saved_video_path = os.path.abspath(video_path)
|
125
|
+
result = {"action": "create_video", "result_video_url": video_url, "result_video_path": saved_video_path,
|
126
|
+
"cover_image_url": cover_image_url}
|
127
|
+
return json.dumps(result, ensure_ascii=False)
|
128
|
+
|
129
|
+
def _download_and_save_video(self, video_url: str, saved_video_path: str) -> None:
|
130
|
+
"""
|
131
|
+
Downloads the video from the given URL and saves it to the specified path.
|
132
|
+
|
133
|
+
:param video_url: The URL of the video.
|
134
|
+
:type video_url: str
|
135
|
+
:param saved_video_path: The path to save the video.
|
136
|
+
:type saved_video_path: str
|
137
|
+
"""
|
138
|
+
try:
|
139
|
+
video_data = requests.get(video_url).content
|
140
|
+
os.makedirs(os.path.dirname(saved_video_path), exist_ok=True)
|
141
|
+
with open(saved_video_path, "wb") as f:
|
142
|
+
f.write(video_data)
|
143
|
+
logger.info(f"Video saved to: {saved_video_path}")
|
144
|
+
except Exception as e:
|
145
|
+
logger.error(f"Error downloading video: {str(e)}")
|
146
|
+
|
147
|
+
|
148
|
+
if __name__ == '__main__':
|
149
|
+
# from agentica.tools.cogview_tool import CogViewTool
|
150
|
+
m = CogVideoTool()
|
151
|
+
prompt = "比得兔开小汽车,游走在马路上,脸上的表情充满开心喜悦"
|
152
|
+
r = m.create_video(prompt)
|
153
|
+
print(r)
|