Skip to content

Commit

Permalink
Onboard a custom prompt for GPT model
Browse files Browse the repository at this point in the history
Create a backup option for custom prompt
Remove debug steps
  • Loading branch information
dormant-user committed Jun 1, 2024
1 parent ea5455c commit 72b9e91
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 77 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Licensed under the [MIT License][license]
[label-python]: https://img.shields.io/badge/Made%20with-Python-blue?style=for-the-badge&logo=Python
[label-pyversion]: https://img.shields.io/badge/python-3.10%20%7C%203.11-orange
[label-pypi-downloads]: https://img.shields.io/pypi/dm/jarvis-ironman
[label-platform]: https://img.shields.io/badge/Platform-Linux|MacOS|Windows-1f425f.svg
[label-platform]: https://img.shields.io/badge/Platform-Linux|macOS|Windows-1f425f.svg

[label-language-ct]: https://img.shields.io/github/languages/count/thevickypedia/Jarvis
[label-code-coverage]: https://img.shields.io/github/languages/top/thevickypedia/Jarvis
Expand Down
2 changes: 1 addition & 1 deletion docs/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h2 align="center">Voice-Activated Natural Language UI</h2><p><a class="referenc
<p><img alt="Python" src="https://img.shields.io/badge/python-3.10%20%7C%203.11-orange" />
<img alt="Pypi-downloads" src="https://img.shields.io/pypi/dm/jarvis-ironman" /></p>
<p><strong>Platform Supported</strong></p>
<p><img alt="Platform" src="https://img.shields.io/badge/Platform-Linux%7CMacOS%7CWindows-1f425f.svg" /></p>
<p><img alt="Platform" src="https://img.shields.io/badge/Platform-Linux%7CmacOS%7CWindows-1f425f.svg" /></p>
<p><strong>Language Stats</strong></p>
<p><img alt="Language count" src="https://img.shields.io/github/languages/count/thevickypedia/Jarvis" />
<img alt="Code coverage" src="https://img.shields.io/github/languages/top/thevickypedia/Jarvis" /></p>
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Licensed under the [MIT License][license]
[label-python]: https://img.shields.io/badge/Made%20with-Python-blue?style=for-the-badge&logo=Python
[label-pyversion]: https://img.shields.io/badge/python-3.10%20%7C%203.11-orange
[label-pypi-downloads]: https://img.shields.io/pypi/dm/jarvis-ironman
[label-platform]: https://img.shields.io/badge/Platform-Linux|MacOS|Windows-1f425f.svg
[label-platform]: https://img.shields.io/badge/Platform-Linux|macOS|Windows-1f425f.svg

[label-language-ct]: https://img.shields.io/github/languages/count/thevickypedia/Jarvis
[label-code-coverage]: https://img.shields.io/github/languages/top/thevickypedia/Jarvis
Expand Down
2 changes: 1 addition & 1 deletion docs/_sources/README.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Licensed under the [MIT License][license]
[label-python]: https://img.shields.io/badge/Made%20with-Python-blue?style=for-the-badge&logo=Python
[label-pyversion]: https://img.shields.io/badge/python-3.10%20%7C%203.11-orange
[label-pypi-downloads]: https://img.shields.io/pypi/dm/jarvis-ironman
[label-platform]: https://img.shields.io/badge/Platform-Linux|MacOS|Windows-1f425f.svg
[label-platform]: https://img.shields.io/badge/Platform-Linux|macOS|Windows-1f425f.svg

