aidial-adapter-anthropic 0.1.0__tar.gz → 0.1.0rc0__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.
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/PKG-INFO +1 -1
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_claude/adapter.py +7 -5
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_claude/blocks.py +4 -20
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_claude/citations.py +4 -4
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/dial/consumer.py +62 -2
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/pyproject.toml +1 -1
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/LICENSE +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/README.md +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/_utils/json.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/_utils/list.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/_utils/pydantic.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/_utils/resource.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/_utils/text.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/__init__.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_base.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_claude/config.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_claude/converters.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_claude/params.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_claude/state.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_claude/tokenizer/__init__.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_claude/tokenizer/anthropic.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_claude/tokenizer/approximate.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_claude/tokenizer/base.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_claude/tools.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_decorator/base.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_decorator/preprocess.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_decorator/replicator.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_errors.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_tokenize.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/_truncate_prompt.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/adapter/claude.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/dial/_attachments.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/dial/_lazy_stage.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/dial/_message.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/dial/request.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/dial/resource.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/dial/storage.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/dial/token_usage.py +0 -0
- {aidial_adapter_anthropic-0.1.0 → aidial_adapter_anthropic-0.1.0rc0}/aidial_adapter_anthropic/dial/tools.py +0 -0
|
@@ -88,7 +88,7 @@ from aidial_adapter_anthropic.adapter._base import (
|
|
|
88
88
|
from aidial_adapter_anthropic.adapter._claude.blocks import (
|
|
89
89
|
IMAGE_ATTACHMENT_PROCESSOR,
|
|
90
90
|
PDF_ATTACHMENT_PROCESSOR,
|
|
91
|
-
|
|
91
|
+
TEXT_ATTACHMENT_PROCESSOR,
|
|
92
92
|
create_text_block,
|
|
93
93
|
)
|
|
94
94
|
from aidial_adapter_anthropic.adapter._claude.citations import create_citations
|
|
@@ -227,7 +227,7 @@ class Adapter(ChatCompletionAdapter):
|
|
|
227
227
|
def attachment_processors(self) -> AttachmentProcessors:
|
|
228
228
|
# Document support: https://docs.anthropic.com/en/docs/build-with-claude/pdf-support#supported-platforms-and-models
|
|
229
229
|
document_processors = (
|
|
230
|
-
[PDF_ATTACHMENT_PROCESSOR,
|
|
230
|
+
[PDF_ATTACHMENT_PROCESSOR, TEXT_ATTACHMENT_PROCESSOR]
|
|
231
231
|
if self.supports_documents
|
|
232
232
|
else []
|
|
233
233
|
)
|
|
@@ -426,8 +426,10 @@ class Adapter(ChatCompletionAdapter):
|
|
|
426
426
|
case TextBlock(citations=citations):
|
|
427
427
|
# The text content is already handled in TextEvent handler.
|
|
428
428
|
for citation in citations or []:
|
|
429
|
-
create_citations(
|
|
430
|
-
consumer,
|
|
429
|
+
await create_citations(
|
|
430
|
+
consumer,
|
|
431
|
+
request.get_resource,
|
|
432
|
+
citation,
|
|
431
433
|
)
|
|
432
434
|
case ToolUseBlock():
|
|
433
435
|
# Tool Use is processed in ContentBlockStartEvent and InputJsonEvent handlers
|
|
@@ -506,7 +508,7 @@ class Adapter(ChatCompletionAdapter):
|
|
|
506
508
|
case TextBlock(text=text, citations=citations):
|
|
507
509
|
consumer.append_content(text)
|
|
508
510
|
for citation in citations or []:
|
|
509
|
-
create_citations(
|
|
511
|
+
await create_citations(
|
|
510
512
|
consumer, request.get_resource, citation
|
|
511
513
|
)
|
|
512
514
|
case ToolUseBlock():
|
|
@@ -50,7 +50,7 @@ def create_text_document_block(
|
|
|
50
50
|
return RequestDocumentBlockParam(
|
|
51
51
|
source=PlainTextSourceParam(
|
|
52
52
|
data=resource.data.decode("utf-8"),
|
|
53
|
-
media_type=
|
|
53
|
+
media_type=resource.type, # type: ignore
|
|
54
54
|
type="text",
|
|
55
55
|
),
|
|
56
56
|
type="document",
|
|
@@ -64,7 +64,7 @@ def create_pdf_document_block(
|
|
|
64
64
|
return RequestDocumentBlockParam(
|
|
65
65
|
source=Base64PDFSourceParam(
|
|
66
66
|
data=resource.data_base64,
|
|
67
|
-
media_type=
|
|
67
|
+
media_type=resource.type, # type: ignore
|
|
68
68
|
type="base64",
|
|
69
69
|
),
|
|
70
70
|
type="document",
|
|
@@ -106,23 +106,7 @@ PDF_ATTACHMENT_PROCESSOR = AttachmentProcessor(
|
|
|
106
106
|
handler=create_pdf_document_block,
|
|
107
107
|
)
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
supported_types={
|
|
111
|
-
"text/plain": {"txt"},
|
|
112
|
-
"text/html": {"html", "htm"},
|
|
113
|
-
"text/css": {"css"},
|
|
114
|
-
"text/javascript": {"js"},
|
|
115
|
-
"application/x-javascript": {"js"},
|
|
116
|
-
"text/x-typescript": {"ts"},
|
|
117
|
-
"application/x-typescript": {"ts"},
|
|
118
|
-
"text/csv": {"csv"},
|
|
119
|
-
"text/markdown": {"md"},
|
|
120
|
-
"text/x-python": {"py"},
|
|
121
|
-
"application/x-python-code": {"py"},
|
|
122
|
-
"application/json": {"json"},
|
|
123
|
-
"text/xml": {"xml"},
|
|
124
|
-
"application/rtf": {"rtf"},
|
|
125
|
-
"text/rtf": {"rtf"},
|
|
126
|
-
},
|
|
109
|
+
TEXT_ATTACHMENT_PROCESSOR = AttachmentProcessor(
|
|
110
|
+
supported_types={"text/plain": {"txt"}},
|
|
127
111
|
handler=create_text_document_block,
|
|
128
112
|
)
|
|
@@ -21,7 +21,7 @@ from aidial_adapter_anthropic.dial.consumer import Consumer
|
|
|
21
21
|
from aidial_adapter_anthropic.dial.resource import DialResource
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
def _add_document_citation(
|
|
24
|
+
async def _add_document_citation(
|
|
25
25
|
consumer: Consumer,
|
|
26
26
|
get_document: Callable[[int], DialResource | None],
|
|
27
27
|
document_index: int,
|
|
@@ -31,7 +31,7 @@ def _add_document_citation(
|
|
|
31
31
|
|
|
32
32
|
# NOTE: multiple citations to the same document are merged into one citation
|
|
33
33
|
# until we find a better API to handle citations embedded in text.
|
|
34
|
-
display_index = consumer.add_citation_attachment(
|
|
34
|
+
display_index = await consumer.add_citation_attachment(
|
|
35
35
|
document_id=document_index, document=document
|
|
36
36
|
)
|
|
37
37
|
|
|
@@ -40,7 +40,7 @@ def _add_document_citation(
|
|
|
40
40
|
consumer.append_content(f"[{display_index}]")
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
def create_citations(
|
|
43
|
+
async def create_citations(
|
|
44
44
|
consumer: Consumer,
|
|
45
45
|
get_document: Callable[[int], DialResource | None],
|
|
46
46
|
citation: TextCitation,
|
|
@@ -49,7 +49,7 @@ def create_citations(
|
|
|
49
49
|
case CitationCharLocation(
|
|
50
50
|
document_index=document_index
|
|
51
51
|
) | CitationPageLocation(document_index=document_index):
|
|
52
|
-
_add_document_citation(consumer, get_document, document_index)
|
|
52
|
+
await _add_document_citation(consumer, get_document, document_index)
|
|
53
53
|
|
|
54
54
|
# Custom document aren't supported yet
|
|
55
55
|
case CitationContentBlockLocation():
|
|
@@ -57,7 +57,7 @@ class Consumer(ContextManager, ABC):
|
|
|
57
57
|
def add_attachment(self, attachment: Attachment): ...
|
|
58
58
|
|
|
59
59
|
@abstractmethod
|
|
60
|
-
def add_citation_attachment(
|
|
60
|
+
async def add_citation_attachment(
|
|
61
61
|
self, document_id: int, document: Attachment | None
|
|
62
62
|
) -> int: ...
|
|
63
63
|
|
|
@@ -169,7 +169,7 @@ class ChoiceConsumer(Consumer):
|
|
|
169
169
|
def add_attachment(self, attachment: Attachment):
|
|
170
170
|
self.choice.add_attachment(attachment)
|
|
171
171
|
|
|
172
|
-
def add_citation_attachment(
|
|
172
|
+
async def add_citation_attachment(
|
|
173
173
|
self, document_id: int, document: Attachment | None
|
|
174
174
|
) -> int:
|
|
175
175
|
if document_id in self._citations:
|
|
@@ -233,3 +233,63 @@ class ChoiceConsumer(Consumer):
|
|
|
233
233
|
@property
|
|
234
234
|
def has_function_call(self) -> bool:
|
|
235
235
|
return self._choice is not None and self._choice.has_function_call
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
class ConsumerDecorator(Consumer):
|
|
239
|
+
consumer: Consumer
|
|
240
|
+
|
|
241
|
+
def __init__(self, consumer: Consumer):
|
|
242
|
+
self.consumer = consumer
|
|
243
|
+
|
|
244
|
+
def __enter__(self) -> Consumer:
|
|
245
|
+
return self.consumer.__enter__()
|
|
246
|
+
|
|
247
|
+
def __exit__(
|
|
248
|
+
self,
|
|
249
|
+
exc_type: type[BaseException] | None,
|
|
250
|
+
exc: BaseException | None,
|
|
251
|
+
traceback: TracebackType | None,
|
|
252
|
+
) -> bool | None:
|
|
253
|
+
return self.consumer.__exit__(exc_type, exc, traceback)
|
|
254
|
+
|
|
255
|
+
def fork(self) -> Consumer:
|
|
256
|
+
return self.consumer.fork()
|
|
257
|
+
|
|
258
|
+
@property
|
|
259
|
+
def choice(self) -> Choice:
|
|
260
|
+
return self.consumer.choice
|
|
261
|
+
|
|
262
|
+
def close_content(self, finish_reason: FinishReason | None = None):
|
|
263
|
+
self.consumer.close_content(finish_reason)
|
|
264
|
+
|
|
265
|
+
def append_content(self, content: str):
|
|
266
|
+
self.consumer.append_content(content)
|
|
267
|
+
|
|
268
|
+
def add_attachment(self, attachment: Attachment):
|
|
269
|
+
self.consumer.add_attachment(attachment)
|
|
270
|
+
|
|
271
|
+
async def add_citation_attachment(self, document_id, document):
|
|
272
|
+
return await self.consumer.add_citation_attachment(
|
|
273
|
+
document_id, document
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
def add_usage(self, usage: TokenUsage):
|
|
277
|
+
self.consumer.add_usage(usage)
|
|
278
|
+
|
|
279
|
+
def set_discarded_messages(
|
|
280
|
+
self, discarded_messages: Optional[DiscardedMessages]
|
|
281
|
+
):
|
|
282
|
+
self.consumer.set_discarded_messages(discarded_messages)
|
|
283
|
+
|
|
284
|
+
def get_discarded_messages(self) -> Optional[DiscardedMessages]:
|
|
285
|
+
return self.consumer.get_discarded_messages()
|
|
286
|
+
|
|
287
|
+
def create_function_tool_call(self, call: ToolCall) -> ToolUseMessage:
|
|
288
|
+
return self.consumer.create_function_tool_call(call)
|
|
289
|
+
|
|
290
|
+
def create_function_call(self, call: FunctionCall) -> ToolUseMessage:
|
|
291
|
+
return self.consumer.create_function_call(call)
|
|
292
|
+
|
|
293
|
+
@property
|
|
294
|
+
def has_function_call(self) -> bool:
|
|
295
|
+
return self.consumer.has_function_call
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "aidial-adapter-anthropic"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.0rc"
|
|
4
4
|
description = "Package implementing adapter from DIAL Chat Completions API to Anthropic API"
|
|
5
5
|
authors = [{ name = "EPAM RAIL", email = "SpecialEPM-DIALDevTeam@epam.com" }]
|
|
6
6
|
license = "Apache-2.0"
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|