Skip to content

Commit

Permalink
deploy: be8db4c
Browse files Browse the repository at this point in the history
  • Loading branch information
DavdGao committed May 6, 2024
1 parent e639a44 commit 6f887d8
Show file tree
Hide file tree
Showing 40 changed files with 2,128 additions and 23 deletions.
Binary file modified en/.doctrees/agentscope.models.doctree
Binary file not shown.
Binary file not shown.
Binary file modified en/.doctrees/environment.pickle
Binary file not shown.
Binary file modified en/.doctrees/index.doctree
Binary file not shown.
Binary file modified en/.doctrees/tutorial/203-model.doctree
Binary file not shown.
Binary file modified en/.doctrees/tutorial/206-prompt.doctree
Binary file not shown.
6 changes: 6 additions & 0 deletions en/_modules/agentscope/models.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ <h1>Source code for agentscope.models</h1><div class="highlight"><pre>
<span class="n">GeminiChatWrapper</span><span class="p">,</span>
<span class="n">GeminiEmbeddingWrapper</span><span class="p">,</span>
<span class="p">)</span>
<span class="kn">from</span> <span class="nn">.zhipu_model</span> <span class="kn">import</span> <span class="p">(</span>
<span class="n">ZhipuAIChatWrapper</span><span class="p">,</span>
<span class="n">ZhipuAIEmbeddingWrapper</span><span class="p">,</span>
<span class="p">)</span>


