
---desc: 文心一言大模型全新版本,图片理解、创作、翻译、代码等能力显著提升,首次支持32K上下文长度,首Token时延显著降低。 support_training: 0 tasks:- 文心大模型- 多模态模型 license: other dev_type:- notebook---## 模型描述文心一言大模型全新版本,图片理解、创作、翻译、代码等能力显著提升,首次支持32K上下文长度,首Token时延显著降低。## 模型开发体验更多文心大模型使用方法,详见[大模型开发文档](https://ai.baidu.com/ai-doc/AISTUDIO/rm344erns)### 使用星河社区提供的大模型API服务-流式输出```pythonimport osfrom openai import OpenAIclient = OpenAI( api_key=os.environ.get("AI_STUDIO_API_KEY"), # 含有 AI Studio 访问令牌的环境变量,https://aistudio.baidu.com/account/accessToken, base_url="https://aistudio.baidu.com/llm/lmapi/v3", # aistudio 大模型 api 服务域名)# 此模型为多模态模型,支持文字、图片输入,以下为【文字输入】、【图片url输入】、【文字+图片输入】三种调用示例。# 更多详情可查看api文档:https://ai.baidu.com/ai-doc/AISTUDIO/rm344erns#56-%E5%A4%9A%E6%A8%A1%E6%80%81# 使用方式一:文字输入completion = client.chat.completions.create( model="ernie-4.5-turbo-vl-32k", messages=[ {'role': 'system', 'content': '你是 AI Studio 实训AI开发平台的开发者助理,你精通开发相关的知识,负责给开发者提供搜索帮助建议。'}, {'role': 'user', 'content': '你好,请介绍一下AI Studio'} ], stream=True,)# 流式输出for chunk in completion: if (len(chunk.choices) > 0): print(chunk.choices[0].delta.content, end="", flush=True)``````python# 使用方式二:图片输入(url)completion = client.chat.completions.create( model="ernie-4.5-turbo-vl-32k", messages=[ { 'role': 'user', 'content': [ { "type": "image_url", "image_url": { "url": "https://testimage.bj.bcebos.com/image1.jpg" } } ] } ], stream=True, )# 流式输出for chunk in completion: if (len(chunk.choices) > 0): print(chunk.choices[0].delta.content, end="", flush=True)``````python# 使用方式三:图片+文本输入completion = client.chat.completions.create( model="ernie-4.5-turbo-vl-32k", messages=[ { "role": "user", "content": [ { "type": "text", "text": "图片里有什么?这两张图片有什么不同?请用中文回答" }, { "type": "image_url", "image_url": { "url": "https://testimage.bj.bcebos.com/image1.jpg" } }, { "type": "image_url", "image_url": { "url": "https://testimage.bj.bcebos.com/image2.png" } } ] } ], stream=True, )# 流式输出for chunk in completion: if (len(chunk.choices) > 0): print(chunk.choices[0].delta.content, end="", flush=True)```