llmir 0.0.10__tar.gz → 0.0.11__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.
- {llmir-0.0.10 → llmir-0.0.11}/PKG-INFO +1 -1
- {llmir-0.0.10 → llmir-0.0.11}/llmir/adapter/openai.py +56 -12
- {llmir-0.0.10 → llmir-0.0.11}/llmir.egg-info/PKG-INFO +1 -1
- {llmir-0.0.10 → llmir-0.0.11}/pyproject.toml +1 -1
- {llmir-0.0.10 → llmir-0.0.11}/README.md +0 -0
- {llmir-0.0.10 → llmir-0.0.11}/llmir/__init__.py +0 -0
- {llmir-0.0.10 → llmir-0.0.11}/llmir/adapter/__init__.py +0 -0
- {llmir-0.0.10 → llmir-0.0.11}/llmir/chunks.py +0 -0
- {llmir-0.0.10 → llmir-0.0.11}/llmir/messages.py +0 -0
- {llmir-0.0.10 → llmir-0.0.11}/llmir/py.typed +0 -0
- {llmir-0.0.10 → llmir-0.0.11}/llmir/rich_repr.py +0 -0
- {llmir-0.0.10 → llmir-0.0.11}/llmir/roles.py +0 -0
- {llmir-0.0.10 → llmir-0.0.11}/llmir/tools.py +0 -0
- {llmir-0.0.10 → llmir-0.0.11}/llmir.egg-info/SOURCES.txt +0 -0
- {llmir-0.0.10 → llmir-0.0.11}/llmir.egg-info/dependency_links.txt +0 -0
- {llmir-0.0.10 → llmir-0.0.11}/llmir.egg-info/requires.txt +0 -0
- {llmir-0.0.10 → llmir-0.0.11}/llmir.egg-info/top_level.txt +0 -0
- {llmir-0.0.10 → llmir-0.0.11}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from typing import TypedDict, Literal, Required
|
|
2
2
|
|
|
3
|
-
from ..messages import AIMessages, AIMessageToolResponse
|
|
3
|
+
from ..messages import AIMessages, AIMessageToolResponse, AIRoles
|
|
4
4
|
from ..chunks import AIChunkText, AIChunkImageURL, AIChunkFile, AIChunkToolCall
|
|
5
5
|
import base64
|
|
6
6
|
import json
|
|
@@ -33,7 +33,7 @@ OpenAIContents = OpenAIText | OpenAIImageURL
|
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
class OpenAIMessage(TypedDict, total=False):
|
|
36
|
-
role: Required[
|
|
36
|
+
role: Required[Literal["system", "user", "assistant"]]
|
|
37
37
|
content: list[OpenAIContents]
|
|
38
38
|
tool_calls: list[OpenAIToolCall]
|
|
39
39
|
|
|
@@ -81,21 +81,65 @@ def to_openai(messages: list[AIMessages]) -> list[OpenAIMessages]:
|
|
|
81
81
|
)
|
|
82
82
|
)
|
|
83
83
|
else:
|
|
84
|
+
|
|
85
|
+
assert(role != "tool")
|
|
86
|
+
content_chunks: list[AIChunkText | AIChunkFile | AIChunkImageURL] = []
|
|
87
|
+
tool_call_chunks: list[AIChunkToolCall] = []
|
|
88
|
+
|
|
89
|
+
media_chunks: list[AIChunkFile | AIChunkImageURL] = []
|
|
90
|
+
|
|
91
|
+
for chunk in message.chunks:
|
|
92
|
+
|
|
93
|
+
if isinstance(chunk, AIChunkToolCall):
|
|
94
|
+
tool_call_chunks.append(chunk)
|
|
95
|
+
|
|
96
|
+
elif role != AIRoles.USER and not isinstance(chunk, AIChunkText):
|
|
97
|
+
media_chunks.append(chunk)
|
|
98
|
+
|
|
99
|
+
else:
|
|
100
|
+
content_chunks.append(chunk)
|
|
101
|
+
|
|
102
|
+
|
|
84
103
|
formatted = OpenAIMessage(
|
|
85
104
|
role=role
|
|
86
105
|
)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
result.append(
|
|
109
|
+
OpenAIMessage(
|
|
110
|
+
role=role,
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
if media_chunks:
|
|
114
|
+
result.append(
|
|
115
|
+
OpenAIMessage(
|
|
116
|
+
role="user", # Hacky, but what else to circumvent API limitations in a broadly compatible way?
|
|
117
|
+
content=[
|
|
118
|
+
content_chunk_to_openai(chunk) for chunk in media_chunks
|
|
119
|
+
],
|
|
120
|
+
)
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
formatted = OpenAIMessage(
|
|
126
|
+
role=role
|
|
127
|
+
)
|
|
128
|
+
if content_chunks:
|
|
129
|
+
formatted["content"] = [content_chunk_to_openai(c) for c in content_chunks]
|
|
130
|
+
if tool_call_chunks:
|
|
131
|
+
formatted["tool_calls"] = [tool_call_chunk_to_openai(c) for c in tool_call_chunks]
|
|
97
132
|
|
|
98
133
|
result.append(formatted)
|
|
134
|
+
|
|
135
|
+
if media_chunks:
|
|
136
|
+
result.append(OpenAIMessage(
|
|
137
|
+
role="user",
|
|
138
|
+
content=[
|
|
139
|
+
content_chunk_to_openai(c) for c in media_chunks
|
|
140
|
+
]
|
|
141
|
+
)
|
|
142
|
+
)
|
|
99
143
|
|
|
100
144
|
return result
|
|
101
145
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|