[label-language-ct]: https://img.shields.io/github/languages/count/thevickypedia/Jarvis
[label-code-coverage]: https://img.shields.io/github/languages/top/thevickypedia/Jarvis
Expand Down
18 changes: 14 additions & 4 deletions docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,12 @@ <h2 id="C">C</h2>
</li>
<li><a href="index.html#jarvis.api.triggers.stock_monitor.StockMonitor.closest_maximum">closest_maximum() (jarvis.api.triggers.stock_monitor.StockMonitor static method)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#jarvis.api.triggers.stock_monitor.StockMonitor.closest_minimum">closest_minimum() (jarvis.api.triggers.stock_monitor.StockMonitor static method)</a>
</li>
<li><a href="index.html#jarvis.modules.models.classes.Indicators.coin">coin (jarvis.modules.models.classes.Indicators attribute)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#jarvis.modules.utils.util.comma_separator">comma_separator() (in module jarvis.modules.utils.util)</a>
</li>
<li><a href="index.html#jarvis.api.models.modals.OfflineCommunicatorModal.command">command (jarvis.api.models.modals.OfflineCommunicatorModal attribute)</a>
Expand Down Expand Up @@ -444,6 +444,12 @@ <h2 id="C">C</h2>
<li><a href="index.html#jarvis.modules.logger.custom_handler">custom_handler() (in module jarvis.modules.logger)</a>
</li>
<li><a href="index.html#jarvis.modules.meetings.ics_meetings.custom_meetings">custom_meetings() (in module jarvis.modules.meetings.ics_meetings)</a>
</li>
<li><a href="index.html#jarvis.modules.transformer.gpt.Customizer.customize_model_cli">customize_model_cli() (jarvis.modules.transformer.gpt.Customizer method)</a>
</li>
<li><a href="index.html#jarvis.modules.transformer.gpt.Customizer.customize_model_sdk">customize_model_sdk() (jarvis.modules.transformer.gpt.Customizer method)</a>
</li>
<li><a href="index.html#jarvis.modules.transformer.gpt.Customizer">Customizer (class in jarvis.modules.transformer.gpt)</a>
</li>
</ul></td>
</tr></table>
Expand Down Expand Up @@ -2715,10 +2721,10 @@ <h2 id="R">R</h2>
</li>
<li><a href="index.html#jarvis.api.squire.timeout_otp.reset_stock_monitor">reset_stock_monitor() (in module jarvis.api.squire.timeout_otp)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#jarvis.api.squire.timeout_otp.reset_surveillance">reset_surveillance() (in module jarvis.api.squire.timeout_otp)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#jarvis.executors.controls.restart">restart() (in module jarvis.executors.controls)</a>
</li>
<li><a href="index.html#jarvis.main.restart_checker">restart_checker() (in module jarvis.main)</a>
Expand Down Expand Up @@ -2774,7 +2780,11 @@ <h2 id="R">R</h2>
<li><a href="index.html#jarvis.api.squire.discover.routes">routes() (in module jarvis.api.squire.discover)</a>
</li>
<li><a href="index.html#jarvis.modules.speaker.speak.Speaker.run">run() (jarvis.modules.speaker.speak.Speaker method)</a>

<ul>
<li><a href="index.html#jarvis.modules.transformer.gpt.Customizer.run">(jarvis.modules.transformer.gpt.Customizer method)</a>
</li>
</ul></li>
<li><a href="index.html#jarvis.modules.audio.speech_synthesis.run_existing_container">run_existing_container() (in module jarvis.modules.audio.speech_synthesis)</a>
</li>
<li><a href="index.html#jarvis.modules.builtin_overrides.APIServer.run_in_parallel">run_in_parallel() (jarvis.modules.builtin_overrides.APIServer method)</a>
Expand Down
47 changes: 42 additions & 5 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10129,6 +10129,46 @@ <h1>Telegram<a class="headerlink" href="#id4" title="Permalink to this heading">
</dl>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="jarvis.modules.transformer.gpt.Customizer">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">jarvis.modules.transformer.gpt.</span></span><span class="sig-name descname"><span class="pre">Customizer</span></span><a class="headerlink" href="#jarvis.modules.transformer.gpt.Customizer" title="Permalink to this definition">¶</a></dt>
<dd><p>Customize prompt for the model with pre-defined instructions.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Customizer</span>
</pre></div>
</div>
<p>Initializes the model name.</p>
<dl class="py method">
<dt class="sig sig-object py" id="jarvis.modules.transformer.gpt.Customizer.run">
<span class="sig-name descname"><span class="pre">run</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">str</span></span></span><a class="headerlink" href="#jarvis.modules.transformer.gpt.Customizer.run" title="Permalink to this definition">¶</a></dt>
<dd><p>Runs the customizer with SDK as the primary option and CLI as secondary.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>Returns the model name.</p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p>str</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="jarvis.modules.transformer.gpt.Customizer.customize_model_cli">
<span class="sig-name descname"><span class="pre">customize_model_cli</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#jarvis.modules.transformer.gpt.Customizer.customize_model_cli" title="Permalink to this definition">¶</a></dt>
<dd><p>Uses the CLI to customize the model.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="jarvis.modules.transformer.gpt.Customizer.customize_model_sdk">
<span class="sig-name descname"><span class="pre">customize_model_sdk</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#jarvis.modules.transformer.gpt.Customizer.customize_model_sdk" title="Permalink to this definition">¶</a></dt>
<dd><p>Uses the CLI to customize the model.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p><a class="reference external" href="https://github.com/ollama/ollama-python/issues/171">Model creation with SDK is currently broke</a>.</p>
</div>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="jarvis.modules.transformer.gpt.Ollama">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">jarvis.modules.transformer.gpt.</span></span><span class="sig-name descname"><span class="pre">Ollama</span></span><a class="headerlink" href="#jarvis.modules.transformer.gpt.Ollama" title="Permalink to this definition">¶</a></dt>
Expand Down Expand Up @@ -10159,18 +10199,15 @@ <h1>Telegram<a class="headerlink" href="#id4" title="Permalink to this heading">

