Skip to content

Commit

Permalink
Merge pull request #59 from AssemblyAI/E07417BDFEA3614F5967B1520F8B2F61
Browse files Browse the repository at this point in the history
Sync from internal repo (2024/06/17)
  • Loading branch information
Swimburger committed Jun 17, 2024
2 parents 2f75167 + 50fca34 commit 66b6fd7
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/api-reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Setup Node.js 20
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 8.10.0
Expand All @@ -38,7 +38,7 @@ jobs:
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Setup Node.js 20
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v3
uses: pnpm/action-setup@v4
with:
version: 8.10.0
run_install: false
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
# - windows-latest
steps:
- name: Setup Node.js ${{ matrix['node-version'] }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix['node-version'] }}
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
Expand All @@ -35,7 +35,7 @@ jobs:
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ node_modules
LICENSE
.gitignore
.prettierignore
.pnpm-store
pnpm-lock.yaml
BUILD.bazel
copy.bara.sky
copybara.sh
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [4.5.0]

- You can now retrieve previous LeMUR responses using `client.lemur.getResponse<LemurTask>("YOUR_REQUEST_ID")`.
- LeMUR functions now return `usage` with the number of `input_tokens` and `output_tokens`.

## [4.4.7]

- Rename `TranscriptService.redactions` function to `TranscriptService.redactedAudio`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "assemblyai",
"version": "4.4.7",
"version": "4.5.0",
"description": "The AssemblyAI JavaScript SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription, as well as the latest LeMUR models.",
"engines": {
"node": ">=18"
Expand Down
12 changes: 12 additions & 0 deletions src/services/lemur/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
LemurActionItemsResponse,
LemurTaskResponse,
PurgeLemurRequestDataResponse,
LemurResponse,
} from "../..";
import { BaseService } from "../base";

Expand Down Expand Up @@ -50,6 +51,17 @@ export class LemurService extends BaseService {
});
}

/**
* Retrieve a LeMUR response that was previously generated.
* @param id - The ID of the LeMUR request you previously made. This would be found in the response of the original request.
* @returns The LeMUR response.
*/
getResponse<T extends LemurResponse>(id: string): Promise<T>;
getResponse(id: string): Promise<LemurResponse>;
getResponse(id: string): Promise<LemurResponse> {
return this.fetchJson<LemurResponse>(`/lemur/v3/${id}`);
}

