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