llmir 0.0.8__tar.gz → 0.0.10__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.8 → llmir-0.0.10}/PKG-INFO +1 -1
- {llmir-0.0.8 → llmir-0.0.10}/llmir/adapter/__init__.py +4 -4
- {llmir-0.0.8 → llmir-0.0.10}/llmir/adapter/openai.py +41 -28
- {llmir-0.0.8 → llmir-0.0.10}/llmir.egg-info/PKG-INFO +1 -1
- {llmir-0.0.8 → llmir-0.0.10}/pyproject.toml +1 -1
- {llmir-0.0.8 → llmir-0.0.10}/README.md +0 -0
- {llmir-0.0.8 → llmir-0.0.10}/llmir/__init__.py +0 -0
- {llmir-0.0.8 → llmir-0.0.10}/llmir/chunks.py +0 -0
- {llmir-0.0.8 → llmir-0.0.10}/llmir/messages.py +0 -0
- {llmir-0.0.8 → llmir-0.0.10}/llmir/py.typed +0 -0
- {llmir-0.0.8 → llmir-0.0.10}/llmir/rich_repr.py +0 -0
- {llmir-0.0.8 → llmir-0.0.10}/llmir/roles.py +0 -0
- {llmir-0.0.8 → llmir-0.0.10}/llmir/tools.py +0 -0
- {llmir-0.0.8 → llmir-0.0.10}/llmir.egg-info/SOURCES.txt +0 -0
- {llmir-0.0.8 → llmir-0.0.10}/llmir.egg-info/dependency_links.txt +0 -0
- {llmir-0.0.8 → llmir-0.0.10}/llmir.egg-info/requires.txt +0 -0
- {llmir-0.0.8 → llmir-0.0.10}/llmir.egg-info/top_level.txt +0 -0
- {llmir-0.0.8 → llmir-0.0.10}/setup.cfg +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from .openai import to_openai, OpenAIMessages, OpenAIMessage, OpenAIMessageToolResponse, OpenAIContents,
|
|
1
|
+
from .openai import to_openai, OpenAIMessages, OpenAIMessage, OpenAIMessageToolResponse, OpenAIContents, OpenAIText, OpenAIImageURL, OpenAIImageURLURL, OpenAIToolCall, OpenAIToolCallFunction
|
|
2
2
|
|
|
3
3
|
__all__ = [
|
|
4
4
|
"to_openai",
|
|
@@ -6,9 +6,9 @@ __all__ = [
|
|
|
6
6
|
"OpenAIMessage",
|
|
7
7
|
"OpenAIMessageToolResponse",
|
|
8
8
|
"OpenAIContents",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
9
|
+
"OpenAIText",
|
|
10
|
+
"OpenAIImageURL",
|
|
11
11
|
"OpenAIImageURLURL",
|
|
12
|
-
"
|
|
12
|
+
"OpenAIToolCall",
|
|
13
13
|
"OpenAIToolCallFunction",
|
|
14
14
|
]
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
from typing import TypedDict, Literal
|
|
1
|
+
from typing import TypedDict, Literal, Required
|
|
2
2
|
|
|
3
3
|
from ..messages import AIMessages, AIMessageToolResponse
|
|
4
|
-
from ..chunks import
|
|
4
|
+
from ..chunks import AIChunkText, AIChunkImageURL, AIChunkFile, AIChunkToolCall
|
|
5
5
|
import base64
|
|
6
6
|
import json
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class OpenAIText(TypedDict):
|
|
10
10
|
type: Literal["text"]
|
|
11
11
|
text: str
|
|
12
12
|
|
|
13
13
|
class OpenAIImageURLURL(TypedDict):
|
|
14
14
|
url: str
|
|
15
15
|
|
|
16
|
-
class
|
|
16
|
+
class OpenAIImageURL(TypedDict):
|
|
17
17
|
type: Literal["image_url"]
|
|
18
18
|
image_url: OpenAIImageURLURL
|
|
19
19
|
|
|
@@ -22,22 +22,23 @@ class OpenAIToolCallFunction(TypedDict):
|
|
|
22
22
|
name: str
|
|
23
23
|
arguments: str
|
|
24
24
|
|
|
25
|
-
class
|
|
25
|
+
class OpenAIToolCall(TypedDict):
|
|
26
26
|
id: str
|
|
27
27
|
type: Literal["function"]
|
|
28
28
|
function: OpenAIToolCallFunction
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
OpenAIContents =
|
|
32
|
+
OpenAIContents = OpenAIText | OpenAIImageURL
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
class OpenAIMessage(TypedDict):
|
|
36
|
-
role: str
|
|
35
|
+
class OpenAIMessage(TypedDict, total=False):
|
|
36
|
+
role: Required[str]
|
|
37
37
|
content: list[OpenAIContents]
|
|
38
|
+
tool_calls: list[OpenAIToolCall]
|
|
38
39
|
|
|
39
|
-
class OpenAIMessageToolResponse(TypedDict):
|
|
40
|
-
role: Literal["tool"]
|
|
40
|
+
class OpenAIMessageToolResponse(TypedDict, total=False):
|
|
41
|
+
role: Required[Literal["tool"]]
|
|
41
42
|
tool_call_id: str
|
|
42
43
|
content: str
|
|
43
44
|
|
|
@@ -75,30 +76,40 @@ def to_openai(messages: list[AIMessages]) -> list[OpenAIMessages]:
|
|
|
75
76
|
OpenAIMessage(
|
|
76
77
|
role="user", # Hacky, but what else to circumvent API limitations in a broadly compatible way?
|
|
77
78
|
content=[
|
|
78
|
-
|
|
79
|
-
]
|
|
79
|
+
content_chunk_to_openai(chunk) for chunk in media_chunks
|
|
80
|
+
],
|
|
80
81
|
)
|
|
81
82
|
)
|
|
82
83
|
else:
|
|
83
|
-
|
|
84
|
-
role=
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
formatted = OpenAIMessage(
|
|
85
|
+
role=role
|
|
86
|
+
)
|
|
87
|
+
content: list[OpenAIContents] = [
|
|
88
|
+
content_chunk_to_openai(chunk) for chunk in message.chunks if not isinstance(chunk, AIChunkToolCall)
|
|
89
|
+
]
|
|
90
|
+
tool_calls: list[OpenAIToolCall] = [
|
|
91
|
+
tool_call_chunk_to_openai(chunk) for chunk in message.chunks if isinstance(chunk, AIChunkToolCall)
|
|
92
|
+
]
|
|
93
|
+
if content:
|
|
94
|
+
formatted["content"] = content
|
|
95
|
+
if tool_calls:
|
|
96
|
+
formatted["tool_calls"] = tool_calls
|
|
97
|
+
|
|
98
|
+
result.append(formatted)
|
|
99
|
+
|
|
89
100
|
return result
|
|
90
101
|
|
|
91
102
|
|
|
92
|
-
def
|
|
103
|
+
def content_chunk_to_openai(chunk: AIChunkText | AIChunkFile | AIChunkImageURL) -> OpenAIContents:
|
|
93
104
|
|
|
94
105
|
match chunk:
|
|
95
106
|
case AIChunkText():
|
|
96
|
-
return
|
|
107
|
+
return OpenAIText(
|
|
97
108
|
type="text",
|
|
98
109
|
text=chunk.text,
|
|
99
110
|
)
|
|
100
111
|
case AIChunkImageURL():
|
|
101
|
-
return
|
|
112
|
+
return OpenAIImageURL(
|
|
102
113
|
type="image_url",
|
|
103
114
|
image_url={
|
|
104
115
|
"url": chunk.url,
|
|
@@ -107,7 +118,7 @@ def chunk_to_openai(chunk: AIChunks) -> OpenAIContents:
|
|
|
107
118
|
case AIChunkFile():
|
|
108
119
|
if chunk.mimetype.startswith("image/"):
|
|
109
120
|
base64_data = base64.b64encode(chunk.bytes).decode('utf-8')
|
|
110
|
-
return
|
|
121
|
+
return OpenAIImageURL(
|
|
111
122
|
type= "image_url",
|
|
112
123
|
image_url= {
|
|
113
124
|
"url": f"data:{chunk.mimetype};base64,{base64_data}",
|
|
@@ -115,20 +126,22 @@ def chunk_to_openai(chunk: AIChunks) -> OpenAIContents:
|
|
|
115
126
|
)
|
|
116
127
|
elif chunk.mimetype == "text/plain":
|
|
117
128
|
text = chunk.bytes.decode(encoding="utf-8")
|
|
118
|
-
return
|
|
129
|
+
return OpenAIText(
|
|
119
130
|
type="text",
|
|
120
131
|
text=text
|
|
121
132
|
)
|
|
122
133
|
else:
|
|
123
134
|
raise ValueError(f"Unsupported file type for OpenAI: {chunk.mimetype}")
|
|
124
|
-
case
|
|
125
|
-
|
|
135
|
+
case _:
|
|
136
|
+
raise ValueError(f"Unsupported chunk type: {type(chunk)}")
|
|
137
|
+
|
|
138
|
+
def tool_call_chunk_to_openai(chunk: AIChunkToolCall) -> OpenAIToolCall:
|
|
139
|
+
|
|
140
|
+
return OpenAIToolCall(
|
|
126
141
|
id=chunk.id,
|
|
127
142
|
type="function",
|
|
128
143
|
function=OpenAIToolCallFunction(
|
|
129
144
|
name=chunk.name,
|
|
130
145
|
arguments=json.dumps(chunk.arguments)
|
|
131
146
|
)
|
|
132
|
-
)
|
|
133
|
-
case _:
|
|
134
|
-
raise ValueError(f"Unsupported chunk type: {type(chunk)}")
|
|
147
|
+
)
|
|
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
|