llmir 0.0.8__py3-none-any.whl → 0.0.9__py3-none-any.whl

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/adapter/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- from .openai import to_openai, OpenAIMessages, OpenAIMessage, OpenAIMessageToolResponse, OpenAIContents, OpenAITextContent, OpenAIImageURLContent, OpenAIImageURLURL, OpenAIToolCallContent, OpenAIToolCallFunction
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
- "OpenAITextContent",
10
- "OpenAIImageURLContent",
9
+ "OpenAIText",
10
+ "OpenAIImageURL",
11
11
  "OpenAIImageURLURL",
12
- "OpenAIToolCallContent",
12
+ "OpenAIToolCall",
13
13
  "OpenAIToolCallFunction",
14
14
  ]
llmir/adapter/openai.py CHANGED
@@ -1,19 +1,19 @@
1
1
  from typing import TypedDict, Literal
2
2
 
3
3
  from ..messages import AIMessages, AIMessageToolResponse
4
- from ..chunks import AIChunks, AIChunkText, AIChunkImageURL, AIChunkFile, AIChunkToolCall
4
+ from ..chunks import AIChunkText, AIChunkImageURL, AIChunkFile, AIChunkToolCall
5
5
  import base64
6
6
  import json
7
7
 
8
8
 
9
- class OpenAITextContent(TypedDict):
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 OpenAIImageURLContent(TypedDict):
16
+ class OpenAIImageURL(TypedDict):
17
17
  type: Literal["image_url"]
18
18
  image_url: OpenAIImageURLURL
19
19
 
@@ -22,19 +22,20 @@ class OpenAIToolCallFunction(TypedDict):
22
22
  name: str
23
23
  arguments: str
24
24
 
25
- class OpenAIToolCallContent(TypedDict):
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 = OpenAITextContent | OpenAIImageURLContent | OpenAIToolCallContent
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"]
@@ -75,30 +76,34 @@ 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
- chunk_to_openai(chunk) for chunk in media_chunks
79
- ]
79
+ content_chunk_to_openai(chunk) for chunk in media_chunks
80
+ ],
81
+ tool_calls=[]
80
82
  )
81
83
  )
82
84
  else:
83
85
  result.append(OpenAIMessage(
84
86
  role= role,
85
- content= [
86
- chunk_to_openai(chunk) for chunk in message.chunks
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)
87
92
  ]
88
93
  ))
89
94
  return result
90
95
 
91
96
 
92
- def chunk_to_openai(chunk: AIChunks) -> OpenAIContents:
97
+ def content_chunk_to_openai(chunk: AIChunkText | AIChunkFile | AIChunkImageURL) -> OpenAIContents:
93
98
 
94
99
  match chunk:
95
100
  case AIChunkText():
96
- return OpenAITextContent(
101
+ return OpenAIText(
97
102
  type="text",
98
103
  text=chunk.text,
99
104
  )
100
105
  case AIChunkImageURL():
101
- return OpenAIImageURLContent(
106
+ return OpenAIImageURL(
102
107
  type="image_url",
103
108
  image_url={
104
109
  "url": chunk.url,
@@ -107,7 +112,7 @@ def chunk_to_openai(chunk: AIChunks) -> OpenAIContents:
107
112
  case AIChunkFile():
108
113
  if chunk.mimetype.startswith("image/"):
109
114
  base64_data = base64.b64encode(chunk.bytes).decode('utf-8')
110
- return OpenAIImageURLContent(
115
+ return OpenAIImageURL(
111
116
  type= "image_url",
112
117
  image_url= {
113
118
  "url": f"data:{chunk.mimetype};base64,{base64_data}",
@@ -115,20 +120,22 @@ def chunk_to_openai(chunk: AIChunks) -> OpenAIContents:
115
120
  )
116
121
  elif chunk.mimetype == "text/plain":
117
122
  text = chunk.bytes.decode(encoding="utf-8")
118
- return OpenAITextContent(
123
+ return OpenAIText(
119
124
  type="text",
120
125
  text=text
121
126
  )
122
127
  else:
123
128
  raise ValueError(f"Unsupported file type for OpenAI: {chunk.mimetype}")
124
- case AIChunkToolCall():
125
- return OpenAIToolCallContent(
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(
126
135
  id=chunk.id,
127
136
  type="function",
128
137
  function=OpenAIToolCallFunction(
129
138
  name=chunk.name,
130
139
  arguments=json.dumps(chunk.arguments)
131
140
  )
132
- )
133
- case _:
134
- raise ValueError(f"Unsupported chunk type: {type(chunk)}")
141
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: llmir
3
- Version: 0.0.8
3
+ Version: 0.0.9
4
4
  Summary: Core message and tool IR for LLM pipelines
5
5
  Author: Mathis Siebert
6
6
  Requires-Python: >=3.11
@@ -5,9 +5,9 @@ llmir/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  llmir/rich_repr.py,sha256=ZGAfpcPkYJSUpFdir8B1MoORVFBSzVckCrRHVVkJIj4,559
6
6
  llmir/roles.py,sha256=B9PmxTHAb8XoiA9en_J1yIP19woddzx4SRUz5XkUxFc,133
7
7
  llmir/tools.py,sha256=fpkC3IafHqZJnwo7imtHdkTdGLBHQuR6DtdztXZrlWg,147
8
- llmir/adapter/__init__.py,sha256=UWfxC24Yll1GBataj4Aur_6RsdQwHQ1fV4ycTUhu7OA,479
9
- llmir/adapter/openai.py,sha256=cRgX-pKyfNx8sFrC9afgVx4phKpbx3YODfUQA7vp-oA,4114
10
- llmir-0.0.8.dist-info/METADATA,sha256=92pI6hxaAZVHEbqmtuwfgOECkap7N_Z3vgtSa84l7jE,177
11
- llmir-0.0.8.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
12
- llmir-0.0.8.dist-info/top_level.txt,sha256=fm538OsNUSYa_71IPztSSN2PBCvcbaD5PmUIzaO5hQs,6
13
- llmir-0.0.8.dist-info/RECORD,,
8
+ llmir/adapter/__init__.py,sha256=6yYVuYUXWiPPx5-v9PdSojEEw0TSFKz_4ELK9ntpRCw,437
9
+ llmir/adapter/openai.py,sha256=lnVhidU5FCivZ_mmFQNXAs9Hlfr7KA1Zv-OF4wjvXa8,4396
10
+ llmir-0.0.9.dist-info/METADATA,sha256=UChge1sU00JhSXv1QlTM4McfwnMF73j1xphw1zkFI2Y,177
11
+ llmir-0.0.9.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
12
+ llmir-0.0.9.dist-info/top_level.txt,sha256=fm538OsNUSYa_71IPztSSN2PBCvcbaD5PmUIzaO5hQs,6
13
+ llmir-0.0.9.dist-info/RECORD,,
File without changes