@copilotkit/voice 0.0.0-mme-a2ui-transports-20260121163813
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/index.d.mts +38 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +34 -0
- package/dist/index.mjs.map +1 -0
- package/eslint.config.mjs +3 -0
- package/package.json +43 -0
- package/src/index.ts +2 -0
- package/src/transcription/transcription-service-openai.ts +58 -0
- package/tsconfig.json +12 -0
- package/tsup.config.ts +13 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Atai Barkai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @copilotkit/voice
|
|
2
|
+
|
|
3
|
+
Audio transcription providers for CopilotKit.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @copilotkit/voice openai
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { CopilotRuntime, createCopilotEndpoint } from "@copilotkitnext/runtime";
|
|
13
|
+
import { TranscriptionServiceOpenAI } from "@copilotkit/voice";
|
|
14
|
+
import OpenAI from "openai";
|
|
15
|
+
|
|
16
|
+
const runtime = new CopilotRuntime({
|
|
17
|
+
agents: { default: yourAgent },
|
|
18
|
+
transcriptionService: new TranscriptionServiceOpenAI({
|
|
19
|
+
openai: new OpenAI({ apiKey: process.env.OPENAI_API_KEY }),
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Once configured, the chat UI shows a microphone button. Users can record audio, which gets transcribed and inserted into the input field as text.
|
|
25
|
+
|
|
26
|
+
## TranscriptionServiceOpenAI
|
|
27
|
+
|
|
28
|
+
Uses [OpenAI Whisper](https://platform.openai.com/docs/guides/speech-to-text) for transcription.
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
new TranscriptionServiceOpenAI({
|
|
32
|
+
openai: new OpenAI({ apiKey: "..." }), // required
|
|
33
|
+
model: "whisper-1", // default
|
|
34
|
+
language: "en", // optional, ISO-639-1 code
|
|
35
|
+
prompt: "Technical discussion context", // optional, helps with domain terms
|
|
36
|
+
temperature: 0, // optional, 0 = deterministic
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Custom providers
|
|
41
|
+
|
|
42
|
+
Extend `TranscriptionService` from runtime:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { TranscriptionService, TranscribeFileOptions } from "@copilotkitnext/runtime";
|
|
46
|
+
|
|
47
|
+
class MyTranscriptionService extends TranscriptionService {
|
|
48
|
+
async transcribeFile(options: TranscribeFileOptions): Promise<string> {
|
|
49
|
+
// options.audioFile, options.mimeType, options.size
|
|
50
|
+
return "transcribed text";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { TranscriptionService, TranscribeFileOptions } from '@copilotkitnext/runtime';
|
|
2
|
+
import OpenAI from 'openai';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for the OpenAI transcription service.
|
|
6
|
+
*/
|
|
7
|
+
interface TranscriptionServiceOpenAIConfig {
|
|
8
|
+
/** OpenAI client instance. */
|
|
9
|
+
openai: OpenAI;
|
|
10
|
+
/** Whisper model to use. Defaults to "whisper-1". */
|
|
11
|
+
model?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Language of the audio in ISO-639-1 format (e.g., "en", "de", "fr").
|
|
14
|
+
* Providing the language improves accuracy and latency.
|
|
15
|
+
*/
|
|
16
|
+
language?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Optional text to guide the model's style or continue a previous segment.
|
|
19
|
+
* Should match the audio language.
|
|
20
|
+
*/
|
|
21
|
+
prompt?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Sampling temperature between 0 and 1.
|
|
24
|
+
* Lower values are more deterministic, higher values more creative.
|
|
25
|
+
*/
|
|
26
|
+
temperature?: number;
|
|
27
|
+
}
|
|
28
|
+
declare class TranscriptionServiceOpenAI extends TranscriptionService {
|
|
29
|
+
private openai;
|
|
30
|
+
private model;
|
|
31
|
+
private language?;
|
|
32
|
+
private prompt?;
|
|
33
|
+
private temperature?;
|
|
34
|
+
constructor(config: TranscriptionServiceOpenAIConfig);
|
|
35
|
+
transcribeFile(options: TranscribeFileOptions): Promise<string>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { TranscriptionServiceOpenAI, type TranscriptionServiceOpenAIConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { TranscriptionService, TranscribeFileOptions } from '@copilotkitnext/runtime';
|
|
2
|
+
import OpenAI from 'openai';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for the OpenAI transcription service.
|
|
6
|
+
*/
|
|
7
|
+
interface TranscriptionServiceOpenAIConfig {
|
|
8
|
+
/** OpenAI client instance. */
|
|
9
|
+
openai: OpenAI;
|
|
10
|
+
/** Whisper model to use. Defaults to "whisper-1". */
|
|
11
|
+
model?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Language of the audio in ISO-639-1 format (e.g., "en", "de", "fr").
|
|
14
|
+
* Providing the language improves accuracy and latency.
|
|
15
|
+
*/
|
|
16
|
+
language?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Optional text to guide the model's style or continue a previous segment.
|
|
19
|
+
* Should match the audio language.
|
|
20
|
+
*/
|
|
21
|
+
prompt?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Sampling temperature between 0 and 1.
|
|
24
|
+
* Lower values are more deterministic, higher values more creative.
|
|
25
|
+
*/
|
|
26
|
+
temperature?: number;
|
|
27
|
+
}
|
|
28
|
+
declare class TranscriptionServiceOpenAI extends TranscriptionService {
|
|
29
|
+
private openai;
|
|
30
|
+
private model;
|
|
31
|
+
private language?;
|
|
32
|
+
private prompt?;
|
|
33
|
+
private temperature?;
|
|
34
|
+
constructor(config: TranscriptionServiceOpenAIConfig);
|
|
35
|
+
transcribeFile(options: TranscribeFileOptions): Promise<string>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { TranscriptionServiceOpenAI, type TranscriptionServiceOpenAIConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
TranscriptionServiceOpenAI: () => TranscriptionServiceOpenAI
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/transcription/transcription-service-openai.ts
|
|
38
|
+
var import_runtime = require("@copilotkitnext/runtime");
|
|
39
|
+
var import_openai = __toESM(require("openai"));
|
|
40
|
+
var TranscriptionServiceOpenAI = class extends import_runtime.TranscriptionService {
|
|
41
|
+
openai;
|
|
42
|
+
model;
|
|
43
|
+
language;
|
|
44
|
+
prompt;
|
|
45
|
+
temperature;
|
|
46
|
+
constructor(config) {
|
|
47
|
+
super();
|
|
48
|
+
this.openai = config.openai ?? new import_openai.default();
|
|
49
|
+
this.model = config.model ?? "whisper-1";
|
|
50
|
+
this.language = config.language;
|
|
51
|
+
this.prompt = config.prompt;
|
|
52
|
+
this.temperature = config.temperature;
|
|
53
|
+
}
|
|
54
|
+
async transcribeFile(options) {
|
|
55
|
+
const response = await this.openai.audio.transcriptions.create({
|
|
56
|
+
file: options.audioFile,
|
|
57
|
+
model: this.model,
|
|
58
|
+
...this.language && { language: this.language },
|
|
59
|
+
...this.prompt && { prompt: this.prompt },
|
|
60
|
+
...this.temperature !== void 0 && { temperature: this.temperature }
|
|
61
|
+
});
|
|
62
|
+
return response.text;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
TranscriptionServiceOpenAI
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/transcription/transcription-service-openai.ts"],"sourcesContent":["// Transcription services\nexport * from \"./transcription/transcription-service-openai\";\n","import {\n TranscribeFileOptions,\n TranscriptionService,\n} from \"@copilotkitnext/runtime\";\nimport OpenAI from \"openai\";\n\n/**\n * Configuration options for the OpenAI transcription service.\n */\nexport interface TranscriptionServiceOpenAIConfig {\n /** OpenAI client instance. */\n openai: OpenAI;\n /** Whisper model to use. Defaults to \"whisper-1\". */\n model?: string;\n /**\n * Language of the audio in ISO-639-1 format (e.g., \"en\", \"de\", \"fr\").\n * Providing the language improves accuracy and latency.\n */\n language?: string;\n /**\n * Optional text to guide the model's style or continue a previous segment.\n * Should match the audio language.\n */\n prompt?: string;\n /**\n * Sampling temperature between 0 and 1.\n * Lower values are more deterministic, higher values more creative.\n */\n temperature?: number;\n}\n\nexport class TranscriptionServiceOpenAI extends TranscriptionService {\n private openai: OpenAI;\n private model: string;\n private language?: string;\n private prompt?: string;\n private temperature?: number;\n\n constructor(config: TranscriptionServiceOpenAIConfig) {\n super();\n this.openai = config.openai ?? new OpenAI();\n this.model = config.model ?? \"whisper-1\";\n this.language = config.language;\n this.prompt = config.prompt;\n this.temperature = config.temperature;\n }\n\n async transcribeFile(options: TranscribeFileOptions): Promise<string> {\n const response = await this.openai.audio.transcriptions.create({\n file: options.audioFile,\n model: this.model,\n ...(this.language && { language: this.language }),\n ...(this.prompt && { prompt: this.prompt }),\n ...(this.temperature !== undefined && { temperature: this.temperature }),\n });\n return response.text;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAGO;AACP,oBAAmB;AA2BZ,IAAM,6BAAN,cAAyC,oCAAqB;AAAA,EAC3D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,QAA0C;AACpD,UAAM;AACN,SAAK,SAAS,OAAO,UAAU,IAAI,cAAAA,QAAO;AAC1C,SAAK,QAAQ,OAAO,SAAS;AAC7B,SAAK,WAAW,OAAO;AACvB,SAAK,SAAS,OAAO;AACrB,SAAK,cAAc,OAAO;AAAA,EAC5B;AAAA,EAEA,MAAM,eAAe,SAAiD;AACpE,UAAM,WAAW,MAAM,KAAK,OAAO,MAAM,eAAe,OAAO;AAAA,MAC7D,MAAM,QAAQ;AAAA,MACd,OAAO,KAAK;AAAA,MACZ,GAAI,KAAK,YAAY,EAAE,UAAU,KAAK,SAAS;AAAA,MAC/C,GAAI,KAAK,UAAU,EAAE,QAAQ,KAAK,OAAO;AAAA,MACzC,GAAI,KAAK,gBAAgB,UAAa,EAAE,aAAa,KAAK,YAAY;AAAA,IACxE,CAAC;AACD,WAAO,SAAS;AAAA,EAClB;AACF;","names":["OpenAI"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/transcription/transcription-service-openai.ts
|
|
2
|
+
import {
|
|
3
|
+
TranscriptionService
|
|
4
|
+
} from "@copilotkitnext/runtime";
|
|
5
|
+
import OpenAI from "openai";
|
|
6
|
+
var TranscriptionServiceOpenAI = class extends TranscriptionService {
|
|
7
|
+
openai;
|
|
8
|
+
model;
|
|
9
|
+
language;
|
|
10
|
+
prompt;
|
|
11
|
+
temperature;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
super();
|
|
14
|
+
this.openai = config.openai ?? new OpenAI();
|
|
15
|
+
this.model = config.model ?? "whisper-1";
|
|
16
|
+
this.language = config.language;
|
|
17
|
+
this.prompt = config.prompt;
|
|
18
|
+
this.temperature = config.temperature;
|
|
19
|
+
}
|
|
20
|
+
async transcribeFile(options) {
|
|
21
|
+
const response = await this.openai.audio.transcriptions.create({
|
|
22
|
+
file: options.audioFile,
|
|
23
|
+
model: this.model,
|
|
24
|
+
...this.language && { language: this.language },
|
|
25
|
+
...this.prompt && { prompt: this.prompt },
|
|
26
|
+
...this.temperature !== void 0 && { temperature: this.temperature }
|
|
27
|
+
});
|
|
28
|
+
return response.text;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
TranscriptionServiceOpenAI
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/transcription/transcription-service-openai.ts"],"sourcesContent":["import {\n TranscribeFileOptions,\n TranscriptionService,\n} from \"@copilotkitnext/runtime\";\nimport OpenAI from \"openai\";\n\n/**\n * Configuration options for the OpenAI transcription service.\n */\nexport interface TranscriptionServiceOpenAIConfig {\n /** OpenAI client instance. */\n openai: OpenAI;\n /** Whisper model to use. Defaults to \"whisper-1\". */\n model?: string;\n /**\n * Language of the audio in ISO-639-1 format (e.g., \"en\", \"de\", \"fr\").\n * Providing the language improves accuracy and latency.\n */\n language?: string;\n /**\n * Optional text to guide the model's style or continue a previous segment.\n * Should match the audio language.\n */\n prompt?: string;\n /**\n * Sampling temperature between 0 and 1.\n * Lower values are more deterministic, higher values more creative.\n */\n temperature?: number;\n}\n\nexport class TranscriptionServiceOpenAI extends TranscriptionService {\n private openai: OpenAI;\n private model: string;\n private language?: string;\n private prompt?: string;\n private temperature?: number;\n\n constructor(config: TranscriptionServiceOpenAIConfig) {\n super();\n this.openai = config.openai ?? new OpenAI();\n this.model = config.model ?? \"whisper-1\";\n this.language = config.language;\n this.prompt = config.prompt;\n this.temperature = config.temperature;\n }\n\n async transcribeFile(options: TranscribeFileOptions): Promise<string> {\n const response = await this.openai.audio.transcriptions.create({\n file: options.audioFile,\n model: this.model,\n ...(this.language && { language: this.language }),\n ...(this.prompt && { prompt: this.prompt }),\n ...(this.temperature !== undefined && { temperature: this.temperature }),\n });\n return response.text;\n }\n}\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,OACK;AACP,OAAO,YAAY;AA2BZ,IAAM,6BAAN,cAAyC,qBAAqB;AAAA,EAC3D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,QAA0C;AACpD,UAAM;AACN,SAAK,SAAS,OAAO,UAAU,IAAI,OAAO;AAC1C,SAAK,QAAQ,OAAO,SAAS;AAC7B,SAAK,WAAW,OAAO;AACvB,SAAK,SAAS,OAAO;AACrB,SAAK,cAAc,OAAO;AAAA,EAC5B;AAAA,EAEA,MAAM,eAAe,SAAiD;AACpE,UAAM,WAAW,MAAM,KAAK,OAAO,MAAM,eAAe,OAAO;AAAA,MAC7D,MAAM,QAAQ;AAAA,MACd,OAAO,KAAK;AAAA,MACZ,GAAI,KAAK,YAAY,EAAE,UAAU,KAAK,SAAS;AAAA,MAC/C,GAAI,KAAK,UAAU,EAAE,QAAQ,KAAK,OAAO;AAAA,MACzC,GAAI,KAAK,gBAAgB,UAAa,EAAE,aAAa,KAAK,YAAY;AAAA,IACxE,CAAC;AACD,WAAO,SAAS;AAAA,EAClB;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@copilotkit/voice",
|
|
3
|
+
"version": "0.0.0-mme-a2ui-transports-20260121163813",
|
|
4
|
+
"description": "Voice services for CopilotKit (transcription, text-to-speech, etc.)",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^22.15.3",
|
|
19
|
+
"eslint": "^9.30.0",
|
|
20
|
+
"tsup": "^8.5.0",
|
|
21
|
+
"typescript": "5.8.2",
|
|
22
|
+
"vitest": "^3.0.5",
|
|
23
|
+
"@copilotkitnext/eslint-config": "0.0.0-mme-a2ui-transports-20260121163813",
|
|
24
|
+
"@copilotkitnext/typescript-config": "0.0.0-mme-a2ui-transports-20260121163813"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"openai": "^5.9.0",
|
|
28
|
+
"@copilotkitnext/runtime": "0.0.0-mme-a2ui-transports-20260121163813"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsup",
|
|
35
|
+
"dev": "tsup --watch",
|
|
36
|
+
"lint": "eslint . --max-warnings 0",
|
|
37
|
+
"check-types": "tsc --noEmit",
|
|
38
|
+
"clean": "rm -rf dist",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"test:watch": "vitest",
|
|
41
|
+
"test:coverage": "vitest run --coverage"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TranscribeFileOptions,
|
|
3
|
+
TranscriptionService,
|
|
4
|
+
} from "@copilotkitnext/runtime";
|
|
5
|
+
import OpenAI from "openai";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for the OpenAI transcription service.
|
|
9
|
+
*/
|
|
10
|
+
export interface TranscriptionServiceOpenAIConfig {
|
|
11
|
+
/** OpenAI client instance. */
|
|
12
|
+
openai: OpenAI;
|
|
13
|
+
/** Whisper model to use. Defaults to "whisper-1". */
|
|
14
|
+
model?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Language of the audio in ISO-639-1 format (e.g., "en", "de", "fr").
|
|
17
|
+
* Providing the language improves accuracy and latency.
|
|
18
|
+
*/
|
|
19
|
+
language?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Optional text to guide the model's style or continue a previous segment.
|
|
22
|
+
* Should match the audio language.
|
|
23
|
+
*/
|
|
24
|
+
prompt?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Sampling temperature between 0 and 1.
|
|
27
|
+
* Lower values are more deterministic, higher values more creative.
|
|
28
|
+
*/
|
|
29
|
+
temperature?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class TranscriptionServiceOpenAI extends TranscriptionService {
|
|
33
|
+
private openai: OpenAI;
|
|
34
|
+
private model: string;
|
|
35
|
+
private language?: string;
|
|
36
|
+
private prompt?: string;
|
|
37
|
+
private temperature?: number;
|
|
38
|
+
|
|
39
|
+
constructor(config: TranscriptionServiceOpenAIConfig) {
|
|
40
|
+
super();
|
|
41
|
+
this.openai = config.openai ?? new OpenAI();
|
|
42
|
+
this.model = config.model ?? "whisper-1";
|
|
43
|
+
this.language = config.language;
|
|
44
|
+
this.prompt = config.prompt;
|
|
45
|
+
this.temperature = config.temperature;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async transcribeFile(options: TranscribeFileOptions): Promise<string> {
|
|
49
|
+
const response = await this.openai.audio.transcriptions.create({
|
|
50
|
+
file: options.audioFile,
|
|
51
|
+
model: this.model,
|
|
52
|
+
...(this.language && { language: this.language }),
|
|
53
|
+
...(this.prompt && { prompt: this.prompt }),
|
|
54
|
+
...(this.temperature !== undefined && { temperature: this.temperature }),
|
|
55
|
+
});
|
|
56
|
+
return response.text;
|
|
57
|
+
}
|
|
58
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@copilotkitnext/typescript-config/base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"rootDir": "src",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"sourceMap": true
|
|
9
|
+
},
|
|
10
|
+
"include": ["src/**/*"],
|
|
11
|
+
"exclude": ["dist", "node_modules"]
|
|
12
|
+
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineConfig } from 'tsup';
|
|
2
|
+
|
|
3
|
+
const isWatch = process.argv.includes("--watch");
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
entry: ['src/index.ts'],
|
|
7
|
+
format: ['cjs', 'esm'],
|
|
8
|
+
dts: isWatch ? false : true,
|
|
9
|
+
sourcemap: true,
|
|
10
|
+
clean: !isWatch,
|
|
11
|
+
target: 'es2022',
|
|
12
|
+
outDir: 'dist',
|
|
13
|
+
});
|