---desc: 文心大模型4.5是百度自主研发的新一代原生多模态基础大模型,通过多个模态联合建模实现协同优化,多模态理解能力优秀;具备更精进的语言能力,理解、生成、逻辑、记忆能力全面提升,去幻觉、逻辑推理、代码能力显著提升。 support_training: 0 tasks:- 文心大模型- 大语言模型 license: other dev_type:- notebook---<div align="center"><img src="https://ai-studio-static-online.cdn.bcebos.com/fc3d615dbfee41b79d4149be75edaa5b261eca1032f74bd7bbbb8464c86ad8e8" width = "450",caption='' /></div>## 模型描述文心大模型4.5是百度自主研发的新一代原生多模态基础大模型,通过多个模态联合建模实现协同优化,多模态理解能力优秀;具备更精进的语言能力,理解、生成、逻辑、记忆能力全面提升,去幻觉、逻辑推理、代码能力显著提升。## 模型开发体验更多文心大模型使用方法,详见[大模型开发文档](https://ai.baidu.com/ai-doc/AISTUDIO/rm344erns)### 使用星河社区提供的大模型API服务```import 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 服务域名)chat_completion = client.chat.completions.create( messages=[ {'role': 'system', 'content': '你是 AI Studio 实训AI开发平台的开发者助理,你精通开发相关的知识,负责给开发者提供搜索帮助建议。'}, {'role': 'user', 'content': '你好,请介绍一下AI Studio'} ], model="ernie-4.5-8k-preview",)print(chat_completion.choices[0].message.content)```### 流式输出```import 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 服务域名)completion = client.chat.completions.create( model="ernie-4.5-8k-preview", messages=[ {'role': 'system', 'content': '你是 AI Studio 实训AI开发平台的开发者助理,你精通开发相关的知识,负责给开发者提供搜索帮助建议。'}, {'role': 'user', 'content': '你好,请介绍一下AI Studio'} ], stream=True,)for chunk in completion: print(chunk.choices[0].delta.content or "", end="")```### 多模态-图片+文本输入-流式```import 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 服务域名)completion = client.chat.completions.create( model="ernie-4.5-8k-preview", 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)```