Skip to content

Commit

Permalink
Fix model customizer with ollama SDK and remove the CLI function
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Jun 4, 2024
1 parent fb1f620 commit 508adb8
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 55 deletions.
8 changes: 3 additions & 5 deletions docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,11 @@ <h2 id="C">C</h2>
<li><a href="index.html#jarvis.modules.tv.lg.LGWebOS.close_app">close_app() (jarvis.modules.tv.lg.LGWebOS method)</a>
</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>
<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>
</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>
<li><a href="index.html#jarvis.modules.utils.util.comma_separator">comma_separator() (in module jarvis.modules.utils.util)</a>
Expand Down Expand Up @@ -453,9 +453,7 @@ <h2 id="C">C</h2>
</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><a href="index.html#jarvis.modules.transformer.gpt.Customizer.customize_model">customize_model() (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>
Expand Down
14 changes: 2 additions & 12 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10262,21 +10262,11 @@ <h1>Telegram<a class="headerlink" href="#id4" title="Permalink to this heading">
</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>
<dt class="sig sig-object py" id="jarvis.modules.transformer.gpt.Customizer.customize_model">
<span class="sig-name descname"><span class="pre">customize_model</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" 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">
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/car.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import time
import traceback
from datetime import datetime

# noinspection PyProtectedMember
Expand Down Expand Up @@ -45,9 +44,6 @@ def create_connection() -> None:
connection = None
except Exception as error:
logger.error(error)
if models.settings.pname == "JARVIS":
# Avoid butchering all log files
logger.error(traceback.format_exc())
connection = None
if connection and connection.head:
if len(connection.vehicles) == 1:
Expand Down
37 changes: 4 additions & 33 deletions jarvis/modules/transformer/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import collections
import difflib
import os
import subprocess
import warnings
from collections.abc import Generator

Expand Down Expand Up @@ -172,48 +171,20 @@ def run(self) -> str:
Returns the model name.
"""
try:
self.customize_model_sdk()
self.customize_model()
return self.model_name
except ollama.ResponseError as error:
logger.error(error)
try:
self.customize_model_cli()
return self.model_name
except (subprocess.SubprocessError, AssertionError) as error:
logger.error(error)
return models.env.ollama_model

def customize_model_cli(self) -> None:
def customize_model(self) -> None:
"""Uses the CLI to customize the model."""
process = subprocess.Popen(
f"ollama create {self.model_name} -f {models.fileio.ollama_model_file}",
shell=True,
universal_newlines=True,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
for line in process.stdout:
logger.info(line.strip())
process.wait()
for line in process.stderr:
logger.warning(line.strip())
assert process.returncode == 0, "Failed to customize the model"

def customize_model_sdk(self) -> None:
"""Uses the CLI to customize the model.
Warnings:
`Model creation with SDK is currently broke <https://github.com/ollama/ollama-python/issues/171>`__.
"""
for res in ollama.create(
model=self.model_name,
modelfile=models.fileio.ollama_model_file,
path=models.fileio.ollama_model_file,
stream=True,
):
logger.info(res["response"])
if res["done"]:
break
logger.info(res["status"])


class Ollama:
Expand Down

0 comments on commit 508adb8

Please sign in to comment.