Skip to content

Commit

Permalink
readme update with data streaming example
Browse files Browse the repository at this point in the history
  • Loading branch information
morisil committed Sep 30, 2024
1 parent 2e3041a commit 641ded9
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@ me to write AI code once, and target all the platforms automatically.

## Usage

The simplest code would look like:
_:warning: This SDK is in the early stage of development, but at the same time it is completely functional and passing
[test cases](src/commonTest/kotlin)._

Add to your `build.gradle.kts`:

```kotlin
dependencies {
implementation("com.xemantic.anthropic:anthropic-sdk-kotlin:0.1-SNAPSHOT")
}
```

The simplest code look like:

```kotlin
fun main() {
Expand All @@ -58,7 +69,28 @@ fun main() {
}
```

This SDK is in an early stage o development, but at the same time it is completely functional and passing
live test cases.
Streaming is also possible:

```kotlin
fun main() {
val client = Anthropic()
val pong = runBlocking {
client.messages.stream {
+Message {
role = Role.USER
+"ping!"
}
}
.filterIsInstance<ContentBlockDelta>()
.map { (it.delta as TextDelta).text }
.toList()
.joinToString(separator = "")
}
println(pong)
}
```

More examples coming soon.
More sophisticated code examples targeting various
platforms will follow in the
[anthropic-sdk-kotlin-demo](https://github.com/xemantic/anthropic-sdk-kotlin-demo)
project.

0 comments on commit 641ded9

Please sign in to comment.