how to run it with my custom model from anthropic? as an attacker model
- User
how to run it with my custom model from anthropic? as an attacker model
Assistant
how to run it with my custom model from anthropic? as an attacker model
Based on the repository content, the TAP implementation currently doesn't have direct support for Anthropic models as an attacker. However, I can suggest how you could add support for it:
language_models.py to add a new class for Anthropic models, similar to how other API models are implemented. Here's a rough example:class AnthropicModel(LanguageModel):
API_RETRY_SLEEP = 10
API_ERROR_OUTPUT = "$ERROR$"
API_QUERY_SLEEP = 0.5
API_MAX_RETRY = 20
API_TIMEOUT = 20
def __init__(self, model_name):
self.model_name = model_name
self.client = anthropic.Client(os.getenv("ANTHROPIC_API_KEY"))
def generate(self, conv: List[Dict],
max_n_tokens: int,
temperature: float,
top_p: float):
output = self.API_ERROR_OUTPUT
for _ in range(self.API_MAX_RETRY):
try:
# Convert conv format to Anthropic format
# You'll need to implement the conversion based on your conv structure
response = self.client.messages.create(
model=self.model_name,
max_tokens=max_n_tokens,
temperature=temperature,
messages=conv # You'll need to format this appropriately
)
output = response.content[0].text
break
except Exception as e:
print(type(e), e)
time.sleep(self.API_RETRY_SLEEP)
time.sleep(self.API_QUERY_SLEEP)
return output
def batched_generate(self,
convs_list: List[List[Dict]],
max_n_tokens: int,
temperature: float,
top_p: float = 1.0):
return [self.generate(conv, max_n_tokens, temperature, top_p) for conv in convs_list]
main_TAP.py to add your Anthropic model as an option in the argument parser:parser.add_argument(
"--attack-model",
default = "vicuna",
help = "Name of attacking model.",
choices=["vicuna",
"vicuna-api-model",
"gpt-3.5-turbo",
"gpt-4",
"gpt-4-turbo",
"gpt-4-1106-preview",
"llama-2-api-model",
"claude-2", # Add your Anthropic model here
"claude-instant"]
)
export ANTHROPIC_API_KEY="your-api-key"
python main_TAP.py --attack-model claude-2 --target-model gpt-4 --evaluator-model gpt-3.5-turbo --goal "your-goal" --target-str "target-string" --store-folder "output-folder"
Note that you'll need to:
pip install anthropicRemember to follow Anthropic's usage policies and terms of service when implementing this integration.