Skip to content

Commit

Permalink
[Model] Update glmvision (#748)
Browse files Browse the repository at this point in the history
* update glm vision

* update glm vision

* fix

* update glm4v_plus

* update glmvision to mass api
  • Loading branch information
iyuge2 authored Jan 24, 2025
1 parent 4f2d6ad commit 89e68e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 30 deletions.
40 changes: 11 additions & 29 deletions vlmeval/api/glm_vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from vlmeval.api.base import BaseAPI
from vlmeval.dataset import DATASET_TYPE
from vlmeval.smp.vlm import encode_image_file_to_base64
from zhipuai import ZhipuAI


class GLMVisionWrapper(BaseAPI):
Expand All @@ -24,21 +25,13 @@ def __init__(self,

self.model = model
self.fail_msg = 'Failed to obtain answer via API. '
self.default_params = {
'top_k': 1,
'best_of': 1,
'do_sample': False,
'stream': False,
'max_tokens': max_tokens,
"skip_moderation": True
}
if key is None:
key = os.environ.get('GLMV_API_KEY', None)
assert key is not None, (
'Please set the API Key (obtain it here: '
'https://open.bigmodel.cn/dev/howuse/introduction)'
'https://bigmodel.cn)'
)
self.key = key
self.client = ZhipuAI(api_key=key)
super().__init__(wait=wait, retry=retry, system_prompt=system_prompt, verbose=verbose, **kwargs)

def build_msgs(self, msgs_raw, system_prompt=None, dataset=None):
Expand All @@ -60,28 +53,17 @@ def generate_inner(self, inputs, **kwargs) -> str:

messages = self.build_msgs(msgs_raw=inputs, dataset=kwargs.get('dataset', None))

url = 'https://api.chatglm.cn/v1/chat/completions'
headers = {
'Content-Type': 'application/json',
'Request-Id': 'remote-test',
'Authorization': f'Bearer {self.key}'
}
payload = {
'model': self.model,
'messages': messages,
**self.default_params
}
response = requests.post(url, headers=headers, data=json.dumps(payload), verify=False)
output = []
response = self.client.chat.completions.create(
model=self.model,
messages=messages,
do_sample=False,
max_tokens=2048
)
try:
assert response.status_code == 200
for line in response.iter_lines():
data = json.loads(line.decode('utf-8').lstrip('data: '))
output.append(data['choices'][0]['message']['content'])
answer = ''.join(output).replace('</s>', '')
answer = response.choices[0].message.content.strip()
if self.verbose:
self.logger.info(f'inputs: {inputs}\nanswer: {answer}')
return 0, answer, 'Succeeded! '
return 0, answer, 'Succeeded!'
except Exception as err:
if self.verbose:
self.logger.error(f'{type(err)}: {err}')
Expand Down
3 changes: 2 additions & 1 deletion vlmeval/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
'Claude3-5V_Sonnet_20241022': partial(Claude3V, model='claude-3-5-sonnet-20241022', temperature=0, retry=10, verbose=False),
# GLM4V
'GLM4V': partial(GLMVisionAPI, model='glm4v-biz-eval', temperature=0, retry=10),
'GLM4V_PLUS': partial(GLMVisionAPI, model='cogvlm-evaluation-241203', temperature=0, retry=10),
'GLM4V_PLUS': partial(GLMVisionAPI, model='glm-4v-plus', temperature=0, retry=10),
'GLM4V_PLUS_20250111': partial(GLMVisionAPI, model='glm-4v-plus-0111', temperature=0, retry=10),
# MiniMax abab
'abab6.5s': partial(GPT4V, model='abab6.5s-chat', api_base='https://api.minimax.chat/v1/chat/completions', temperature=0, retry=10),
'abab7-preview': partial(GPT4V, model='abab7-chat-preview', api_base='https://api.minimax.chat/v1/chat/completions', temperature=0, retry=10),
Expand Down

0 comments on commit 89e68e8

Please sign in to comment.