-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lightspeed): create lightspeed backend (#2115)
* feat(lightspeed): introduce lightspeed backend * feat(lightspeed): add openai dependency * Introduce completions endpoint * docs(lightspped): add README * feat(lightspeed): add simple validation * working langchain Signed-off-by: Stephanie <yangcao@redhat.com> * update tests Signed-off-by: Stephanie <yangcao@redhat.com> * yarn Signed-off-by: Stephanie <yangcao@redhat.com> * update router Signed-off-by: Stephanie <yangcao@redhat.com> * address some review comment Signed-off-by: Stephanie <yangcao@redhat.com> * run lint prettier Signed-off-by: Stephanie <yangcao@redhat.com> * update readme Signed-off-by: Stephanie <yangcao@redhat.com> * update readme Signed-off-by: Stephanie <yangcao@redhat.com> * fix readme * add unauthenticated for query endpoint as no user authentication has been implemented yet Signed-off-by: Stephanie <yangcao@redhat.com> * rebase and cleanup Signed-off-by: Stephanie <yangcao@redhat.com> * run prettier format Signed-off-by: Stephanie <yangcao@redhat.com> * comment auth related code Signed-off-by: Stephanie <yangcao@redhat.com> * run prettier Signed-off-by: Stephanie <yangcao@redhat.com> * comment import for authentication use Signed-off-by: Stephanie <yangcao@redhat.com> * export dynamic Signed-off-by: Stephanie <yangcao@redhat.com> * cleanup Signed-off-by: Stephanie <yangcao@redhat.com> * rebase and yarn install Signed-off-by: Stephanie <yangcao@redhat.com> * clenaup Signed-off-by: Stephanie <yangcao@redhat.com> * rebase and yarn install Signed-off-by: Stephanie <yangcao@redhat.com> --------- Signed-off-by: Stephanie <yangcao@redhat.com> Co-authored-by: Dominika Zemanovicova <dzemanov@redhat.com>
- Loading branch information
Showing
21 changed files
with
3,089 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# Lightspeed Backend | ||
|
||
This is the lightspeed backend plugin that enables you to interact with any LLM server running a model with OpenAI's API compatibility. | ||
|
||
## Getting Started | ||
|
||
### Installing the plugin | ||
|
||
```bash | ||
yarn add --cwd packages/backend @janus-idp/backstage-plugin-lightspeed-backend | ||
``` | ||
|
||
### Configuring the Backend | ||
|
||
#### Old Backend System | ||
|
||
1. Create a new file `packages/backend/src/plugins/lightspeed.ts`, and add the following | ||
|
||
```ts title="packages/backend/src/plugins/lightspeed.ts" | ||
import { Router } from 'express'; | ||
|
||
import { createRouter } from '@janus-idp/backstage-plugin-lightspeed-backend'; | ||
|
||
import { PluginEnvironment } from '../types'; | ||
|
||
export default async function createPlugin( | ||
env: PluginEnvironment, | ||
): Promise<Router> { | ||
return await createRouter({ | ||
config: env.config, | ||
logger: env.logger, | ||
discovery: env.discovery, | ||
catalogApi: env.catalogApi, | ||
}); | ||
} | ||
``` | ||
|
||
1. Next, in your overall backend router (typically `packages/backend/src/index.ts`) add a route for `/lightspeed`: | ||
|
||
```ts title="packages/backend/src/index.ts" | ||
import lightspeed from './plugins/lightspeed'; | ||
|
||
// ... | ||
async function main() { | ||
// ... | ||
// Add the following line | ||
const lightspeedEnv = useHotMemoize(module, () => createEnv('lightspeed')); | ||
// ... | ||
// Add the following line under the other lines that add their routers to apiRouter | ||
apiRouter.use('/lightspeed', await lightspeed(lightspeedEnv)); | ||
// ... | ||
} | ||
``` | ||
|
||
#### New Backend System | ||
|
||
Add the following to your `packages/backend/src/index.ts` file: | ||
|
||
```ts title="packages/backend/src/index.ts" | ||
const backend = createBackend(); | ||
|
||
// Add the following line | ||
backend.add(import('@janus-idp/backstage-plugin-lightspeed-backend')); | ||
|
||
backend.start(); | ||
``` | ||
|
||
### Plugin Configurations | ||
|
||
Add the following proxy configurations into your `app-config.yaml` file: | ||
|
||
```yaml | ||
proxy: | ||
endpoints: | ||
'/lightspeed/api': | ||
target: '<LLM server URL>' | ||
headers: | ||
content-type: 'application/json' | ||
Authorization: 'Bearer <api-token>' | ||
secure: true | ||
changeOrigin: true | ||
credentials: 'dangerously-allow-unauthenticated' # No Backstage credentials are required to access this proxy target | ||
``` | ||
Example local development configuration: | ||
```yaml | ||
proxy: | ||
endpoints: | ||
'/lightspeed/api': | ||
target: 'https://localhost:443/v1' | ||
headers: | ||
content-type: 'application/json' | ||
Authorization: 'Bearer js92n-ssj28dbdk902' # dummy token | ||
secure: true | ||
changeOrigin: true | ||
credentials: 'dangerously-allow-unauthenticated' # No Backstage credentials are required to access this proxy target | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export interface Config {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{ | ||
"name": "@janus-idp/backstage-plugin-lightspeed-backend-dynamic", | ||
"version": "0.1.0", | ||
"main": "dist/index.cjs.js", | ||
"types": "dist/index.d.ts", | ||
"license": "Apache-2.0", | ||
"private": true, | ||
"publishConfig": { | ||
"access": "public", | ||
"main": "dist/index.cjs.js", | ||
"types": "dist/index.d.ts" | ||
}, | ||
"backstage": { | ||
"role": "backend-plugin" | ||
}, | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.cjs.js", | ||
"default": "./dist/index.cjs.js" | ||
}, | ||
"./alpha": { | ||
"require": "./dist/alpha.cjs.js", | ||
"default": "./dist/alpha.cjs.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"scripts": {}, | ||
"dependencies": { | ||
"@langchain/core": "^0.2.30", | ||
"@langchain/openai": "^0.2.8", | ||
"@types/express": "^*", | ||
"express": "^4.17.1", | ||
"express-promise-router": "^4.1.0", | ||
"node-fetch": "^2.6.7", | ||
"yn": "^4.0.0" | ||
}, | ||
"devDependencies": {}, | ||
"files": [ | ||
"dist", | ||
"config.d.ts", | ||
"app-config.janus-idp.yaml", | ||
"alpha" | ||
], | ||
"configSchema": "config.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/janus-idp/backstage-plugins", | ||
"directory": "plugins/lightspeed-backend" | ||
}, | ||
"keywords": [ | ||
"backstage", | ||
"plugin" | ||
], | ||
"homepage": "https://janus-idp.io/", | ||
"bugs": "https://github.com/janus-idp/backstage-plugins/issues", | ||
"bundleDependencies": true, | ||
"peerDependencies": { | ||
"@backstage/backend-app-api": "^0.9.3", | ||
"@backstage/backend-common": "^0.23.2", | ||
"@backstage/backend-dynamic-feature-service": "^0.3.2", | ||
"@backstage/backend-plugin-api": "^0.6.21", | ||
"@backstage/backend-plugin-manager": "npm:@janus-idp/backend-plugin-manager@0.0.2-janus.5", | ||
"@backstage/backend-test-utils": "^0.5.1", | ||
"@backstage/catalog-client": "^1.6.6", | ||
"@backstage/config": "^1.2.0", | ||
"@backstage/plugin-catalog-node": "^1.12.6" | ||
}, | ||
"overrides": { | ||
"@aws-sdk/util-utf8-browser": { | ||
"@smithy/util-utf8": "^2.0.0" | ||
} | ||
}, | ||
"resolutions": { | ||
"@aws-sdk/util-utf8-browser": "npm:@smithy/util-utf8@~2" | ||
} | ||
} |
Oops, something went wrong.