Skip to content

Commit

Permalink
No system problem if default agent
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjosephhorton committed Sep 17, 2024
1 parent 5349a60 commit 373fb55
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 4 additions & 0 deletions edsl/agents/PromptConstructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ def agent_instructions_prompt(self) -> Prompt:
>>> i.prompt_constructor.agent_instructions_prompt
Prompt(text=\"""You are answering questions as if you were a human. Do not break character.\""")
"""
from edsl import Agent

if self.agent == Agent(): # if agent is empty, then return an empty prompt
return Prompt(text="")
if not hasattr(self, "_agent_instructions_prompt"):
applicable_prompts = prompt_lookup(
component_type="agent_instructions",
Expand Down
11 changes: 7 additions & 4 deletions edsl/inference_services/OpenAIService.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,15 @@ async def async_execute_model_call(
else:
content = user_prompt
client = self.async_client()
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": content},
]
if system_prompt == "" and self.omit_system_prompt_if_empty:
messages = messages[1:]
params = {
"model": self.model,
"messages": [
{"role": "system", "content": system_prompt},
{"role": "user", "content": content},
],
"messages": messages,
"temperature": self.temperature,
"max_tokens": self.max_tokens,
"top_p": self.top_p,
Expand Down
5 changes: 4 additions & 1 deletion edsl/language_models/LanguageModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,16 @@ class LanguageModel(
} # TODO: Use the OpenAI Teir 1 rate limits
_safety_factor = 0.8

def __init__(self, tpm=None, rpm=None, **kwargs):
def __init__(
self, tpm=None, rpm=None, omit_system_prompt_if_empty_string=True, **kwargs
):
"""Initialize the LanguageModel."""
self.model = getattr(self, "_model_", None)
default_parameters = getattr(self, "_parameters_", None)
parameters = self._overide_default_parameters(kwargs, default_parameters)
self.parameters = parameters
self.remote = False
self.omit_system_prompt_if_empty = omit_system_prompt_if_empty_string

if rpm is not None:
self._rpm = rpm
Expand Down
6 changes: 4 additions & 2 deletions edsl/language_models/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ class Model(metaclass=Meta):
def __new__(cls, model_name=None, registry=None, *args, **kwargs):
# Map index to the respective subclass
if model_name is None:
model_name = cls.default_model
model_name = (
cls.default_model
) # when model_name is None, use the default model, set in the config file
from edsl.inference_services.registry import default

registry = registry or default

if isinstance(model_name, int):
if isinstance(model_name, int): # can refer to a model by index
model_name = cls.available(name_only=True)[model_name]

factory = registry.create_model_factory(model_name)
Expand Down

0 comments on commit 373fb55

Please sign in to comment.