Skip to content

Commit

Permalink
added: ui for hyde-search
Browse files Browse the repository at this point in the history
  • Loading branch information
Sadaf-A committed Nov 5, 2023
1 parent 7ce27d2 commit bb6afbe
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 14 deletions.
75 changes: 71 additions & 4 deletions JS/edgechains/examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions JS/edgechains/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"lint": "eslint",
"lint:fix": "eslint --fix",
"start": "nest start",
"copy:views":"cp -r views dist/views",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
Expand All @@ -26,6 +27,8 @@
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/typeorm": "^10.0.0",
"@types/ejs": "^3.1.4",
"ejs": "^3.1.9",
"pg": "^8.11.3",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1"
Expand Down
36 changes: 27 additions & 9 deletions JS/edgechains/examples/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Body, Controller, Get, HttpCode, Post, Query } from '@nestjs/common';
import {
Body,
Controller,
Get,
HttpCode,
Post,
Query,
Render,
} from '@nestjs/common';
import { AppService } from './app.service';
import { hydeSearchAdaEmbedding } from './hydeExample/hydeExample';

Expand All @@ -13,16 +21,26 @@ export class AppController {

@Post('/hyde-search/query-rrf')
@HttpCode(200)
hydeSearch(@Query() params: any, @Body() query: any) {
async hydeSearch(@Query() params: any, @Body() query: any) {
const jsonData = JSON.parse(query.jsonData);
const arkRequest = {
topK: params.topK,
metadataTable: query.metadataTable,
query: query.query,
textWeight: query.textWeight,
similarityWeight: query.similarityWeight,
dateWeight: query.dateWeight,
orderRRF: query.orderRRF,
metadataTable: jsonData.metadataTable,
query: jsonData.query,
textWeight: jsonData.textWeight,
similarityWeight: jsonData.similarityWeight,
dateWeight: jsonData.dateWeight,
orderRRF: jsonData.orderRRF,
};
const result = await hydeSearchAdaEmbedding(arkRequest);
return result.finalAnswer;
}

@Get('/hyde-search/query-rrf')
@Render('hyde-search')
root() {
return {
result: '',
};
return hydeSearchAdaEmbedding(arkRequest);
}
}
6 changes: 5 additions & 1 deletion JS/edgechains/examples/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as path from 'path';
import { NestExpressApplication } from '@nestjs/platform-express';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, '../views'));
await app.listen(8080);
}
bootstrap();
27 changes: 27 additions & 0 deletions JS/edgechains/examples/views/hyde-search.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<title>ChatGPT Query</title>
<script src="https://unpkg.com/[email protected]/dist/htmx.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.7/handlebars.min.js"></script>
</head>
<body>
<h1>ChatGPT Query</h1>
<form hx-post="/hyde-search/query-rrf?topK=5" hx-trigger="submit" hx-target="#result" hx-include="[name='jsonData']" hx-indicator="#loading-indicator">
<form class="htmx-request" hx-post="/hyde-search/query-rrf?topK=5" hx-trigger="submit" hx-target="#result" hx-vals="prepareData">
<label for="jsonData">Enter query details:</label>
<textarea id="jsonData" name="jsonData" required></textarea>
<br><br>
<button type="submit">Submit</button>
</form>
</form>

<div id="result">
<!-- EJS template will render the results here -->
</div>

<script id="result-template" type="text/template">
<p>Result: <%= result %></p>
</script>
</body>
</html>

0 comments on commit bb6afbe

Please sign in to comment.