Skip to content

Commit

Permalink
support o1 and claude (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harold-lkk authored Dec 21, 2024
1 parent 784b12a commit a58c914
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lagent/llms/anthropic_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ def generate_request_data(self, model_type, messages, gen_params):
if messages[0]['role'] == 'system':
system = messages.pop(0)
system = system['content']

for message in messages:
message.pop('name', None)
data = {'model': model_type, 'messages': messages, **gen_params}
if system:
data['system'] = system
Expand Down Expand Up @@ -389,6 +390,8 @@ async def _chat(self, messages: List[dict], **gen_params) -> str:
):
self.invalid_keys.add(key)
print(f'API has no quota: {key}, Valid keys: {len(self.keys) - len(self.invalid_keys)}')
else:
raise error
max_num_retries += 1

raise RuntimeError(
Expand Down
3 changes: 3 additions & 0 deletions lagent/llms/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ def generate_request_data(self, model_type, messages, gen_params, json_mode=Fals
gen_params.pop('top_k')
gen_params.pop('skip_special_tokens', None)
gen_params.pop('session_id', None)

data = {'model': model_type, 'messages': messages, 'n': 1, **gen_params}
if json_mode:
data['response_format'] = {'type': 'json_object'}
Expand All @@ -819,6 +820,8 @@ def generate_request_data(self, model_type, messages, gen_params, json_mode=Fals
gen_params['repetition_penalty'] = gen_params.pop('frequency_penalty')
gen_params['result_format'] = 'message'
data = {'model': model_type, 'input': {'messages': messages}, 'parameters': {**gen_params}}
elif model_type.lower().startswith('o1'):
data = {'model': model_type, 'messages': messages, 'n': 1}
else:
raise NotImplementedError(f'Model type {model_type} is not supported')

Expand Down

0 comments on commit a58c914

Please sign in to comment.