MCPcopy Create free account
hub / github.com/llm-attacks/llm-attacks / OpenaiModel

Class OpenaiModel

api_experiments/evaluate_api_models.py:23–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21 return json.JSONEncoder.default(self, obj)
22
23class OpenaiModel():
24 def __init__(self, model_name="gpt-3.5-turbo", add_system_prompt=True) -> None:
25 self.model_name = model_name
26 self.add_system_prompt = add_system_prompt
27
28 def fit_message(self, msg):
29 if self.add_system_prompt:
30 conversation = [
31 {"role": "system", "content": "You are a helpful assistant."},
32 {"role": "user", "content": msg}
33 ]
34 else:
35 conversation = [
36 {"role": "user", "content": msg}
37 ]
38 return conversation
39
40
41 def __call__(self, msg, **kwargs):
42 while True:
43 try:
44 raw_response = openai.ChatCompletion.create(
45 model=self.model_name,
46 messages=self.fit_message(msg),
47 **kwargs)
48 self.raw_response = raw_response
49
50 return [str(m.message.content) for m in raw_response['choices']]
51 except:
52 pass
53
54 time.sleep(10)
55
56class AnthropicModel():
57 def __init__(self, model_name="claude-2") -> None:

Callers 1

load_chatbotFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected