Skip to content

Commit

Permalink
♻️ refactor: refactor the api (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Nov 15, 2023
1 parent 8698bc7 commit 7364ca3
Show file tree
Hide file tree
Showing 90 changed files with 1,094 additions and 828 deletions.
File renamed without changes.
File renamed without changes.
13 changes: 8 additions & 5 deletions .dumirc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineConfig } from 'dumi';
import path from 'node:path';

import { description, homepage, name } from './package.json';

Expand Down Expand Up @@ -41,6 +42,9 @@ const themeConfig = {
};

export default defineConfig({
alias: {
'@lobehub/tts/react': path.join(__dirname, './src/react'),
},
apiParser: isProduction ? {} : false,
base: '/',
define: {
Expand All @@ -51,11 +55,10 @@ export default defineConfig({
mfsu: isWin ? undefined : {},
npmClient: 'pnpm',
publicPath: '/',
resolve: isProduction
? {
entryFile: './src/index.ts',
}
: undefined,
resolve: {
atomDirs: [{ dir: 'src/react', type: 'component' }],
entryFile: isProduction ? './src/index.ts' : undefined,
},
styles: [
`html, body { background: transparent; }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
225 changes: 225 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,231 @@

# Changelog

## [Version 1.13.0-beta.3](https://github.com/lobehub/lobe-tts/compare/v1.13.0-beta.2...v1.13.0-beta.3)

<sup>Released on **2023-11-15**</sup>

#### ♻ Code Refactoring

- **misc**: Refactor the demo usage.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

- **misc**: Refactor the demo usage ([802c59a](https://github.com/lobehub/lobe-tts/commit/802c59a))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>

## [Version 1.13.0-beta.2](https://github.com/lobehub/lobe-tts/compare/v1.13.0-beta.1...v1.13.0-beta.2)

<sup>Released on **2023-11-15**</sup>

#### ✨ Features

- **misc**: Add SWR config to hooks.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

- **misc**: Add SWR config to hooks ([2c49e02](https://github.com/lobehub/lobe-tts/commit/2c49e02))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>

## [Version 1.13.0-beta.1](https://github.com/lobehub/lobe-tts/compare/v1.12.1-beta.6...v1.13.0-beta.1)

<sup>Released on **2023-11-15**</sup>

#### ✨ Features

- **misc**: Add class.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

- **misc**: Add class ([07245e3](https://github.com/lobehub/lobe-tts/commit/07245e3))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>

### [Version 1.12.1-beta.6](https://github.com/lobehub/lobe-tts/compare/v1.12.1-beta.5...v1.12.1-beta.6)

<sup>Released on **2023-11-15**</sup>

#### ♻ Code Refactoring

- **misc**: Refactor to fix build.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

- **misc**: Refactor to fix build ([9858fcb](https://github.com/lobehub/lobe-tts/commit/9858fcb))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>

### [Version 1.12.1-beta.5](https://github.com/lobehub/lobe-tts/compare/v1.12.1-beta.4...v1.12.1-beta.5)

<sup>Released on **2023-11-15**</sup>

#### ♻ Code Refactoring

- **misc**: Refactor to fix build.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

- **misc**: Refactor to fix build ([d875be6](https://github.com/lobehub/lobe-tts/commit/d875be6))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>

### [Version 1.12.1-beta.4](https://github.com/lobehub/lobe-tts/compare/v1.12.1-beta.3...v1.12.1-beta.4)

<sup>Released on **2023-11-15**</sup>

#### 🐛 Bug Fixes

- **misc**: Fix client fetch.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's fixed

- **misc**: Fix client fetch ([9262608](https://github.com/lobehub/lobe-tts/commit/9262608))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>

### [Version 1.12.1-beta.3](https://github.com/lobehub/lobe-tts/compare/v1.12.1-beta.2...v1.12.1-beta.3)

<sup>Released on **2023-11-15**</sup>

#### ♻ Code Refactoring

- **misc**: Fix react entry.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

- **misc**: Fix react entry ([6a4631d](https://github.com/lobehub/lobe-tts/commit/6a4631d))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>

### [Version 1.12.1-beta.2](https://github.com/lobehub/lobe-tts/compare/v1.12.1-beta.1...v1.12.1-beta.2)

<sup>Released on **2023-11-15**</sup>

#### ♻ Code Refactoring

- **misc**: 将 react 部分抽取到 /react 子级路径下.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

- **misc**: 将 react 部分抽取到 /react 子级路径下 ([80b24e8](https://github.com/lobehub/lobe-tts/commit/80b24e8))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>

### [Version 1.12.1-beta.1](https://github.com/lobehub/lobe-tts/compare/v1.12.0...v1.12.1-beta.1)

<sup>Released on **2023-11-15**</sup>

#### ♻ Code Refactoring

- **misc**: Refactor api.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

- **misc**: Refactor api ([a7c0095](https://github.com/lobehub/lobe-tts/commit/a7c0095))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>

## [Version 1.12.0](https://github.com/lobehub/lobe-tts/compare/v1.11.1...v1.12.0)

<sup>Released on **2023-11-13**</sup>
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ Click button below to deploy your private plugins' gateway.

This project provides some additional configuration items set with environment variables:

| Environment Variable | Description | Default |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
| `ALLOW_ORIGINS` | Allow origins , string or string array | |
| `OPENAI_API_KEY` | This is the API key you apply on the OpenAI account page | `sk-xxxxxx...xxxxxx` |
| `OPENAI_PROXY_URL` | If you manually configure the OpenAI interface proxy, you can use this configuration item to override the default OpenAI API request base URL | `https://api.openai.com/v1` |
| `AZURE_SPEECH_KEY` | This is the API key of Azure Speech Service | |
| `AZURE_SPEECH_REGION` | This is the region of Azure Speech Service | |
| `AZURE_SPEECH_PROXY_URL` | If you manually configure the AZURE Speech interface proxy, you can use this configuration item to override the default Speech API request base URL | `/api/azure-speech` |
| `MICROSOFT_SPEECH_PROXY_URL` | If you manually configure the Microsoft Speech interface proxy, you can use this configuration item to override the default Speech API request base URL | `/api/microsoft-speech` |
| `EDDGE_API_TOKEN` | This is the API key of Edge Speech Service | |
| `EDDGE_PROXY_URL` | If you manually configure the Edge interface proxy, you can use this configuration item to override the default Edge wss request base URL | |
| Environment Variable | Description | Default |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
| `ALLOW_ORIGINS` | Allow origins , string or string array | |
| `OPENAI_API_KEY` | This is the API key you apply on the OpenAI account page | `sk-xxxxxx...xxxxxx` |
| `OPENAI_PROXY_URL` | If you manually configure the OpenAI interface proxy, you can use this configuration item to override the default OpenAI API request base URL | `https://api.openai.com/v1` |
| `AZURE_SPEECH_KEY` | This is the API key of Azure Speech Service | |
| `AZURE_SPEECH_REGION` | This is the region of Azure Speech Service | |
| `AZURE_SPEECH_PROXY_URL` | If you manually configure the AZURE Speech interface proxy, you can use this configuration item to override the default Speech API request base URL | `/api/azure-speech` |
| `MICROSOFT_SPEECH_API_URL` | If you manually configure the Microsoft Speech interface proxy, you can use this configuration item to override the default Speech API request base URL | `/api/microsoft-speech` |
| `EDGE_API_TOKEN` | This is the API key of Edge Speech Service | |
| `EDGE_SPEECH_API_URL` | If you manually configure the Edge interface proxy, you can use this configuration item to override the default Edge wss request base URL | |

<div align="right">

Expand Down
28 changes: 0 additions & 28 deletions api/azure-speech.ts

This file was deleted.

14 changes: 14 additions & 0 deletions api/edge-speech.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createEdgeSpeechComletion } from '../src/server/createEdgeSpeechComletion';
import { EdgeSpeechPayload } from '../src/server/types';

export const config = {
runtime: 'edge',
};

export default async (req: Request) => {
if (req.method !== 'POST') return new Response('Method Not Allowed', { status: 405 });

const payload = (await req.json()) as EdgeSpeechPayload;

return createEdgeSpeechComletion({ payload });
};
12 changes: 5 additions & 7 deletions api/microsoft-speech.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import cors from '../src/server/cors';
import { getAllowOrigins } from '../src/server/getAllowOrigins';
import { handleMicrosoftSpeechRequest } from '../src/server/handleMicrosoftSpeechRequest';
import { createMicrosoftSpeechComletion } from '../src/server/createMicrosoftSpeechComletion';
import { MicrosoftSpeechPayload } from '../src/server/types';

export const config = {
runtime: 'edge',
};

export default async (req: Request) => {
if (req.method !== 'POST') return new Response('Method Not Allowed', { status: 405 });
const origin = getAllowOrigins(req);
if (!origin) return new Response('Origin Not Allowed', { status: 403 });
const res = await handleMicrosoftSpeechRequest(req);
return cors(req, new Response(res.body, res), { methods: ['POST'], origin });
const payload = (await req.json()) as MicrosoftSpeechPayload;

return createMicrosoftSpeechComletion({ payload });
};
28 changes: 28 additions & 0 deletions api/open-stt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import OpenAI from 'openai';

import { createOpenaiAudioTranscriptionsCompletion } from '../src/server/createOpenaiAudioTranscriptionsCompletion';
import { OpenAISTTPayload } from '../src/server/types';

export const config = {
runtime: 'edge',
};

export default async (req: Request) => {
if (req.method !== 'POST') return new Response('Method Not Allowed', { status: 405 });

const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
const OPENAI_PROXY_URL = process.env.OPENAI_PROXY_URL;

if (!OPENAI_API_KEY) return new Response('OPENAI_API_KEY is not set', { status: 500 });

const payload = (await req.json()) as OpenAISTTPayload;

const openai = new OpenAI({ apiKey: OPENAI_API_KEY, baseURL: OPENAI_PROXY_URL });
const res = await createOpenaiAudioTranscriptionsCompletion({ openai, payload });

return new Response(JSON.stringify(res), {
headers: {
'content-type': 'application/json;charset=UTF-8',
},
});
};
Loading

0 comments on commit 7364ca3

Please sign in to comment.