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

BUG AttributeError: 'OpenAIChatTarget' object has no attribute 'print' #166

Closed
corticalstack opened this issue Apr 23, 2024 · 0 comments
Closed

Comments

@corticalstack
Copy link

Describe the bug

Trying to instantiate an OpenAIChatTarget (not Azure). Code taken from previous issue regards implementing the OpenAIChatTarget:

import os

from pyrit.common import default_values
from pyrit.prompt_target import OpenAIChatTarget
from pyrit.models import ChatMessage

default_values.load_default_env()

target_llm = OpenAIChatTarget(
    deployment_name=os.environ.get("OPENAI_CHAT_DEPLOYMENT"),
    endpoint=os.environ.get("OPENAI_CHAT_ENDPOINT"),
    api_key=os.environ.get("OPENAI_CHAT_KEY"),
)

print(os.environ.get("OPENAI_CHAT_DEPLOYMENT"))
print(os.environ.get("OPENAI_CHAT_END"))
prompt = "test"
target_llm.complete_chat(messages=[ChatMessage(content=prompt, role="user")])

Steps/Code to Reproduce

Run the above code, fails with no attribute print. Pyrit installed with pip. Perhaps your PyPi release is outdated?

AttributeError                            Traceback (most recent call last)
Cell In[1], [line 9](vscode-notebook-cell:?execution_count=1&line=9)
      [5](vscode-notebook-cell:?execution_count=1&line=5) from pyrit.models import ChatMessage
      [7](vscode-notebook-cell:?execution_count=1&line=7) default_values.load_default_env()
----> [9](vscode-notebook-cell:?execution_count=1&line=9) target_llm = OpenAIChatTarget(
     [10](vscode-notebook-cell:?execution_count=1&line=10)     deployment_name=os.environ.get("OPENAI_CHAT_DEPLOYMENT"),
     [11](vscode-notebook-cell:?execution_count=1&line=11)     endpoint=os.environ.get("OPENAI_CHAT_ENDPOINT"),
     [12](vscode-notebook-cell:?execution_count=1&line=12)     api_key=os.environ.get("OPENAI_CHAT_KEY"),
     [13](vscode-notebook-cell:?execution_count=1&line=13) )
     [15](vscode-notebook-cell:?execution_count=1&line=15) print(os.environ.get("OPENAI_CHAT_DEPLOYMENT"))
     [16](vscode-notebook-cell:?execution_count=1&line=16) print(os.environ.get("OPENAI_CHAT_END"))

File [~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:317](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a22506f65227d.vscode-resource.vscode-cdn.net/mnt/samssd/developments/genai-playground/language/98-red-team/~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:317), in OpenAIChatTarget.__init__(self, deployment_name, endpoint, api_key, memory, max_tokens, temperature, top_p, frequency_penalty, presence_penalty)
    [311](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a22506f65227d.vscode-resource.vscode-cdn.net/mnt/samssd/developments/genai-playground/language/98-red-team/~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:311) self._presence_penalty = presence_penalty
    [313](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a22506f65227d.vscode-resource.vscode-cdn.net/mnt/samssd/developments/genai-playground/language/98-red-team/~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:313) self._deployment_name = default_values.get_required_value(
    [314](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a22506f65227d.vscode-resource.vscode-cdn.net/mnt/samssd/developments/genai-playground/language/98-red-team/~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:314)     env_var_name=self.DEPLOYMENT_ENVIRONMENT_VARIABLE, passed_value=deployment_name
    [315](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a22506f65227d.vscode-resource.vscode-cdn.net/mnt/samssd/developments/genai-playground/language/98-red-team/~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:315) )
    [316](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a22506f65227d.vscode-resource.vscode-cdn.net/mnt/samssd/developments/genai-playground/language/98-red-team/~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:316) endpoint = default_values.get_required_value(
--> [317](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a22506f65227d.vscode-resource.vscode-cdn.net/mnt/samssd/developments/genai-playground/language/98-red-team/~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:317)     env_var_name=self.print, passed_value=endpoint
    [318](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a22506f65227d.vscode-resource.vscode-cdn.net/mnt/samssd/developments/genai-playground/language/98-red-team/~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:318) )
    [319](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a22506f65227d.vscode-resource.vscode-cdn.net/mnt/samssd/developments/genai-playground/language/98-red-team/~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:319) api_key = default_values.get_required_value(
    [320](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a22506f65227d.vscode-resource.vscode-cdn.net/mnt/samssd/developments/genai-playground/language/98-red-team/~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:320)     env_var_name=self.API_KEY_ENVIRONMENT_VARIABLE, passed_value=api_key
    [321](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a22506f65227d.vscode-resource.vscode-cdn.net/mnt/samssd/developments/genai-playground/language/98-red-team/~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:321) )
    [322](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a22506f65227d.vscode-resource.vscode-cdn.net/mnt/samssd/developments/genai-playground/language/98-red-team/~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:322) self._client = OpenAI(
    [323](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a22506f65227d.vscode-resource.vscode-cdn.net/mnt/samssd/developments/genai-playground/language/98-red-team/~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:323)     api_key=api_key,
    [324](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a22506f65227d.vscode-resource.vscode-cdn.net/mnt/samssd/developments/genai-playground/language/98-red-team/~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:324)     base_url=endpoint,
    [325](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a22506f65227d.vscode-resource.vscode-cdn.net/mnt/samssd/developments/genai-playground/language/98-red-team/~/.conda/envs/genaiplayground_redteam/lib/python3.10/site-packages/pyrit/prompt_target/openai_chat_target.py:325) )

AttributeError: 'OpenAIChatTarget' object has no attribute 'print'

Versions

OS: Ubuntu 23.04 (Windows 11, WSL 2)
Python : 3.10.14

System:
python: 3.10.14 (main, Mar 21 2024, 16:24:04) [GCC 11.2.0]
executable: /root/miniconda3/envs/lhg_py310_pyrit/bin/python
machine: Linux-5.10.102.1-microsoft-standard-WSL2-x86_64-with-glibc2.37

Python dependencies:
pyrit: 0.1.2
Cython: None
numpy: 1.26.4
openai: 1.23.2
pip: 23.3.1
scikit-learn: 1.4.2
scipy: 1.13.0
setuptools: 68.0.0
tensorflow: None
torch: 2.1.2
transformers: 4.40.0

@corticalstack corticalstack changed the title AttributeError: 'OpenAIChatTarget' object has no attribute 'print' BUG: AttributeError: 'OpenAIChatTarget' object has no attribute 'print' Apr 23, 2024
@corticalstack corticalstack changed the title BUG: AttributeError: 'OpenAIChatTarget' object has no attribute 'print' BUG AttributeError: 'OpenAIChatTarget' object has no attribute 'print' Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant