Files
chongming-core/test_aicc.py
T
2026-07-27 14:25:29 +08:00

45 lines
1.5 KiB
Python

import asyncio
import base64
from openai import AsyncOpenAI
from bytedance.volcengine_aicc_sdk.secure_http_client import AICCConfig, AsyncSecureHttpClient
ep_name = "ep-20260721154333-fre3bey"
api_key = "db04d42e-71e3-4119-abee-12ecc7ef5c34"
base_url= "https://sd77a0f4ummt3i4vnems0.apigateway-cn-beijing.volceapi.com/api/v3"
async def main():
with open("./test.png", "rb") as f:
image_base64 = base64.b64encode(f.read()).decode("utf-8")
mime_type = "image/png"
prompt = '请问图州是否有抽烟行为(注意请仔细检查是否为嘴叼吸管造成的误报),若有请以该格式返回 {"result": "true", bbox: [[x1, y1, x2, y2],...]},若无则返回{"result": "false", bbox: []}'
messages = [
{
"role": "user",
"content": [
{"type": "image_url", "image_url": f"data:{mime_type};base64,{image_base64}"},
{"type": "text", "text": prompt}
]
}
]
aicc_config = AICCConfig(ra_url=base_url, auth_token=api_key)
client = AsyncOpenAI(
api_key=api_key,
base_url=base_url,
http_client=AsyncSecureHttpClient(aicc_config=aicc_config),
)
# 问答非流式,通过 extra_body 禁用思考模式
response = await client.chat.completions.create(
model=ep_name,
messages=messages, # type: ignore
extra_body={"thinking": {"type": "disabled"}}
)
result = response.choices[0].message.content
print(result)
if __name__ == "__main__":
asyncio.run(main())