/**
* Delete the data for a previously submitted LeMUR request.
* @param id - ID of the LeMUR request
Expand Down
54 changes: 49 additions & 5 deletions src/types/openapi.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,11 @@ export type LemurActionItemsParams = LemurBaseParams & {
* ```js
* {
* "request_id": "5"e1b27c2-691f-4414-8bc5-f14678442f9e",
* "response": "Here are some potential action items based on the transcript:\n\n- Monitor air quality levels in affected areas and issue warnings as needed.\n\n- Advise vulnerable populations like children, the elderly, and those with respiratory conditions to limit time outdoors.\n\n- Have schools cancel outdoor activities when air quality is poor.\n\n- Educate the public on health impacts of smoke inhalation and precautions to take.\n\n- Track progression of smoke plumes using weather and air quality monitoring systems.\n\n- Coordinate cross-regionally to manage smoke exposure as air masses shift.\n\n- Plan for likely increase in such events due to climate change. Expand monitoring and forecasting capabilities.\n\n- Conduct research to better understand health impacts of wildfire smoke and mitigation strategies.\n\n- Develop strategies to prevent and manage wildfires to limit air quality impacts.\n"
* "response": "Here are some potential action items based on the transcript:\n\n- Monitor air quality levels in affected areas and issue warnings as needed.\n\n- Advise vulnerable populations like children, the elderly, and those with respiratory conditions to limit time outdoors.\n\n- Have schools cancel outdoor activities when air quality is poor.\n\n- Educate the public on health impacts of smoke inhalation and precautions to take.\n\n- Track progression of smoke plumes using weather and air quality monitoring systems.\n\n- Coordinate cross-regionally to manage smoke exposure as air masses shift.\n\n- Plan for likely increase in such events due to climate change. Expand monitoring and forecasting capabilities.\n\n- Conduct research to better understand health impacts of wildfire smoke and mitigation strategies.\n\n- Develop strategies to prevent and manage wildfires to limit air quality impacts.\n",
* "usage": {
* "input_tokens": 27,
* "output_tokens": 3
* }
* }
* ```
*/
Expand Down Expand Up @@ -659,7 +663,11 @@ export type LemurBaseParams = {
* @example
* ```js
* {
* "request_id": "5e1b27c2-691f-4414-8bc5-f14678442f9e"
* "request_id": "5e1b27c2-691f-4414-8bc5-f14678442f9e",
* "usage": {
* "input_tokens": 27,
* "output_tokens": 3
* }
* }
* ```
*/
Expand All @@ -668,6 +676,10 @@ export type LemurBaseResponse = {
* The ID of the LeMUR request
*/
request_id: string;
/**
* The usage numbers for the LeMUR request
*/
usage: LemurUsage;
};

/**
Expand Down Expand Up @@ -788,7 +800,11 @@ export type LemurQuestionAnswerParams = LemurBaseParams & {
* "answer": "yes",
* "question": "Is global warming affecting wildfires?"
* }
* ]
* ],
* "usage": {
* "input_tokens": 27,
* "output_tokens": 3
* }
* }
* ```
*/
Expand All @@ -799,6 +815,12 @@ export type LemurQuestionAnswerResponse = LemurBaseResponse & {
response: LemurQuestionAnswer[];
};

export type LemurResponse =
| LemurTaskResponse
| LemurSummaryResponse
| LemurQuestionAnswerResponse
| LemurActionItemsResponse;

/**
* @example
* ```js
Expand All @@ -825,7 +847,11 @@ export type LemurSummaryParams = LemurBaseParams & {
* ```js
* {
* "request_id": "5e1b27c2-691f-4414-8bc5-f14678442f9e",
* "response": "- Wildfires in Canada are sending smoke and air pollution across parts of the US, triggering air quality alerts from Maine to Minnesota. Concentrations of particulate matter have exceeded safety levels.\n\n- Weather systems are channeling the smoke through Pennsylvania into the Mid-Atlantic and Northeast regions. New York City has canceled outdoor activities to keep children and vulnerable groups indoors.\n\n- Very small particulate matter can enter the lungs and impact respiratory, cardiovascular and neurological health. Young children, the elderly and those with preexisting conditions are most at risk.\n\n- The conditions causing the poor air quality could get worse or shift to different areas in coming days depending on weather patterns. More wildfires may also contribute to higher concentrations.\n\n- Climate change is leading to longer and more severe fire seasons. Events of smoke traveling long distances and affecting air quality over wide areas will likely become more common in the future.\"\n"
* "response": "- Wildfires in Canada are sending smoke and air pollution across parts of the US, triggering air quality alerts from Maine to Minnesota. Concentrations of particulate matter have exceeded safety levels.\n\n- Weather systems are channeling the smoke through Pennsylvania into the Mid-Atlantic and Northeast regions. New York City has canceled outdoor activities to keep children and vulnerable groups indoors.\n\n- Very small particulate matter can enter the lungs and impact respiratory, cardiovascular and neurological health. Young children, the elderly and those with preexisting conditions are most at risk.\n\n- The conditions causing the poor air quality could get worse or shift to different areas in coming days depending on weather patterns. More wildfires may also contribute to higher concentrations.\n\n- Climate change is leading to longer and more severe fire seasons. Events of smoke traveling long distances and affecting air quality over wide areas will likely become more common in the future.\"\n",
* "usage": {
* "input_tokens": 27,
* "output_tokens": 3
* }
* }
* ```
*/
Expand Down Expand Up @@ -863,7 +889,11 @@ export type LemurTaskParams = {
* ```js
* {
* "request_id": "5e1b27c2-691f-4414-8bc5-f14678442f9e",
* "response": "Based on the transcript, the following locations were mentioned as being affected by wildfire smoke from Canada:\n\n- Maine\n- Maryland\n- Minnesota\n- Mid Atlantic region\n- Northeast region\n- New York City\n- Baltimore\n"
* "response": "Based on the transcript, the following locations were mentioned as being affected by wildfire smoke from Canada:\n\n- Maine\n- Maryland\n- Minnesota\n- Mid Atlantic region\n- Northeast region\n- New York City\n- Baltimore\n",
* "usage": {
* "input_tokens": 27,
* "output_tokens": 3
* }
* }
* ```
*/
Expand All @@ -874,6 +904,20 @@ export type LemurTaskResponse = {
response: string;
} & LemurBaseResponse;

/**
* The usage numbers for the LeMUR request
*/
export type LemurUsage = {
/**
* The number of input tokens used by the model
*/
input_tokens: number;
/**
* The number of output tokens generated by the model
*/
output_tokens: number;
};

/**
* @example
* ```js
Expand Down
28 changes: 27 additions & 1 deletion tests/integration/lemur.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "dotenv/config";
import { AssemblyAI } from "../../src";
import { AssemblyAI, LemurTaskResponse } from "../../src";

const client = new AssemblyAI({
apiKey: process.env.ASSEMBLYAI_API_KEY!,
Expand Down Expand Up @@ -64,6 +64,32 @@ describe("lemur", () => {
);
});

it("should return response", async () => {
const taskResponse = await client.lemur.task({
final_model: "basic",
transcript_ids: knownTranscriptIds,
prompt: "Write a haiku about this conversation.",
});

const taskResponse2 = await client.lemur.getResponse(
taskResponse.request_id,
);
expect(taskResponse).toStrictEqual(taskResponse2);
});

it("should return response with generic", async () => {
const taskResponse = await client.lemur.task({
final_model: "basic",
transcript_ids: knownTranscriptIds,
prompt: "Write a haiku about this conversation.",
});

const taskResponse2 = await client.lemur.getResponse<LemurTaskResponse>(
taskResponse.request_id,
);
expect(taskResponse).toStrictEqual(taskResponse2);
});

it("should purge request data", async () => {
const { request_id } = await client.lemur.summary({
final_model: "basic",
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/lemur.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fetchMock from "jest-fetch-mock";
import { createClient, requestMatches } from "./utils";
import { LemurTaskResponse } from "../../src";

const knownTranscriptIds = ["transcript_123"];
const knownLemurRequestId = "lemur_123";
Expand Down Expand Up @@ -113,6 +114,41 @@ describe("lemur", () => {
);
});

it("should return response", async () => {
fetchMock.doMockOnceIf(
requestMatches({
method: "GET",
url: `/lemur/v3/${knownLemurRequestId}`,
}),
JSON.stringify({
request_id: knownLemurRequestId,
response: "some response",
}),
);
const response = await assembly.lemur.getResponse(knownLemurRequestId);
expect(response).toBeTruthy();
expect(response.request_id).toBe(knownLemurRequestId);
expect(response.response).toBe("some response");
});

it("should return response with generic", async () => {
fetchMock.doMockOnceIf(
requestMatches({
method: "GET",
url: `/lemur/v3/${knownLemurRequestId}`,
}),
JSON.stringify({
request_id: knownLemurRequestId,
response: "some response",
}),
);
const response =
await assembly.lemur.getResponse<LemurTaskResponse>(knownLemurRequestId);
expect(response).toBeTruthy();
expect(response.request_id).toBe(knownLemurRequestId);
expect(response.response).toBe("some response");
});

it("should purge request data", async () => {
fetchMock.doMockOnceIf(
requestMatches({
Expand Down

0 comments on commit 66b6fd7

Please sign in to comment.