<dl class="py method">
<dt class="sig sig-object py" id="jarvis.modules.transformer.gpt.Ollama.query">
<span class="sig-name descname"><span class="pre">query</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">phrase</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">respond</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">bool</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">True</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">None</span></span></span><a class="headerlink" href="#jarvis.modules.transformer.gpt.Ollama.query" title="Permalink to this definition">¶</a></dt>
<span class="sig-name descname"><span class="pre">query</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">phrase</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</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">None</span></span></span><a class="headerlink" href="#jarvis.modules.transformer.gpt.Ollama.query" title="Permalink to this definition">¶</a></dt>
<dd><p>Queries the Ollama api with the request and speaks the response.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p>This plugin can fetch responses from a mapping file for, reusability when requests are identical.</p>
</div>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>phrase</strong> – Takes the phrase spoken as an argument.</p></li>
<li><p><strong>respond</strong> – Takes a boolean flag to suppress response.</p></li>
</ul>
<dd class="field-odd"><p><strong>phrase</strong> – Takes the phrase spoken as an argument.</p>
</dd>
</dl>
</dd></dl>
Expand Down
Binary file modified docs/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions jarvis/executors/others.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import urllib.request
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from threading import Thread
from typing import List, Tuple

import boto3
Expand Down Expand Up @@ -125,9 +124,6 @@ def apps(phrase: str) -> None:

if not app_check:
speaker.speak(text=f"I did not find the app {keyword}. Try again.")
Thread(
target=support.unrecognized_dumper, args=[{"APPLICATIONS": keyword}]
).start()
return
app_status = os.system(f"open /Applications/{keyword!r} > /dev/null 2>&1")
keyword = keyword.replace(".app", "")
Expand Down
2 changes: 2 additions & 0 deletions jarvis/executors/static_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from jarvis.modules.models import models
from jarvis.modules.utils import util

# TODO: Move most if not all of these to Modelfile


def form(*args) -> None:
"""Response for form."""
Expand Down
3 changes: 3 additions & 0 deletions jarvis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ def start() -> None:
shared.processes = processor.start_processes(
func_name="speech_synthesis_api"
)
# Enable speech synthesis for speaker
if not models.env.speech_synthesis_timeout:
models.env.speech_synthesis_timeout = 10
else:
shared.processes = processor.start_processes()
location.write_current_location()
Expand Down
8 changes: 4 additions & 4 deletions jarvis/modules/models/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ class EnvConfig(BaseSettings):
maps_api: str | None = None
news_api: str | None = None
ollama_model: str = "llama3"
ollama_timeout: int = Field(5, le=10, ge=1)
ollama_reuse_threshold: float | None = Field(None, ge=0.5, le=0.9)
ollama_timeout: int = Field(5, le=30, ge=1)
ollama_reuse_threshold: float | None = Field(None, le=0.9, ge=0.1)

# Communication config
gmail_user: EmailStr | None = None
Expand Down Expand Up @@ -465,8 +465,8 @@ class EnvConfig(BaseSettings):
bot_secret: str | None = Field(None, pattern="^[A-Za-z0-9_-]{1,256}$")
bot_certificate: FilePath | None = None

# Speech synthesis config
speech_synthesis_timeout: int = 3
# Speech synthesis config (disabled for speaker by default)
speech_synthesis_timeout: int = 0
speech_synthesis_voice: str = "en-us_northern_english_male-glow_tts"
speech_synthesis_quality: SSQuality = SSQuality.Medium_Quality
speech_synthesis_host: str = socket.gethostbyname("localhost")
Expand Down
15 changes: 15 additions & 0 deletions jarvis/modules/transformer/Modelfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM llama3

# set the temperature to 1 [higher is more creative, lower is more coherent]
PARAMETER temperature 1

# set the system message
SYSTEM """
You are Jarvis, a virtual assistant designed by Mr. Rao. Answer as Jarvis, the assistant, only.
Conversation Guidelines:
1. Keep your responses as short as possible (less than 100 words)
2. Use commas and full stops but DO NOT use emojis or other punctuations.
3. Your responses will be fed into a voice model, so limit your responses to a SINGLE SENTENCE through out the session.
"""

# todo: feed all features, location info and any custom conversation
4 changes: 2 additions & 2 deletions jarvis/modules/transformer/gpt.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

### Model specific todos:

1. [Customize prompt](https://github.com/ollama/ollama/blob/main/README.md#customize-a-prompt)
1. ~~[Customize prompt](https://github.com/ollama/ollama/blob/main/README.md#customize-a-prompt)~~
2. Support running in Docker containers
3. Write util scripts to,
- customize the model
- ~~customize the model~~
- build model and initiate server independently _(including docker)_
4. Add an option to host model on a remote server with an accessible endpoint
Loading

0 comments on commit 72b9e91

Please sign in to comment.