|
| 1 | +import os.path |
| 2 | + |
| 3 | +from zhipuai import ZhipuAI |
| 4 | +import zhipuai |
| 5 | +import time |
| 6 | + |
| 7 | +import logging |
| 8 | +import logging.config |
| 9 | + |
| 10 | + |
| 11 | +def test_completions_vlm_thinking(logging_conf): |
| 12 | + logging.config.dictConfig(logging_conf) # type: ignore |
| 13 | + client = ZhipuAI() # 填写您自己的APIKey |
| 14 | + try: |
| 15 | + # 生成request_id |
| 16 | + request_id = time.time() |
| 17 | + print(f"request_id:{request_id}") |
| 18 | + response = client.chat.completions.create( |
| 19 | + request_id=request_id, |
| 20 | + model="glm-4.1v-thinking-flash", # 填写需要调用的模型名称 |
| 21 | + messages=[ |
| 22 | + { |
| 23 | + "role": "user", |
| 24 | + "content": [ |
| 25 | + { |
| 26 | + "type": "text", |
| 27 | + "text": "图里有什么" |
| 28 | + }, |
| 29 | + |
| 30 | + { |
| 31 | + "type": "image_url", |
| 32 | + "image_url": { |
| 33 | + "url": "https://img1.baidu.com/it/u=1369931113,3388870256&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1703696400&t=f3028c7a1dca43a080aeb8239f09cc2f" |
| 34 | + } |
| 35 | + } |
| 36 | + ] |
| 37 | + } |
| 38 | + ], |
| 39 | + temperature=0.5, |
| 40 | + max_tokens = 1024, |
| 41 | + user_id="12345678" |
| 42 | + ) |
| 43 | + print(response) |
| 44 | + |
| 45 | + |
| 46 | + except zhipuai.core._errors.APIRequestFailedError as err: |
| 47 | + print(err) |
| 48 | + except zhipuai.core._errors.APIInternalError as err: |
| 49 | + print(err) |
| 50 | + except zhipuai.core._errors.APIStatusError as err: |
| 51 | + print(err) |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +def test_completions_vlm_thinking_stream(logging_conf): |
| 56 | + logging.config.dictConfig(logging_conf) # type: ignore |
| 57 | + client = ZhipuAI() # 填写您自己的APIKey |
| 58 | + try: |
| 59 | + # 生成request_id |
| 60 | + request_id = time.time() |
| 61 | + print(f"request_id:{request_id}") |
| 62 | + response = client.chat.completions.create( |
| 63 | + request_id=request_id, |
| 64 | + model="glm-4.1v-thinking-flash", # 填写需要调用的模型名称 |
| 65 | + messages=[ |
| 66 | + { |
| 67 | + "role": "user", |
| 68 | + "content": [ |
| 69 | + { |
| 70 | + "type": "text", |
| 71 | + "text": "图里有什么" |
| 72 | + }, |
| 73 | + |
| 74 | + { |
| 75 | + "type": "image_url", |
| 76 | + "image_url": { |
| 77 | + "url": "https://img1.baidu.com/it/u=1369931113,3388870256&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1703696400&t=f3028c7a1dca43a080aeb8239f09cc2f" |
| 78 | + } |
| 79 | + } |
| 80 | + ] |
| 81 | + } |
| 82 | + ], |
| 83 | + temperature=0.5, |
| 84 | + max_tokens = 1024, |
| 85 | + user_id="12345678", |
| 86 | + stream=True |
| 87 | + ) |
| 88 | + for item in response: |
| 89 | + print(item) |
| 90 | + |
| 91 | + except zhipuai.core._errors.APIRequestFailedError as err: |
| 92 | + print(err) |
| 93 | + except zhipuai.core._errors.APIInternalError as err: |
| 94 | + print(err) |
| 95 | + except zhipuai.core._errors.APIStatusError as err: |
| 96 | + print(err) |
| 97 | + |
0 commit comments