Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix a regression in the generate extension. #3

Merged
merged 3 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/banks/extensions/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ def _generate(self, text, model_name=DEFAULT_MODEL):
{"role": "user", "content": text},
]
response: ModelResponse = cast(ModelResponse, completion(model=model_name, messages=messages))
content: str = response["choices"][0]["message"]["content"]
if SYSTEM_PROMPT.canary_leaked(content):
msg = "The system prompt has leaked into the response, possible prompt injection!"
raise CanaryWordError(msg)
return self._get_content(response)

async def _agenerate(self, text, model_name=DEFAULT_MODEL):
"""
Expand All @@ -78,4 +75,11 @@ async def _agenerate(self, text, model_name=DEFAULT_MODEL):
{"role": "user", "content": text},
]
response: ModelResponse = cast(ModelResponse, await acompletion(model=model_name, messages=messages))
return response["choices"][0]["message"]["content"]
return self._get_content(response)

def _get_content(self, response: ModelResponse) -> str:
content = response["choices"][0]["message"]["content"]
if SYSTEM_PROMPT.canary_leaked(content):
msg = "The system prompt has leaked into the response, possible prompt injection!"
raise CanaryWordError(msg)
return content
2 changes: 1 addition & 1 deletion src/banks/filters/lemmatize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from banks.errors import MissingDependencyError

try:
from simplemma import text_lemmatizer
from simplemma.simplemma import text_lemmatizer

simplemma_avail = True
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion src/banks/templates/generate_tweet.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Generate a tweet about the topic {{ topic }} with a positive sentiment.
#}
Examples:
{% for number in range(3) %}
- {% generate "write a tweet with positive sentiment" "gpt-3.5-turbo" %}
- {% generate "write a tweet with positive sentiment", "gpt-3.5-turbo" %}

{% endfor %}
Loading