Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.4.0

- Decode embedding vectors and phrase-level transcript segments while retaining the previous constructors.

## 0.3.0

- Add the asset library: keep files in a library and reference them as `spicy://a/<id>` in any media
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ speak the OpenAI, Anthropic and Gemini wire formats.
<dependency>
<groupId>ai.spicyapi</groupId>
<artifactId>spicyapi-java</artifactId>
<version>0.3.0</version>
<version>0.4.0</version>
</dependency>
```

Expand Down Expand Up @@ -58,7 +58,8 @@ Build the input from that model's own `inputSchema` — every model has differen
whole result in the text field and return no files at all; a client that only looks for files
reports a perfectly successful task as having produced nothing. A transcription that reports timing
also has `transcript()`: the detected language, per-word start and end times and, for multichannel
audio, one entry per channel.
audio, one entry per channel. Use `segments()` for timed phrases. For embedding tasks,
`task.output().embeddings().data()` provides each vector and its input index.

A layer decomposition returns a base image followed by transparent layers. Each asset's `layer()`
holds its `zIndex` and, when `positioned()`, the `boundingBox` that places it on the base; stack them
Expand Down
234 changes: 230 additions & 4 deletions contracts/openapi.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ai.spicyapi</groupId>
<artifactId>spicyapi-java</artifactId>
<version>0.3.0</version>
<version>0.4.0</version>
<packaging>jar</packaging>

<name>SpicyAPI Java client</name>
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/ai/spicyapi/TaskEmbeddings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ai.spicyapi;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;

/**
* Vectors produced by a text embedding task.
* @param inputTokens measured input token count
* @param data one vector for each input
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public record TaskEmbeddings(int inputTokens, List<Vector> data) {
/** Normalizes an absent array to an empty list. */
public TaskEmbeddings {
data = Internal.emptyIfNull(data);
}

/**
* A vector and its position in the input.
* @param index zero-based position
* @param embedding vector coordinates
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public record Vector(int index, List<Double> embedding) {
/** Normalizes an absent array to an empty list. */
public Vector {
embedding = Internal.emptyIfNull(embedding);
}
}
}
8 changes: 7 additions & 1 deletion src/main/java/ai/spicyapi/TaskOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@
* @param assets generated artifacts; empty for a text-only result
* @param transcript the structured transcript, with timing and language, on speech-to-text
* endpoints that report it; {@code null} everywhere else
* @param embeddings vectors from a text embedding task, or {@code null}
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public record TaskOutput(String text, List<TaskAsset> assets, TaskTranscript transcript) {
public record TaskOutput(String text, List<TaskAsset> assets, TaskTranscript transcript, TaskEmbeddings embeddings) {

// Text-only outputs carry no assets field; normalise it to an empty list.
public TaskOutput {
assets = Internal.emptyIfNull(assets);
}

/** Retains the original transcript-aware constructor. */
public TaskOutput(String text, List<TaskAsset> assets, TaskTranscript transcript) {
this(text, assets, transcript, null);
}

/**
* The shape this record had before {@code transcript} was added, kept so existing callers
* still compile.
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/ai/spicyapi/TaskTranscript.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@
* @param words timed words; empty when the model reports none
* @param channels one entry per audio channel when multichannel transcription was
* requested; empty otherwise
* @param segments timed phrases, including speaker labels when available
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public record TaskTranscript(String text, String language, String languageCode, Double languageProbability,
Double durationSeconds, List<TaskTranscriptWord> words,
List<TaskTranscriptChannel> channels) {
List<TaskTranscriptChannel> channels, List<TaskTranscriptWord> segments) {

/** Retains the constructor used before phrase-level timing was available. */
public TaskTranscript(String text, String language, String languageCode, Double languageProbability,
Double durationSeconds, List<TaskTranscriptWord> words, List<TaskTranscriptChannel> channels) {
this(text, language, languageCode, languageProbability, durationSeconds, words, channels, List.of());
}

// Absent arrays become empty lists, so callers never null-check them.
public TaskTranscript {
words = Internal.emptyIfNull(words);
channels = Internal.emptyIfNull(channels);
segments = Internal.emptyIfNull(segments);
}
}
14 changes: 14 additions & 0 deletions src/test/java/ai/spicyapi/JsonMappingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ void transcriptMaps() throws Exception {
"absent arrays come back empty");
}

@Test
void vectorAndSegmentOutputs() throws Exception {
TaskOutput output = MAPPER.readValue("""
{"embeddings":{"inputTokens":3,"data":[{"index":1,"embedding":[-0.25,0.5]}]},
"transcript":{"segments":[{"text":"Hello","start":0.0,"end":1.25,"speakerId":"A"}]}}""", TaskOutput.class);
assertEquals(3, output.embeddings().inputTokens());
assertEquals(1, output.embeddings().data().get(0).index());
assertEquals(List.of(-0.25, 0.5), output.embeddings().data().get(0).embedding());
assertEquals("A", output.transcript().segments().get(0).speakerId());
TaskTranscript legacy = new TaskTranscript(null, null, null, null, null, null, null);
assertTrue(legacy.segments().isEmpty());
assertNull(new TaskOutput(null, null, legacy).embeddings());
}

@Test
@DisplayName("layer decomposition assets carry their stacking order and placement")
void layerMaps() throws Exception {
Expand Down
Loading