diff --git a/.github/workflows/api-reference.yml b/.github/workflows/api-reference.yml index 74df8cb..46d08ee 100644 --- a/.github/workflows/api-reference.yml +++ b/.github/workflows/api-reference.yml @@ -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 @@ -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 }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bfd5eb4..b1d3ce9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f01aedf..0365126 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: @@ -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 }} diff --git a/.prettierignore b/.prettierignore index c09dfa0..5f4f13c 100644 --- a/.prettierignore +++ b/.prettierignore @@ -10,6 +10,8 @@ node_modules LICENSE .gitignore .prettierignore +.pnpm-store +pnpm-lock.yaml BUILD.bazel copy.bara.sky copybara.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b08791..cb74f8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [4.5.0] + +- You can now retrieve previous LeMUR responses using `client.lemur.getResponse("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`. diff --git a/package.json b/package.json index 51c03c5..dc81773 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/services/lemur/index.ts b/src/services/lemur/index.ts index 793585b..3da5d4e 100644 --- a/src/services/lemur/index.ts +++ b/src/services/lemur/index.ts @@ -8,6 +8,7 @@ import { LemurActionItemsResponse, LemurTaskResponse, PurgeLemurRequestDataResponse, + LemurResponse, } from "../.."; import { BaseService } from "../base"; @@ -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(id: string): Promise; + getResponse(id: string): Promise; + getResponse(id: string): Promise { + return this.fetchJson(`/lemur/v3/${id}`); + } + /** * Delete the data for a previously submitted LeMUR request. * @param id - ID of the LeMUR request diff --git a/src/types/openapi.generated.ts b/src/types/openapi.generated.ts index 306d65c..fcd0fef 100644 --- a/src/types/openapi.generated.ts +++ b/src/types/openapi.generated.ts @@ -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 + * } * } * ``` */ @@ -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 + * } * } * ``` */ @@ -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; }; /** @@ -788,7 +800,11 @@ export type LemurQuestionAnswerParams = LemurBaseParams & { * "answer": "yes", * "question": "Is global warming affecting wildfires?" * } - * ] + * ], + * "usage": { + * "input_tokens": 27, + * "output_tokens": 3 + * } * } * ``` */ @@ -799,6 +815,12 @@ export type LemurQuestionAnswerResponse = LemurBaseResponse & { response: LemurQuestionAnswer[]; }; +export type LemurResponse = + | LemurTaskResponse + | LemurSummaryResponse + | LemurQuestionAnswerResponse + | LemurActionItemsResponse; + /** * @example * ```js @@ -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 + * } * } * ``` */ @@ -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 + * } * } * ``` */ @@ -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 diff --git a/tests/integration/lemur.test.ts b/tests/integration/lemur.test.ts index b3d12f9..7919509 100644 --- a/tests/integration/lemur.test.ts +++ b/tests/integration/lemur.test.ts @@ -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!, @@ -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( + taskResponse.request_id, + ); + expect(taskResponse).toStrictEqual(taskResponse2); + }); + it("should purge request data", async () => { const { request_id } = await client.lemur.summary({ final_model: "basic", diff --git a/tests/unit/lemur.test.ts b/tests/unit/lemur.test.ts index ea12ce4..16ad809 100644 --- a/tests/unit/lemur.test.ts +++ b/tests/unit/lemur.test.ts @@ -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"; @@ -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(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({