Skip to content

Commit

Permalink
feat: Add extensions on ToolResultBlockContent in anthropic_sdk_dart (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz committed Jul 2, 2024
1 parent 8ebeacd commit 8d92d9b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
20 changes: 20 additions & 0 deletions packages/anthropic_sdk_dart/lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ extension MessageContentX on MessageContent {
}
}

/// Extension methods for [ToolResultBlockContent].
extension ToolResultBlockContentX on ToolResultBlockContent {
/// Returns the text content of the tool result block content.
String get text {
return map(
text: (ToolResultBlockContentText t) => t.value,
blocks: (b) =>
b.value.whereType<TextBlock>().map((t) => t.text).join('\n'),
);
}

/// Returns the blocks of the tool result block content.
List<Block> get blocks {
return map(
text: (t) => [Block.text(text: t.value)],
blocks: (b) => b.value,
);
}
}

/// Extension methods for [Block].
extension BlockX on Block {
/// Returns the text content of the block.
Expand Down
15 changes: 13 additions & 2 deletions packages/langchain_anthropic/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# 🦜️🔗 LangChain.dart
# 🦜️🔗 LangChain.dart / Anthropic

Anthropic module for [LangChain.dart](https://github.com/davidmigloz/langchain_dart).
[![tests](https://img.shields.io/github/actions/workflow/status/davidmigloz/langchain_dart/test.yaml?logo=github&label=tests)](https://github.com/davidmigloz/langchain_dart/actions/workflows/test.yaml)
[![docs](https://img.shields.io/github/actions/workflow/status/davidmigloz/langchain_dart/pages%2Fpages-build-deployment?logo=github&label=docs)](https://github.com/davidmigloz/langchain_dart/actions/workflows/pages/pages-build-deployment)
[![langchain_anthropic](https://img.shields.io/pub/v/langchain_anthropic.svg)](https://pub.dev/packages/langchain_anthropic)
[![](https://dcbadge.vercel.app/api/server/x4qbhqecVR?style=flat)](https://discord.gg/x4qbhqecVR)
[![MIT](https://img.shields.io/badge/license-MIT-purple.svg)](https://github.com/davidmigloz/langchain_dart/blob/main/LICENSE)

[Anthropic](https://anthropic.com) module for [LangChain.dart](https://github.com/davidmigloz/langchain_dart).

## Features

- Chat models:
* `ChatAnthropic`: wrapper around [Anthropic Messages](https://docs.anthropic.com/en/api/messages) API (Claude).

## License

Expand Down

0 comments on commit 8d92d9b

Please sign in to comment.