Skip to content

Commit

Permalink
feat: added chatgpt plugin layer
Browse files Browse the repository at this point in the history
  • Loading branch information
sametcodes committed May 20, 2023
1 parent 836127e commit 0d4c926
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules
.env
static
.env
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ import routes from './routes';

const app = express();

app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', 'https://chat.openai.com');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', '*');
next();
});

app.use(express.json());

routes.forEach(route => {
app[route.method](route.path, ...route.middlewares, route.handler)
})
});

app.use(express.static('static'));


app.listen(env.PORT, () => {
console.log(`Server running on port ${env.PORT}`);
Expand Down
10 changes: 4 additions & 6 deletions src/routes/v2/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { parseCSV } from "../../utils";
import { v4 as uuidv4 } from 'uuid';

const availablePlatforms = [
"shopify",
"amazon",
"ciceksepeti",
"hepsiburada",
"trendyol"
Expand All @@ -15,14 +13,14 @@ export const queryCategory = async (req: Request, res: Response) => {
if (availablePlatforms.includes(req.params.platform) === false) {
return res.status(400).json({
success: false, data: null,
error: 'The given platform is not available. Available platforms' + availablePlatforms.join(', ')
error: 'The given platform is not available. Available platforms ' + availablePlatforms.join(', ')
})
}
if (!req.body.input) {
if (!req.query.input && !req.body.input) {
return res.status(400).json({ success: false, data: null, error: 'Input data is required' })
}
const { platform } = req.params;
const { input, deepSearch } = req.body;
const { platform } = req.params ;
const { input, deepSearch } = req.body.input ? req.body : req.query;
const response = await searchInVectors(platform, input);

if (deepSearch === "true") {
Expand Down
16 changes: 16 additions & 0 deletions static/.well-known/ai-plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"schema_version": "v1",
"name_for_human": "Category Taxonomy",
"name_for_model": "category_taxonomy",
"description_for_human": "Plugin to classify products into categories of well-known e-commerce platforms.",
"description_for_model": "Plugin to classify products into categories of well-known e-commerce platforms.",
"auth": { "type": "none" },
"api": {
"type": "openapi",
"url": "http://localhost:6006/openapi.yaml",
"is_user_authenticated": false
},
"logo_url": "http://localhost:6006/logo.png",
"contact_email": "[email protected]",
"legal_info_url": "http://localhost:6006/legal"
}
Binary file added static/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions static/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
openapi: 3.0.1
info:
title: Category Prediction API
version: '1.0'
servers:
- url: 'http://localhost:6006'
paths:
/v2/category/predict/{platform}:
post:
summary: Predict the category for a given platform
operationId: predictCategory
parameters:
- name: platform
in: path
description: The name of the platform to make a prediction for
required: true
schema:
type: string
enum: [trendyol, hepsiburada, ciceksepeti]
- name: input
in: query
description: The name of the product
required: true
schema:
type: string
- name: deepSearch
in: query
description: Flag to indicate whether a deep search should be performed or not
required: true
schema:
type: boolean
responses:
'200':
description: Successful operation
'400':
description: Bad request. User input is invalid.
'500':
description: Internal server error.
2 changes: 1 addition & 1 deletion vectors/ciceksepeti/docstore.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vectors/hepsiburada/docstore.json

Large diffs are not rendered by default.

0 comments on commit 0d4c926

Please sign in to comment.