Skip to content

Commit 12e2bb3

Browse files
authored
Merge pull request #11 from FlowLLM-AI/vector_store_update
add content block enum
2 parents 2fb499c + 2479b28 commit 12e2bb3

6 files changed

Lines changed: 30 additions & 11 deletions

File tree

flowllm/core/enumeration/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
"""Core enumeration module."""
22

33
from .chunk_enum import ChunkEnum
4+
from .content_block_type import ContentBlockType
45
from .http_enum import HttpEnum
56
from .registry_enum import RegistryEnum
67
from .role import Role
78

89
__all__ = [
910
"ChunkEnum",
11+
"ContentBlockType",
1012
"HttpEnum",
1113
"RegistryEnum",
1214
"Role",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Content block type enumeration for multimodal content."""
2+
3+
from enum import Enum
4+
5+
6+
class ContentBlockType(str, Enum):
7+
"""Enumeration of content block types in multimodal responses."""
8+
9+
TEXT = "text"
10+
IMAGE_URL = "image_url"
11+
AUDIO = "audio"
12+
VIDEO = "video"

flowllm/core/llm/lite_llm.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def stream_chat(
110110
**self.kwargs,
111111
**kwargs,
112112
}
113-
logger.info(f"LiteLLM.stream_chat: {chat_kwargs}")
113+
log_kwargs = {k: v for k, v in chat_kwargs.items() if k != "messages"}
114+
logger.info(f"LiteLLM.stream_chat: {log_kwargs}")
114115

115116
for i in range(self.max_retries):
116117
try:
@@ -216,7 +217,8 @@ async def astream_chat(
216217
**self.kwargs,
217218
**kwargs,
218219
}
219-
logger.info(f"LiteLLM.astream_chat: {chat_kwargs}")
220+
log_kwargs = {k: v for k, v in chat_kwargs.items() if k != "messages"}
221+
logger.info(f"LiteLLM.astream_chat: {log_kwargs}")
220222

221223
for i in range(self.max_retries):
222224
try:

flowllm/core/llm/openai_compatible_llm.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ def stream_chat(
106106
**self.kwargs,
107107
**kwargs,
108108
}
109-
logger.info(f"OpenAICompatibleLLM.stream_chat: {chat_kwargs}")
109+
log_kwargs = {k: v for k, v in chat_kwargs.items() if k != "messages"}
110+
logger.info(f"OpenAICompatibleLLM.stream_chat: {log_kwargs}")
110111

111112
for i in range(self.max_retries):
112113
try:
@@ -207,7 +208,8 @@ async def astream_chat(
207208
**self.kwargs,
208209
**kwargs,
209210
}
210-
logger.info(f"OpenAICompatibleLLM.astream_chat: {chat_kwargs}")
211+
log_kwargs = {k: v for k, v in chat_kwargs.items() if k != "messages"}
212+
logger.info(f"OpenAICompatibleLLM.astream_chat: {log_kwargs}")
211213

212214
for i in range(self.max_retries):
213215
try:

flowllm/core/schema/message.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pydantic import BaseModel, ConfigDict, Field, model_validator
77

88
from .tool_call import ToolCall
9-
from ..enumeration import Role
9+
from ..enumeration import Role, ContentBlockType
1010

1111

1212
class ContentBlock(BaseModel):
@@ -35,7 +35,7 @@ class ContentBlock(BaseModel):
3535

3636
model_config = ConfigDict(extra="allow")
3737

38-
type: str = Field(default="")
38+
type: ContentBlockType = Field(default="")
3939
content: str | dict | list = Field(default="")
4040

4141
@model_validator(mode="before")
@@ -44,14 +44,15 @@ def init_block(cls, data: dict):
4444
"""Initialize content block by extracting content based on type field."""
4545
result = data.copy()
4646
content_type = data.get("type", "")
47-
result["content"] = data[content_type]
47+
if content_type and content_type in data:
48+
result["content"] = data[content_type]
4849
return result
4950

5051
def simple_dump(self) -> dict:
5152
"""Convert ContentBlock to a simple dictionary format."""
5253
result = {
53-
"type": self.type,
54-
self.type: self.content,
54+
"type": self.type.value,
55+
self.type.value: self.content,
5556
**self.model_extra,
5657
}
5758

tests/test_vision_audio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def encode_image(image_path):
1414
return base64.b64encode(image_file.read()).decode("utf-8")
1515

1616
# 将xxxx/eagle.png替换为你本地图像的绝对路径
17-
base64_image = encode_image("/Users/yuli/workspace/ReMe/20251128144329.jpg")
17+
base64_image = encode_image("/Users/yuli/Documents/20251128144329.jpg")
1818

1919
llm = OpenAICompatibleLLM(model_name="qwen3-vl-plus")
2020
messages = [
@@ -50,7 +50,7 @@ def encode_audio(audio_path):
5050
return base64.b64encode(audio_file.read()).decode("utf-8")
5151

5252
# 请将 ABSOLUTE_PATH/welcome.mp3 替换为本地音频的绝对路径
53-
audio_file_path = "/Users/yuli/workspace/ReMe/recordings/111.wav"
53+
audio_file_path = "/Users/yuli/Documents/111.wav"
5454
base64_audio = encode_audio(audio_file_path)
5555

5656
messages = [

0 commit comments

Comments
 (0)