Skip to content

Commit

Permalink
deploy: 9d4a1bb
Browse files Browse the repository at this point in the history
  • Loading branch information
DavdGao committed May 11, 2024
1 parent ffc49e2 commit 25059bb
Show file tree
Hide file tree
Showing 22 changed files with 340 additions and 105 deletions.
Binary file modified en/.doctrees/agentscope.models.doctree
Binary file not shown.
Binary file modified en/.doctrees/agentscope.models.ollama_model.doctree
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/206-prompt.doctree
Binary file not shown.
123 changes: 90 additions & 33 deletions en/_modules/agentscope/models/ollama_model.html

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions en/_sources/tutorial/206-prompt.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ messages as input. The message must obey the following rules (updated in

#### Prompt Strategy

Given a list of messages, we will parse each message as follows:

- `Msg`: Fill the `role` and `content` fields directly. If it has an `url`
field, which refers to an image, we will add it to the message.
- `List`: Parse each element in the list according to the above rules.
- If the role field of the first input message is `"system"`,
it will be treated as system prompt and the other messages will consist
dialogue history in the system message prefixed by "## Dialogue History".
- If the `url` attribute of messages is not `None`, we will gather all urls in
the `"images"` field in the returned dictionary.

```python
from agentscope.models import OllamaChatWrapper
Expand All @@ -268,9 +268,11 @@ print(prompt)

```bash
[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "assistant", "content": "Hi."},
{"role": "assistant", "content": "Nice to meet you!", "images": ["https://example.com/image.jpg"]},
{
"role": "system",
"content": "You are a helpful assistant\n\n## Dialogue History\nBob: Hi.\nAlice: Nice to meet you!",
"images": ["https://example.com/image.jpg"]
},
]
```

Expand Down
33 changes: 30 additions & 3 deletions en/agentscope.models.html
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,36 @@
<dl class="py method">
<dt class="sig sig-object py" id="agentscope.models.OllamaChatWrapper.format">
<span class="sig-name descname"><span class="pre">format</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="agentscope.message.html#agentscope.message.MessageBase" title="agentscope.message.MessageBase"><span class="pre">MessageBase</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">Sequence</span><span class="p"><span class="pre">[</span></span><a class="reference internal" href="agentscope.message.html#agentscope.message.MessageBase" title="agentscope.message.MessageBase"><span class="pre">MessageBase</span></a><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">List</span><span class="p"><span class="pre">[</span></span><span class="pre">dict</span><span class="p"><span class="pre">]</span></span></span></span><a class="reference internal" href="_modules/agentscope/models/ollama_model.html#OllamaChatWrapper.format"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#agentscope.models.OllamaChatWrapper.format" title="Link to this definition"></a></dt>
<dd><p>A basic strategy to format the input into the required format of
Ollama Chat API.</p>
<p>Note for ollama chat api, the content field shouldn’t be empty string.</p>
<dd><p>Format the messages for ollama Chat API.</p>
<p>All messages will be formatted into a single system message with
system prompt and dialogue history.</p>
<p>Note:
1. This strategy maybe not suitable for all scenarios,
and developers are encouraged to implement their own prompt
engineering strategies.
2. For ollama chat api, the content field shouldn’t be empty string.</p>
<p>Example:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">prompt</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
<span class="n">Msg</span><span class="p">(</span><span class="s2">&quot;system&quot;</span><span class="p">,</span> <span class="s2">&quot;You&#39;re a helpful assistant&quot;</span><span class="p">,</span> <span class="n">role</span><span class="o">=</span><span class="s2">&quot;system&quot;</span><span class="p">),</span>
<span class="n">Msg</span><span class="p">(</span><span class="s2">&quot;Bob&quot;</span><span class="p">,</span> <span class="s2">&quot;Hi, how can I help you?&quot;</span><span class="p">,</span> <span class="n">role</span><span class="o">=</span><span class="s2">&quot;assistant&quot;</span><span class="p">),</span>
<span class="n">Msg</span><span class="p">(</span><span class="s2">&quot;user&quot;</span><span class="p">,</span> <span class="s2">&quot;What&#39;s the date today?&quot;</span><span class="p">,</span> <span class="n">role</span><span class="o">=</span><span class="s2">&quot;user&quot;</span><span class="p">)</span>
<span class="p">)</span>
</pre></div>
</div>
<p>The prompt will be as follows:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
<span class="p">{</span>
<span class="s2">&quot;role&quot;</span><span class="p">:</span> <span class="s2">&quot;user&quot;</span><span class="p">,</span>
<span class="s2">&quot;content&quot;</span><span class="p">:</span> <span class="p">(</span>
<span class="s2">&quot;You&#39;re a helpful assistant</span><span class="se">\n\n</span><span class="s2">&quot;</span>
<span class="s2">&quot;## Dialogue History</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="s2">&quot;Bob: Hi, how can I help you?</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="s2">&quot;user: What&#39;s the date today?&quot;</span>
<span class="p">)</span>
<span class="p">}</span>
<span class="p">]</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>args</strong> (<cite>Union[MessageBase, Sequence[MessageBase]]</cite>) – The input arguments to be formatted, where each argument
Expand Down
33 changes: 30 additions & 3 deletions en/agentscope.models.ollama_model.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,36 @@
<dl class="py method">
<dt class="sig sig-object py" id="agentscope.models.ollama_model.OllamaChatWrapper.format">
<span class="sig-name descname"><span class="pre">format</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="agentscope.message.html#agentscope.message.MessageBase" title="agentscope.message.MessageBase"><span class="pre">MessageBase</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">Sequence</span><span class="p"><span class="pre">[</span></span><a class="reference internal" href="agentscope.message.html#agentscope.message.MessageBase" title="agentscope.message.MessageBase"><span class="pre">MessageBase</span></a><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">List</span><span class="p"><span class="pre">[</span></span><span class="pre">dict</span><span class="p"><span class="pre">]</span></span></span></span><a class="reference internal" href="_modules/agentscope/models/ollama_model.html#OllamaChatWrapper.format"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#agentscope.models.ollama_model.OllamaChatWrapper.format" title="Link to this definition"></a></dt>
<dd><p>A basic strategy to format the input into the required format of
Ollama Chat API.</p>
<p>Note for ollama chat api, the content field shouldn’t be empty string.</p>
<dd><p>Format the messages for ollama Chat API.</p>
<p>All messages will be formatted into a single system message with
system prompt and dialogue history.</p>
<p>Note:
1. This strategy maybe not suitable for all scenarios,
and developers are encouraged to implement their own prompt
engineering strategies.
2. For ollama chat api, the content field shouldn’t be empty string.</p>
<p>Example:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">prompt</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
<span class="n">Msg</span><span class="p">(</span><span class="s2">&quot;system&quot;</span><span class="p">,</span> <span class="s2">&quot;You&#39;re a helpful assistant&quot;</span><span class="p">,</span> <span class="n">role</span><span class="o">=</span><span class="s2">&quot;system&quot;</span><span class="p">),</span>
<span class="n">Msg</span><span class="p">(</span><span class="s2">&quot;Bob&quot;</span><span class="p">,</span> <span class="s2">&quot;Hi, how can I help you?&quot;</span><span class="p">,</span> <span class="n">role</span><span class="o">=</span><span class="s2">&quot;assistant&quot;</span><span class="p">),</span>
<span class="n">Msg</span><span class="p">(</span><span class="s2">&quot;user&quot;</span><span class="p">,</span> <span class="s2">&quot;What&#39;s the date today?&quot;</span><span class="p">,</span> <span class="n">role</span><span class="o">=</span><span class="s2">&quot;user&quot;</span><span class="p">)</span>
<span class="p">)</span>
</pre></div>
</div>
<p>The prompt will be as follows:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
<span class="p">{</span>
<span class="s2">&quot;role&quot;</span><span class="p">:</span> <span class="s2">&quot;user&quot;</span><span class="p">,</span>
<span class="s2">&quot;content&quot;</span><span class="p">:</span> <span class="p">(</span>
<span class="s2">&quot;You&#39;re a helpful assistant</span><span class="se">\n\n</span><span class="s2">&quot;</span>
<span class="s2">&quot;## Dialogue History</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="s2">&quot;Bob: Hi, how can I help you?</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="s2">&quot;user: What&#39;s the date today?&quot;</span>
<span class="p">)</span>
<span class="p">}</span>
<span class="p">]</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>args</strong> (<cite>Union[MessageBase, Sequence[MessageBase]]</cite>) – The input arguments to be formatted, where each argument
Expand Down
2 changes: 1 addition & 1 deletion en/searchindex.js

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions en/tutorial/206-prompt.html
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,12 @@ <h3>OllamaChatWrapper<a class="headerlink" href="#ollamachatwrapper" title="Link
</ul>
<section id="id3">
<h4>Prompt Strategy<a class="headerlink" href="#id3" title="Link to this heading"></a></h4>
<p>Given a list of messages, we will parse each message as follows:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">Msg</span></code>: Fill the <code class="docutils literal notranslate"><span class="pre">role</span></code> and <code class="docutils literal notranslate"><span class="pre">content</span></code> fields directly. If it has an <code class="docutils literal notranslate"><span class="pre">url</span></code>
field, which refers to an image, we will add it to the message.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">List</span></code>: Parse each element in the list according to the above rules.</p></li>
<li><p>If the role field of the first input message is <code class="docutils literal notranslate"><span class="pre">&quot;system&quot;</span></code>,
it will be treated as system prompt and the other messages will consist
dialogue history in the system message prefixed by “## Dialogue History”.</p></li>
<li><p>If the <code class="docutils literal notranslate"><span class="pre">url</span></code> attribute of messages is not <code class="docutils literal notranslate"><span class="pre">None</span></code>, we will gather all urls in
the <code class="docutils literal notranslate"><span class="pre">&quot;images&quot;</span></code> field in the returned dictionary.</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">agentscope.models</span> <span class="kn">import</span> <span class="n">OllamaChatWrapper</span>

Expand All @@ -371,9 +372,11 @@ <h4>Prompt Strategy<a class="headerlink" href="#id3" title="Link to this heading
</pre></div>
</div>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">[</span>
<span class="w"> </span><span class="o">{</span><span class="s2">&quot;role&quot;</span>:<span class="w"> </span><span class="s2">&quot;system&quot;</span>,<span class="w"> </span><span class="s2">&quot;content&quot;</span>:<span class="w"> </span><span class="s2">&quot;You are a helpful assistant&quot;</span><span class="o">}</span>,
<span class="w"> </span><span class="o">{</span><span class="s2">&quot;role&quot;</span>:<span class="w"> </span><span class="s2">&quot;assistant&quot;</span>,<span class="w"> </span><span class="s2">&quot;content&quot;</span>:<span class="w"> </span><span class="s2">&quot;Hi.&quot;</span><span class="o">}</span>,
<span class="w"> </span><span class="o">{</span><span class="s2">&quot;role&quot;</span>:<span class="w"> </span><span class="s2">&quot;assistant&quot;</span>,<span class="w"> </span><span class="s2">&quot;content&quot;</span>:<span class="w"> </span><span class="s2">&quot;Nice to meet you!&quot;</span>,<span class="w"> </span><span class="s2">&quot;images&quot;</span>:<span class="w"> </span><span class="o">[</span><span class="s2">&quot;https://example.com/image.jpg&quot;</span><span class="o">]}</span>,
<span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="s2">&quot;role&quot;</span>:<span class="w"> </span><span class="s2">&quot;system&quot;</span>,
<span class="w"> </span><span class="s2">&quot;content&quot;</span>:<span class="w"> </span><span class="s2">&quot;You are a helpful assistant\n\n## Dialogue History\nBob: Hi.\nAlice: Nice to meet you!&quot;</span>,
<span class="w"> </span><span class="s2">&quot;images&quot;</span>:<span class="w"> </span><span class="o">[</span><span class="s2">&quot;https://example.com/image.jpg&quot;</span><span class="o">]</span>
<span class="w"> </span><span class="o">}</span>,
<span class="o">]</span>
</pre></div>
</div>
Expand Down
Binary file modified zh_CN/.doctrees/agentscope.models.doctree
Binary file not shown.
Binary file modified zh_CN/.doctrees/agentscope.models.ollama_model.doctree
Binary file not shown.
Binary file modified zh_CN/.doctrees/environment.pickle
Binary file not shown.
Binary file modified zh_CN/.doctrees/index.doctree
Binary file not shown.
Binary file modified zh_CN/.doctrees/tutorial/206-prompt.doctree
Binary file not shown.
Loading

0 comments on commit 25059bb

Please sign in to comment.