Skip to content

Commit

Permalink
remove pyping
Browse files Browse the repository at this point in the history
  • Loading branch information
ilude committed Jun 15, 2024
1 parent 0a5aadb commit 2949e52
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/processors/title_editor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime, timedelta
import logging
import os
import pyping
import socket

from pytz import utc
from models.feed_article import FeedArticle
Expand All @@ -18,12 +18,17 @@


class TitleEditor:
def hostname_resolves(hostname):
try:
socket.gethostbyname(hostname)
return 1
except socket.error:
return 0

def __init__(self):
self.ollama_url = os.getenv('OLLAMA_URL')

self.ping_result = (pyping.ping(self.ollama_url).ret_code == 0)

if self.ollama_url and self.ping_result:
if self.ollama_url and self.hostname_resolves(self.ollama_url):
parser = StructuredOutputParser.from_response_schemas(
[ResponseSchema(name="title", description="title of the article")]
)
Expand Down Expand Up @@ -72,7 +77,7 @@ def __init__(self):
self.script_hash = calculate_sha1_hash(f"{system_prompt.content}{model_name}{model_temp}")

def process(self, articles: list[FeedArticle]) -> list[FeedArticle]:
if self.ollama_url and self.ping_result:
if self.ollama_url and self.hostname_resolves(self.ollama_url):

needs_processed = list(filter(lambda article: article.processed != self.script_hash, articles))
# if len(needs_processed) > 10:
Expand Down

0 comments on commit 2949e52

Please sign in to comment.