livekit-plugins-volcenginee 1.3.4__tar.gz → 1.3.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {livekit_plugins_volcenginee-1.3.4 → livekit_plugins_volcenginee-1.3.5}/.gitignore +1 -0
- {livekit_plugins_volcenginee-1.3.4 → livekit_plugins_volcenginee-1.3.5}/PKG-INFO +1 -1
- {livekit_plugins_volcenginee-1.3.4 → livekit_plugins_volcenginee-1.3.5}/livekit/plugins/volcengine/llm.py +2 -2
- livekit_plugins_volcenginee-1.3.5/livekit/plugins/volcengine/utils.py +25 -0
- livekit_plugins_volcenginee-1.3.5/livekit/plugins/volcengine/version.py +1 -0
- livekit_plugins_volcenginee-1.3.4/livekit/plugins/volcengine/utils.py +0 -154
- livekit_plugins_volcenginee-1.3.4/livekit/plugins/volcengine/version.py +0 -1
- {livekit_plugins_volcenginee-1.3.4 → livekit_plugins_volcenginee-1.3.5}/README.md +0 -0
- {livekit_plugins_volcenginee-1.3.4 → livekit_plugins_volcenginee-1.3.5}/livekit/plugins/volcengine/__init__.py +0 -0
- {livekit_plugins_volcenginee-1.3.4 → livekit_plugins_volcenginee-1.3.5}/livekit/plugins/volcengine/log.py +0 -0
- {livekit_plugins_volcenginee-1.3.4 → livekit_plugins_volcenginee-1.3.5}/livekit/plugins/volcengine/py.typed +0 -0
- {livekit_plugins_volcenginee-1.3.4 → livekit_plugins_volcenginee-1.3.5}/livekit/plugins/volcengine/realtime.py +0 -0
- {livekit_plugins_volcenginee-1.3.4 → livekit_plugins_volcenginee-1.3.5}/livekit/plugins/volcengine/stt.py +0 -0
- {livekit_plugins_volcenginee-1.3.4 → livekit_plugins_volcenginee-1.3.5}/livekit/plugins/volcengine/tts.py +0 -0
- {livekit_plugins_volcenginee-1.3.4 → livekit_plugins_volcenginee-1.3.5}/pyproject.toml +0 -0
|
@@ -21,7 +21,7 @@ from livekit.agents.types import (
|
|
|
21
21
|
from livekit.agents.utils import is_given
|
|
22
22
|
|
|
23
23
|
from .log import logger
|
|
24
|
-
from .utils import
|
|
24
|
+
from .utils import to_fnc_ctx
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
@dataclass
|
|
@@ -206,7 +206,7 @@ class LLMStream(llm.LLMStream):
|
|
|
206
206
|
stream: openai.AsyncStream[
|
|
207
207
|
ChatCompletionChunk
|
|
208
208
|
] = await self._client.chat.completions.create(
|
|
209
|
-
messages=
|
|
209
|
+
messages=self._chat_ctx.to_provider_format(format="openai")[0],
|
|
210
210
|
tools=to_fnc_ctx(self._tools) if self._tools else openai.NOT_GIVEN,
|
|
211
211
|
model=self._model,
|
|
212
212
|
stream_options={"include_usage": True},
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from collections.abc import Sequence
|
|
5
|
+
from typing import Awaitable, Callable, Union, cast
|
|
6
|
+
|
|
7
|
+
from livekit.agents import llm
|
|
8
|
+
from openai.types.chat import ChatCompletionToolParam
|
|
9
|
+
|
|
10
|
+
AsyncAzureADTokenProvider = Callable[[], Union[str, Awaitable[str]]]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_base_url(base_url: str | None) -> str:
|
|
14
|
+
if not base_url:
|
|
15
|
+
base_url = os.getenv(
|
|
16
|
+
"VOLCENGINE_LLM_BASE_URL", "https://ark.cn-beijing.volces.com/api/v3"
|
|
17
|
+
)
|
|
18
|
+
return base_url
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def to_fnc_ctx(fnc_ctx: Sequence[llm.Tool]) -> list[ChatCompletionToolParam]:
|
|
22
|
+
return cast(
|
|
23
|
+
list[ChatCompletionToolParam],
|
|
24
|
+
llm.ToolContext(fnc_ctx).parse_function_tools("openai"),
|
|
25
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.3.5"
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import base64
|
|
4
|
-
import os
|
|
5
|
-
from collections import OrderedDict
|
|
6
|
-
from collections.abc import Awaitable, Sequence
|
|
7
|
-
from typing import Any, Callable, Union, cast
|
|
8
|
-
|
|
9
|
-
from openai.types.chat import (
|
|
10
|
-
ChatCompletionContentPartParam,
|
|
11
|
-
ChatCompletionMessageParam,
|
|
12
|
-
ChatCompletionToolParam,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
from livekit.agents import llm
|
|
16
|
-
|
|
17
|
-
AsyncAzureADTokenProvider = Callable[[], Union[str, Awaitable[str]]]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def get_base_url(base_url: str | None) -> str:
|
|
21
|
-
if not base_url:
|
|
22
|
-
base_url = os.getenv(
|
|
23
|
-
"VOLCENGINE_LLM_BASE_URL", "https://ark.cn-beijing.volces.com/api/v3"
|
|
24
|
-
)
|
|
25
|
-
return base_url
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def to_fnc_ctx(fnc_ctx: Sequence[llm.Tool]) -> list[ChatCompletionToolParam]:
|
|
29
|
-
return cast(
|
|
30
|
-
list[ChatCompletionToolParam],
|
|
31
|
-
llm.ToolContext(fnc_ctx).parse_function_tools("openai"),
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def to_chat_ctx(
|
|
36
|
-
chat_ctx: llm.ChatContext, cache_key: Any
|
|
37
|
-
) -> list[ChatCompletionMessageParam]:
|
|
38
|
-
# group the message and function_calls
|
|
39
|
-
item_groups: dict[str, list[llm.ChatItem]] = OrderedDict()
|
|
40
|
-
for item in chat_ctx.items:
|
|
41
|
-
if (
|
|
42
|
-
item.type == "message" and item.role == "assistant"
|
|
43
|
-
) or item.type == "function_call":
|
|
44
|
-
group_id = item.id.split("/")[0]
|
|
45
|
-
if group_id not in item_groups:
|
|
46
|
-
item_groups[group_id] = []
|
|
47
|
-
item_groups[group_id].append(item)
|
|
48
|
-
else:
|
|
49
|
-
item_groups[item.id] = [item]
|
|
50
|
-
|
|
51
|
-
return [_group_to_chat_item(items, cache_key) for items in item_groups.values()]
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def _group_to_chat_item(
|
|
55
|
-
items: list[llm.ChatItem], cache_key: Any
|
|
56
|
-
) -> ChatCompletionMessageParam:
|
|
57
|
-
if len(items) == 1:
|
|
58
|
-
return _to_chat_item(items[0], cache_key)
|
|
59
|
-
else:
|
|
60
|
-
msg = {"role": "assistant", "tool_calls": []}
|
|
61
|
-
for item in items:
|
|
62
|
-
if item.type == "message":
|
|
63
|
-
assert item.role == "assistant", (
|
|
64
|
-
"only assistant messages can be grouped"
|
|
65
|
-
)
|
|
66
|
-
assert "content" not in msg, (
|
|
67
|
-
"only one assistant message is allowed in a group"
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
msg.update(_to_chat_item(item, cache_key))
|
|
71
|
-
elif item.type == "function_call":
|
|
72
|
-
msg["tool_calls"].append(
|
|
73
|
-
{
|
|
74
|
-
"id": item.call_id,
|
|
75
|
-
"type": "function",
|
|
76
|
-
"function": {"name": item.name, "arguments": item.arguments},
|
|
77
|
-
}
|
|
78
|
-
)
|
|
79
|
-
return msg
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def _to_chat_item(msg: llm.ChatItem, cache_key: Any) -> ChatCompletionMessageParam:
|
|
83
|
-
if msg.type == "message":
|
|
84
|
-
list_content: list[ChatCompletionContentPartParam] = []
|
|
85
|
-
text_content = ""
|
|
86
|
-
for content in msg.content:
|
|
87
|
-
if isinstance(content, str):
|
|
88
|
-
if text_content:
|
|
89
|
-
text_content += "\n"
|
|
90
|
-
text_content += content
|
|
91
|
-
elif isinstance(content, llm.ImageContent):
|
|
92
|
-
list_content.append(_to_image_content(content, cache_key))
|
|
93
|
-
|
|
94
|
-
if not list_content:
|
|
95
|
-
# certain providers require text-only content in a string vs a list.
|
|
96
|
-
# for max-compatibility, we will combine all text content into a single string.
|
|
97
|
-
return {
|
|
98
|
-
"role": msg.role, # type: ignore
|
|
99
|
-
"content": text_content,
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if text_content:
|
|
103
|
-
list_content.append({"type": "text", "text": text_content})
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
"role": msg.role, # type: ignore
|
|
107
|
-
"content": list_content,
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
elif msg.type == "function_call":
|
|
111
|
-
return {
|
|
112
|
-
"role": "assistant",
|
|
113
|
-
"tool_calls": [
|
|
114
|
-
{
|
|
115
|
-
"id": msg.call_id,
|
|
116
|
-
"type": "function",
|
|
117
|
-
"function": {
|
|
118
|
-
"name": msg.name,
|
|
119
|
-
"arguments": msg.arguments,
|
|
120
|
-
},
|
|
121
|
-
}
|
|
122
|
-
],
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
elif msg.type == "function_call_output":
|
|
126
|
-
return {
|
|
127
|
-
"role": "tool",
|
|
128
|
-
"tool_call_id": msg.call_id,
|
|
129
|
-
"content": msg.output,
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
def _to_image_content(
|
|
134
|
-
image: llm.ImageContent, cache_key: Any
|
|
135
|
-
) -> ChatCompletionContentPartParam:
|
|
136
|
-
img = llm.utils.serialize_image(image)
|
|
137
|
-
if img.external_url:
|
|
138
|
-
return {
|
|
139
|
-
"type": "image_url",
|
|
140
|
-
"image_url": {
|
|
141
|
-
"url": img.external_url,
|
|
142
|
-
"detail": img.inference_detail,
|
|
143
|
-
},
|
|
144
|
-
}
|
|
145
|
-
if cache_key not in image._cache:
|
|
146
|
-
image._cache[cache_key] = img.data_bytes
|
|
147
|
-
b64_data = base64.b64encode(image._cache[cache_key]).decode("utf-8")
|
|
148
|
-
return {
|
|
149
|
-
"type": "image_url",
|
|
150
|
-
"image_url": {
|
|
151
|
-
"url": f"data:{img.mime_type};base64,{b64_data}",
|
|
152
|
-
"detail": img.inference_detail,
|
|
153
|
-
},
|
|
154
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "1.3.4"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|