Message¶
How to use¶
import PIL.Image
from lumix.types.messages import *
from lumix.llm import OpenAI
messages = [
SystemMessage(content="You are a AI assistant."),
UserMessage(content="你好"),
AssistantMessage(content="你好, 我是AI助手。有什么可以帮助你的吗?"),
ImageMessage(
content="介绍这三张图片",
images=[
"https://test.png",
PIL.Image.Image,
"base64,data: image/png;base64,"
]
),
]
llm = OpenAI(
model="qwen", api_key="your_api_key",
base_url="https://api.openai.com/v1")
response = llm.completion(messages=messages)
print(response)
BaseMessage¶
SystemMessage¶
UserMessage¶
AssistantMessage¶
ImageMessage¶
# Object
role='assistant' content='介绍这三张图片' images=['https://test.png', 'PIL.Image.Image', 'base64,data: image/png;base64,']
# to openai message
{
"role": "user",
"content": [
{
"type": "text",
"text": "介绍这三张图片"
},
{
"type": "image_url",
"image_url": {
"url": image_url
}
},
{
"type": "image_url",
"image_url": {
"url": image_url
}
},
],
}
# to dict
{
"role": "user",
"content": [
{
"type": "text",
"text": "介绍这三张图片"
},
{
"type": "image",
"image": "image_url",
},
{
"type": "image",
"image": "image_url",
},
],
}