Skip to content

Commit

Permalink
feat(system_content): made it parametric
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaferrario committed Mar 13, 2024
1 parent dcf31dd commit c24983e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion keybert/llm/_litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class LiteLLM(BaseLLM):
def __init__(self,
model: str = "gpt-3.5-turbo",
prompt: str = None,
system_content: str = "You are a helpful assistant.",
generator_kwargs: Mapping[str, Any] = {},
delay_in_seconds: float = None,
verbose: bool = False
Expand All @@ -79,6 +80,7 @@ def __init__(self,
else:
self.prompt = prompt

self.system_content = system_content
self.default_prompt_ = DEFAULT_PROMPT
self.delay_in_seconds = delay_in_seconds
self.verbose = verbose
Expand Down Expand Up @@ -116,7 +118,7 @@ def extract_keywords(self, documents: List[str], candidate_keywords: List[List[s

# Use a chat model
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "system", "content": self.system_content},
{"role": "user", "content": prompt}
]
kwargs = {"model": self.model, "messages": messages, **self.generator_kwargs}
Expand Down
4 changes: 3 additions & 1 deletion keybert/llm/_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def __init__(self,
client,
model: str = "gpt-3.5-turbo-instruct",
prompt: str = None,
system_content: str = "You are a helpful assistant.",
generator_kwargs: Mapping[str, Any] = {},
delay_in_seconds: float = None,
exponential_backoff: bool = False,
Expand All @@ -128,6 +129,7 @@ def __init__(self,
else:
self.prompt = prompt

self.system_content = system_content
self.default_prompt_ = DEFAULT_CHAT_PROMPT if chat else DEFAULT_PROMPT
self.delay_in_seconds = delay_in_seconds
self.exponential_backoff = exponential_backoff
Expand Down Expand Up @@ -170,7 +172,7 @@ def extract_keywords(self, documents: List[str], candidate_keywords: List[List[s
# Use a chat model
if self.chat:
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "system", "content": self.system_content},
{"role": "user", "content": prompt}
]
kwargs = {"model": self.model, "messages": messages, **self.generator_kwargs}
Expand Down

0 comments on commit c24983e

Please sign in to comment.