<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span>
Expand All @@ -152,6 +156,8 @@ <h1>Source code for agentscope.models</h1><div class="highlight"><pre>
<span class="s2">&quot;OllamaGenerationWrapper&quot;</span><span class="p">,</span>
<span class="s2">&quot;GeminiChatWrapper&quot;</span><span class="p">,</span>
<span class="s2">&quot;GeminiEmbeddingWrapper&quot;</span><span class="p">,</span>
<span class="s2">&quot;ZhipuAIChatWrapper&quot;</span><span class="p">,</span>
<span class="s2">&quot;ZhipuAIEmbeddingWrapper&quot;</span><span class="p">,</span>
<span class="s2">&quot;load_model_by_config_name&quot;</span><span class="p">,</span>
<span class="s2">&quot;read_model_configs&quot;</span><span class="p">,</span>
<span class="s2">&quot;clear_model_configs&quot;</span><span class="p">,</span>
Expand Down
498 changes: 498 additions & 0 deletions en/_modules/agentscope/models/zhipu_model.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions en/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ <h1>All modules for which code is available</h1>
<li><a href="agentscope/models/openai_model.html">agentscope.models.openai_model</a></li>
<li><a href="agentscope/models/post_model.html">agentscope.models.post_model</a></li>
<li><a href="agentscope/models/response.html">agentscope.models.response</a></li>
<li><a href="agentscope/models/zhipu_model.html">agentscope.models.zhipu_model</a></li>
</ul><li><a href="agentscope/msghub.html">agentscope.msghub</a></li>
<li><a href="agentscope/parsers/code_block_parser.html">agentscope.parsers.code_block_parser</a></li>
<li><a href="agentscope/parsers/json_object_parser.html">agentscope.parsers.json_object_parser</a></li>
Expand Down
6 changes: 6 additions & 0 deletions en/_sources/agentscope.models.zhipu_model.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
agentscope.models.zhipu_model
=============================
.. automodule:: agentscope.models.zhipu_model
:members:
:undoc-members:
:show-inheritance:
45 changes: 45 additions & 0 deletions en/_sources/tutorial/203-model.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Currently, AgentScope supports the following model service APIs:
- OpenAI API, including chat, image generation (DALL-E), and Embedding.
- DashScope API, including chat, image sythesis and text embedding.
- Gemini API, including chat and embedding.
- ZhipuAI API, including chat and embedding.
- Ollama API, including chat, embedding and generation.
- Post Request API, model inference services based on Post
requests, including Huggingface/ModelScope Inference API and various
Expand Down Expand Up @@ -81,6 +82,8 @@ In the current AgentScope, the supported `model_type` types, the corresponding
| | Multimodal | [`DashScopeMultiModalWrapper`](https://github.com/modelscope/agentscope/blob/main/src/agentscope/models/dashscope_model.py) | `"dashscope_multimodal"` | qwen-vl-plus, qwen-vl-max, qwen-audio-turbo, ... |
| Gemini API | Chat | [`GeminiChatWrapper`](https://github.com/modelscope/agentscope/blob/main/src/agentscope/models/gemini_model.py) | `"gemini_chat"` | gemini-pro, ... |
| | Embedding | [`GeminiEmbeddingWrapper`](https://github.com/modelscope/agentscope/blob/main/src/agentscope/models/gemini_model.py) | `"gemini_embedding"` | models/embedding-001, ... |
| ZhipuAI API | Chat | [`ZhipuAIChatWrapper`](https://github.com/modelscope/agentscope/blob/main/src/agentscope/models/zhipu_model.py) | `"zhipuai_chat"` | glm4, ... |
| | Embedding | [`ZhipuAIEmbeddingWrapper`](https://github.com/modelscope/agentscope/blob/main/src/agentscope/models/zhipu_model.py) | `"zhipuai_embedding"` | embedding-2, ... |
| ollama | Chat | [`OllamaChatWrapper`](https://github.com/modelscope/agentscope/blob/main/src/agentscope/models/ollama_model.py) | `"ollama_chat"` | llama2, ... |
| | Embedding | [`OllamaEmbeddingWrapper`](https://github.com/modelscope/agentscope/blob/main/src/agentscope/models/ollama_model.py) | `"ollama_embedding"` | llama2, ... |
| | Generation | [`OllamaGenerationWrapper`](https://github.com/modelscope/agentscope/blob/main/src/agentscope/models/ollama_model.py) | `"ollama_generate"` | llama2, ... |
Expand Down Expand Up @@ -303,6 +306,48 @@ Here we provide example configurations for different model wrappers.

<br/>


#### ZhipuAI API

<details>
<summary>ZhipuAI Chat API (<code><a href="https://github.com/modelscope/agentscope/blob/main/src/agentscope/models/zhipu_model.py">agentscope.models.ZhipuAIChatWrapper</a></code>)</summary>

```python
{
"config_name": "my_zhipuai_chat_config",
"model_type": "zhipuai_chat",

# Required parameters
"model_name": "{model_name}", # The model name in ZhipuAI API, e.g. glm-4

# Optional parameters
"api_key": "{your_api_key}"
}
```

</details>

<details>
<summary>ZhipuAI Embedding API (<code><a href="https://github.com/modelscope/agentscope/blob/main/src/agentscope/models/zhipu_model.py">agentscope.models.ZhipuAIEmbeddingWrapper</a></code>)</summary>

```python
{
"config_name": "my_zhipuai_embedding_config",
"model_type": "zhipuai_embedding",

# Required parameters
"model_name": "{model_name}", # The model name in ZhipuAI API, e.g. embedding-2

# Optional parameters
"api_key": "{your_api_key}",
}
```

</details>

<br/>


#### Ollama API

<details>
Expand Down
42 changes: 42 additions & 0 deletions en/_sources/tutorial/206-prompt.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ generation model APIs.
- [OllamaChatWrapper](#ollamachatwrapper)
- [OllamaGenerationWrapper](#ollamagenerationwrapper)
- [GeminiChatWrapper](#geminichatwrapper)
- [ZhipuAIChatWrapper](#zhipuaichatwrapper)

These strategies are implemented in the `format` functions of the model
wrapper classes.
Expand Down Expand Up @@ -365,6 +366,47 @@ print(prompt)
]
```

### `ZhipuAIChatWrapper`

`ZhipuAIChatWrapper` encapsulates the ZhipuAI chat API, which takes a list of messages as input. The message must obey the following rules:

- Require `role` and `content` fields, and `role` must be either `"user"`
`"system"` or `"assistant"`.
- There must be at least one `user` message.

#### Prompt Strategy

If the role field of the first message is `"system"`, it will be converted into a single message with the `role` field as `"system"` and the `content` field as the system message. The rest of the messages will be converted into a message with the `role` field as `"user"` and the `content` field as the dialogue history.

An example is shown below:

```python
from agentscope.models import ZhipuAIChatWrapper
from agentscope.message import Msg

model = ZhipuAIChatWrapper(
config_name="", # empty since we directly initialize the model wrapper
model_name="glm-4",
api_key="your api key",
)

prompt = model.format(
Msg("system", "You're a helpful assistant", role="system"), # Msg object
[ # a list of Msg objects
Msg(name="Bob", content="Hi!", role="assistant"),
Msg(name="Alice", content="Nice to meet you!", role="assistant"),
],
)
print(prompt)
```

```bash
[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": "## Dialogue History\nBob: Hi!\nAlice: Nice to meet you!"},
]
```

## Prompt Engine (Will be deprecated in the future)

AgentScope provides the `PromptEngine` class to simplify the process of crafting
Expand Down
Loading

0 comments on commit 6f887d8

Please sign in to comment.