Skip to content

Commit ada2564

Browse files
committed
small steps to make the plugin work
1 parent 461296e commit ada2564

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

HissMed/retrieve_articles.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,21 @@ def batch_download_pdfs(cls, query, retmax=100, db="pmc"):
8787
cls.download_pdfs(pmc_ids)
8888

8989
@classmethod
90-
def run(cls, query, email):
90+
def run(cls, query):
91+
if Entrez.email is None:
92+
raise ValueError("Please set your email address")
9193
cls.create_directory()
92-
Entrez.email = email
9394
cls.batch_download_pdfs(query)
9495

96+
@classmethod
97+
def set_email(cls, email):
98+
if email == 'your.email@mail.com':
99+
raise ValueError("Please set your email address")
100+
Entrez.email = email
95101

96102
if __name__ == "__main__":
97103
args = PapersDownloader.get_args()
98104
query = args.query or '(Multiple Myeloma[Title]) AND ("2021/01/01"[Publication Date] : "2021/01/10"[Publication Date])'
99105
email = args.email or "your.email@example.com"
100-
PapersDownloader.run(query, email)
106+
PapersDownloader.set_email(email)
107+
PapersDownloader.run(query)

hissmed_literature_assistant.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
from cat.mad_hatter.decorators import tool, hook, plugin
2-
from pydantic import BaseModel
32
from datetime import datetime, date
3+
from cat.looking_glass.stray_cat import StrayCat
4+
from cat.log import log
5+
import os
6+
import sys
47

5-
class MySettings(BaseModel):
6-
required_int: int
7-
optional_int: int = 69
8-
required_str: str
9-
optional_str: str = "meow"
10-
required_date: date
11-
optional_date: date = 1679616000
8+
sys.path.append(os.path.join(os.path.dirname(__file__)))
129

13-
@plugin
14-
def settings_model():
15-
return MySettings
16-
17-
@tool
18-
def get_the_day(tool_input, cat):
19-
"""Get the day of the week. Input is always None."""
10+
from HissMed.retrieve_articles import PapersDownloader
2011

21-
dt = datetime.now()
2212

23-
return dt.strftime('%A')
24-
25-
@hook
26-
def before_cat_sends_message(message, cat):
13+
def settings_model():
14+
settings = cat.mad_hatter.get_plugin().load_settings()
15+
return settings
2716

28-
prompt = f'Rephrase the following sentence in a grumpy way: {message["content"]}'
29-
message["content"] = cat.llm(prompt)
3017

31-
return message
18+
@tool
19+
def hisscat_download_literature(user_message, cat):
20+
""" run this tool whenever the message starts with HissMed search"""
21+
# user_message = StrayCat.working_memory.user_message_json.text
22+
log.debug(f"User message received: {user_message}") # Log the user message
23+
# Check if the input matches the 'HissMed search: <query>' format
24+
if user_message.startswith("HissMed search: "):
25+
settings = settings_model()
26+
PapersDownloader.set_email(email=settings['email'])
27+
# Extract the query
28+
query = user_message[len("HissMed search: "):]
29+
# Print the query
30+
log.debug(f"Query received: {query}")
31+
PapersDownloader.run(query)
32+
return user_message

settings.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from pydantic import BaseModel, Field, field_validator
1+
from pydantic import BaseModel, field_validator
2+
from cat.mad_hatter.decorators import plugin
23

34
class MySettings(BaseModel):
45
email: str = "your.email@mail.com"
@@ -7,11 +8,11 @@ class MySettings(BaseModel):
78
@field_validator("email")
89
@classmethod
910
def email_validator(cls, email):
10-
if "@" not in value:
11+
if "@" not in email:
1112
raise ValueError("Invalid email address")
12-
elif "your.email@mail.com" == value:
13+
elif "your.email@mail.com" == email:
1314
raise ValueError("Please set your email address")
1415

15-
#@plugin
16+
@plugin
1617
def settings_model():
1718
return MySettings

0 commit comments

Comments
 (0)