Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 0.1.0-alpha.2 #30

Merged
merged 7 commits into from Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish-sonatype.yml
Expand Up @@ -30,7 +30,7 @@ jobs:

- name: Publish to Sonatype
run: |
./gradlew publish --stacktrace
./gradlew publishToMavenCentral --stacktrace -PmavenCentralUsername="$SONATYPE_USERNAME" -PmavenCentralPassword="$SONATYPE_PASSWORD"
env:
SONATYPE_USERNAME: ${{ secrets.LANG_SMITH_SONATYPE_USERNAME || secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.LANG_SMITH_SONATYPE_PASSWORD || secrets.SONATYPE_PASSWORD }}
Expand Down
Binary file modified .gradle/8.0.2/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/8.0.2/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.0.2/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/8.0.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/8.0.2/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion .release-please-manifest.json
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.1"
".": "0.1.0-alpha.2"
}
13 changes: 13 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,18 @@
# Changelog

## 0.1.0-alpha.2 (2024-03-22)

Full Changelog: [v0.1.0-alpha.1...v0.1.0-alpha.2](https://github.com/langchain-ai/langsmith-java/compare/v0.1.0-alpha.1...v0.1.0-alpha.2)

### Features

* do not inline example ([fa22fd7](https://github.com/langchain-ai/langsmith-java/commit/fa22fd702baaaaa6c1062c73571360210a63de5c))
* fix link ([c6b8b73](https://github.com/langchain-ai/langsmith-java/commit/c6b8b737b6214b717f747002f4f5f314ebce7fbb))
* update builder patterns, use end options ([33019db](https://github.com/langchain-ai/langsmith-java/commit/33019db58bbbb63590dacbecd60548ea3f76ebd3))
* update README ([aa6b46d](https://github.com/langchain-ai/langsmith-java/commit/aa6b46d44f8f7b15d342d7bb4defc566fd6f5369))
* updates ([eb0044a](https://github.com/langchain-ai/langsmith-java/commit/eb0044a2a4b0d7f90e9842eb7fa53503d7c85232))
* Use new sonatype publishing plugin ([d3f8fb2](https://github.com/langchain-ai/langsmith-java/commit/d3f8fb2c0931c78f9a830b3fd4d0a398e5c481f1))

## 0.1.0-alpha.1 (2024-03-19)

Full Changelog: [v0.0.1-alpha.0...v0.1.0-alpha.1](https://github.com/langchain-ai/langsmith-java/compare/v0.0.1-alpha.0...v0.1.0-alpha.1)
Expand Down
60 changes: 32 additions & 28 deletions README.md
@@ -1,18 +1,14 @@
# Lang Smith Java API Library

<!-- x-release-please-start-version -->

[![Maven Central](https://img.shields.io/maven-central/v/com.langsmith.api/langsmith-java)](https://central.sonatype.com/artifact/com.langsmith.api/langsmith-java/0.1.0-alpha.1)

<!-- x-release-please-end -->
[![Maven Central](https://img.shields.io/maven-central/v/com.langsmith.api/langsmith-java)](https://central.sonatype.com/artifact/com.langsmith.api/langsmith-java/0.0.1-alpha.0)

The Lang Smith Java SDK provides convenient access to the Lang Smith REST API from applications written in Java. It includes helper classes with helpful types and documentation for every request and response property.

The Lang Smith Java SDK is similar to the Lang Smith Kotlin SDK but with minor differences that make it more ergonomic for use in Java, such as `Optional` instead of nullable values, `Stream` instead of `Sequence`, and `CompletableFuture` instead of suspend functions.

## Documentation

The REST API documentation can be found [on docs.langsmith.com](https://docs.LangSmith.com).
The REST API documentation can be found [on docs.langsmith.com](https://api.smith.langchain.com/redoc).

---

Expand All @@ -22,10 +18,8 @@ The REST API documentation can be found [on docs.langsmith.com](https://docs.La

#### Gradle

<!-- x-release-please-start-version -->

```kotlin
implementation("com.langsmith.api:langsmith-java:0.1.0-alpha.1")
implementation("com.langsmith.api:langsmith-java:0.0.1-alpha.0")
```

#### Maven
Expand All @@ -34,12 +28,10 @@ implementation("com.langsmith.api:langsmith-java:0.1.0-alpha.1")
<dependency>
<groupId>com.langsmith.api</groupId>
<artifactId>langsmith-java</artifactId>
<version>0.1.0-alpha.1</version>
<version>0.0.1-alpha.0</version>
</dependency>
```

<!-- x-release-please-end -->

### Configure the client

Use `LangSmithOkHttpClient.builder()` to configure the client. At a minimum you need to set `.apiKey()`:
Expand Down Expand Up @@ -71,8 +63,20 @@ LangSmithClient client = LangSmithOkHttpClient.builder()

Read the documentation for more configuration options.

You can also set the `LANGCHAIN_PROJECT` to post runs to a specific project.
If unspecified, runs will be posted to the `default` project.

| Property | Environment variable | Required | Default value |
| -------- | -------------------- | -------- | ------------- |
| project | `LANGCHAIN_PROJECT` | false | — |

---

### Example: using the RunTree API (experimental)
The RunTree API is currently the recommended way to post runs to LangSmith.

See a full example in the [here](./examples/src/main/java/com/langsmith/example/OpenAiExample.java).

### Example: creating a resource

To create a new run, first use the `RunBatchParams` builder to specify attributes,
Expand Down Expand Up @@ -157,22 +161,22 @@ This library throws exceptions in a single hierarchy for easy handling:

- **`LangSmithException`** - Base exception for all exceptions

- **`LangSmithServiceException`** - HTTP errors with a well-formed response body we were able to parse. The exception message and the `.debuggingRequestId()` will be set by the server.

| 400 | BadRequestException |
| ------ | ----------------------------- |
| 401 | AuthenticationException |
| 403 | PermissionDeniedException |
| 404 | NotFoundException |
| 422 | UnprocessableEntityException |
| 429 | RateLimitException |
| 5xx | InternalServerException |
| others | UnexpectedStatusCodeException |

- **`LangSmithIoException`** - I/O networking errors
- **`LangSmithInvalidDataException`** - any other exceptions on the client side, e.g.:
- We failed to serialize the request body
- We failed to parse the response body (has access to response code and body)
- **`LangSmithServiceException`** - HTTP errors with a well-formed response body we were able to parse. The exception message and the `.debuggingRequestId()` will be set by the server.

| 400 | BadRequestException |
| ------ | ----------------------------- |
| 401 | AuthenticationException |
| 403 | PermissionDeniedException |
| 404 | NotFoundException |
| 422 | UnprocessableEntityException |
| 429 | RateLimitException |
| 5xx | InternalServerException |
| others | UnexpectedStatusCodeException |

- **`LangSmithIoException`** - I/O networking errors
- **`LangSmithInvalidDataException`** - any other exceptions on the client side, e.g.:
- We failed to serialize the request body
- We failed to parse the response body (has access to response code and body)

## Network options

Expand Down
16 changes: 1 addition & 15 deletions build.gradle.kts
@@ -1,20 +1,6 @@
plugins {
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
}

allprojects {
group = "com.langsmith.api"
version = "0.1.0-alpha.1" // x-release-please-version
version = "0.1.0-alpha.2" // x-release-please-version
}

nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))

username.set(System.getenv("SONATYPE_USERNAME"))
password.set(System.getenv("SONATYPE_PASSWORD"))
}
}
}
Binary file modified buildSrc/.gradle/8.0.2/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified buildSrc/.gradle/8.0.2/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified buildSrc/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified buildSrc/.gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
4 changes: 4 additions & 0 deletions buildSrc/build.gradle.kts
@@ -1,12 +1,16 @@
plugins {
`kotlin-dsl`
kotlin("jvm") version "1.9.22"
id("com.vanniktech.maven.publish") version "0.28.0"
}

repositories {
gradlePluginPortal()
mavenCentral()
}

dependencies {
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.25.0")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22")
implementation("com.vanniktech:gradle-maven-publish-plugin:0.28.0")
}
14 changes: 4 additions & 10 deletions buildSrc/src/main/kotlin/langsmith.java.gradle.kts
@@ -1,6 +1,9 @@
import com.diffplug.gradle.spotless.SpotlessExtension
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import java.util.Locale

plugins {
`java-library`
Expand All @@ -11,11 +14,6 @@ repositories {
mavenCentral()
}

configure<JavaPluginExtension> {
withJavadocJar()
withSourcesJar()
}

configure<SpotlessExtension> {
java {
importOrder()
Expand All @@ -35,10 +33,6 @@ tasks.withType<JavaCompile> {
options.release.set(8)
}

tasks.named<Jar>("javadocJar") {
setZip64(true)
}

tasks.jar {
manifest {
attributes(mapOf(
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/langsmith.kotlin.gradle.kts
@@ -1,4 +1,5 @@
import com.diffplug.gradle.spotless.SpotlessExtension
import com.vanniktech.maven.publish.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand Down
83 changes: 34 additions & 49 deletions buildSrc/src/main/kotlin/langsmith.publish.gradle.kts
@@ -1,67 +1,52 @@
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.get

plugins {
`maven-publish`
`signing`
id("com.vanniktech.maven.publish")
}

configure<PublishingExtension> {
publications {
create<MavenPublication>("maven") {
from(components["java"])
repositories {
gradlePluginPortal()
mavenCentral()
}

pom {
name.set("LangSmith")
description.set("An SDK library for LangSmith")
url.set("https://docs.LangSmith.com")
extra["signingInMemoryKey"] = System.getenv("GPG_SIGNING_KEY")
extra["signingInMemoryKeyId"] = System.getenv("GPG_SIGNING_KEY_ID")
extra["signingInMemoryKeyPassword"] = System.getenv("GPG_SIGNING_PASSWORD")

licenses {
license {
name.set("Apache-2.0")
}
}
configure<MavenPublishBaseExtension> {
signAllPublications()
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)

developers {
developer {
name.set("Lang Smith")
email.set("[email protected]")
}
}
this.coordinates(project.group.toString(), project.name, project.version.toString())

scm {
connection.set("scm:git:git://github.com/langchain-ai/langsmith-java.git")
developerConnection.set("scm:git:git://github.com/langchain-ai/langsmith-java.git")
url.set("https://github.com/langchain-ai/langsmith-java")
}
pom {
name.set("LangSmith")
description.set("An SDK library for LangSmith")
url.set("https://docs.LangSmith.com")

versionMapping {
allVariants {
fromResolutionResult()
}
}
licenses {
license {
name.set("Apache-2.0")
}
}
}
}

signing {
val signingKeyId = System.getenv("GPG_SIGNING_KEY_ID")?.ifBlank { null }
val signingKey = System.getenv("GPG_SIGNING_KEY")?.ifBlank { null }
val signingPassword = System.getenv("GPG_SIGNING_PASSWORD")?.ifBlank { null }
if (signingKey != null && signingPassword != null) {
useInMemoryPgpKeys(
signingKeyId,
signingKey,
signingPassword,
)
sign(publishing.publications["maven"])
}
}
developers {
developer {
name.set("Lang Smith")
email.set("[email protected]")
}
}

tasks.publish {
dependsOn(":closeAndReleaseSonatypeStagingRepository")
}
scm {
connection.set("scm:git:git://github.com/langchain-ai/langsmith-java.git")
developerConnection.set("scm:git:git://github.com/langchain-ai/langsmith-java.git")
url.set("https://github.com/langchain-ai/langsmith-java")
}
}
}
2 changes: 1 addition & 1 deletion examples/build.gradle.kts
Expand Up @@ -32,7 +32,7 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
}

// Dynamically create a task for each example
val examples = listOf("RunTreeExample", "OpenAiExample") // Add the names of your example classes here
val examples = listOf("OpenAiExample") // Add the names of your example classes here

examples.forEach { example ->
tasks.create("run$example", org.gradle.api.tasks.JavaExec::class.java) {
Expand Down
30 changes: 21 additions & 9 deletions examples/src/main/java/com/langsmith/example/OpenAiExample.java
@@ -1,9 +1,11 @@
package com.langsmith.example;

import com.langsmith.runtree.EndOptions;
import com.langsmith.runtree.RunTree;
import com.langsmith.runtree.RunTreeConfigBuilder;
import com.langsmith.runtree.RunTreeConfig;
import com.theokanning.openai.service.OpenAiService;
import com.theokanning.openai.completion.chat.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -16,12 +18,14 @@ public static void main(String[] args) {
String question = "Can you summarize this morning's meetings?";

// Create a top-level run
RunTreeConfigBuilder pipelineConfigBuilder = new RunTreeConfigBuilder()
RunTreeConfig pipelineConfig = RunTreeConfig
.builder()
.setName("Chat Pipeline")
.setRunType("chain")
.setInputs(Collections.singletonMap("question", question));
.setInputs(Collections.singletonMap("question", question))
.build();

RunTree pipeline = new RunTree(pipelineConfigBuilder.build());
RunTree pipeline = new RunTree(pipelineConfig);

var context = "During this morning's meeting, we solved all world conflict.";

Expand All @@ -38,22 +42,30 @@ public static void main(String[] args) {
.build();

// Create a child run
RunTreeConfigBuilder childConfigBuilder = new RunTreeConfigBuilder()
RunTreeConfig childConfig = RunTreeConfig
.builder()
.setName("OpenAI Call")
.setRunType("llm")
.setInputs(Collections.singletonMap("messages", messages))
.setParentRun(pipeline);
.setParentRun(pipeline)
.build();

RunTree childTree = pipeline.createChild(childConfigBuilder.build());
RunTree childTree = pipeline.createChild(childConfig);

ChatMessage responseMessage = service.createChatCompletion(completionRequest).getChoices().get(0).getMessage();
System.out.println("Response: " + responseMessage.getContent());

// End the child run
childTree.end(Collections.singletonMap("response", responseMessage), null, null);
childTree.end(EndOptions
.builder()
.setOutputs(Collections.singletonMap("response", responseMessage))
.build());

// End the parent run
pipeline.end(Collections.singletonMap("response", responseMessage.getContent()), null, null);
pipeline.end(EndOptions
.builder()
.setOutputs(Collections.singletonMap("response", responseMessage.getContent()))
.build());
childTree.postRunAsync().join();
pipeline.postRunAsync().join();
}
Expand Down