Skip to content

Commit

Permalink
feat: reorganize the workspace to simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
viveknair committed Apr 8, 2023
1 parent 64564b7 commit 4b3ff74
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ jobs:
- name: Run `openapi` command 🚀
uses: readmeio/rdme@v8
with:
rdme: openapi specs/node-resolved.yaml --key=${{ secrets.README_API_KEY }} --id=643081f907460f03415ae770
rdme: openapi dist/spec-resolved.yaml --key=${{ secrets.README_API_KEY }} --id=643081f907460f03415ae770
if: ${{ steps.release.outputs.release_created }}
4 changes: 2 additions & 2 deletions openapitools.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"node": {
"generatorName": "typescript-axios",
"output": "../gentrace-node/package",
"inputSpec": "./specs/node-resolved.yaml",
"inputSpec": "./dist/node.yaml",
"templateDir": "./templates/node",
"additionalProperties": {
"npmName": "@gentrace/node",
Expand All @@ -20,7 +20,7 @@
"browser": {
"generatorName": "typescript-axios",
"output": "../gentrace-browser",
"inputSpec": "./specs/browser-resolved.yaml",
"inputSpec": "./dist/browser.yaml",
"templateDir": "./templates/browser",
"additionalProperties": {
"npmName": "@gentrace/browser",
Expand Down
20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
"author": "Gentrace",
"license": "MIT",
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.5.2",
"npm-run-all": "^4.1.5",
"@commitlint/cli": "^17.5.1",
"@commitlint/config-conventional": "^17.4.4",
"husky": "^4.3.8"
"@openapitools/openapi-generator-cli": "^2.5.2",
"@types/fs-extra": "^11.0.1",
"@types/js-yaml": "^4.0.5",
"fs-extra": "^11.1.1",
"husky": "^4.3.8",
"npm-run-all": "^4.1.5",
"rimraf": "^4.4.1",
"ts-node": "^10.9.1"
},
"husky": {
"hooks": {
Expand All @@ -24,11 +29,12 @@
]
},
"scripts": {
"build": "run-s config generate",
"build": "run-s sconfig generate",
"clean": "rimraf dist",
"bump-patch": "./scripts/bump-patch",
"config": "run-p config:*",
"config:node-spec": "envsubst '${npm_package_version}' < specs/node.yaml > specs/node-resolved.yaml",
"config:browser-spec": "envsubst '${npm_package_version}' < specs/browser.yaml > specs/browser-resolved.yaml",
"sconfig": "run-s sconfig:spec-version sconfig:create-custom-specs",
"sconfig:spec-version": "mkdir -p dist && envsubst '${npm_package_version}' < spec.yaml > dist/spec-resolved.yaml",
"sconfig:create-custom-specs": "ts-node ./scripts/create-custom-specs.ts",
"generate": "run-s generate:*",
"generate:node-ts": "npx @openapitools/openapi-generator-cli generate --generator-key node",
"generate:browser-ts": "npx @openapitools/openapi-generator-cli generate --generator-key browser"
Expand Down
44 changes: 44 additions & 0 deletions scripts/create-custom-specs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import fs from "fs-extra";
import yaml from "js-yaml";

type OpenAPISpec = {
paths: {
[endpoint: string]: {
[method: string]: {
tags: string[];
};
};
};
};

const ingestionSpec = yaml.load(
fs.readFileSync("spec.yaml", "utf8")
) as OpenAPISpec;

const ingestionTag = "Ingestion";
const ingestionPaths = Object.fromEntries(
Object.entries(ingestionSpec.paths).filter(([, data]) =>
Object.values(data).some((op) => op.tags && op.tags.includes(ingestionTag))
)
);

ingestionSpec.paths = ingestionPaths;

fs.mkdirpSync("dist");
fs.writeFileSync("dist/node.yaml", yaml.dump(ingestionSpec));

const feedbackSpec = yaml.load(
fs.readFileSync("spec.yaml", "utf8")
) as OpenAPISpec;

const feedbackTag = "Feedback";
const feedbackPaths = Object.fromEntries(
Object.entries(feedbackSpec.paths).filter(([, data]) =>
Object.values(data).some((op) => op.tags && op.tags.includes(feedbackTag))
)
);

feedbackSpec.paths = feedbackPaths;

fs.mkdirpSync("dist");
fs.writeFileSync("dist/browser.yaml", yaml.dump(feedbackSpec));
100 changes: 96 additions & 4 deletions specs/node.yaml → spec.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
openapi: "3.0.0"

info:
title: Gentrace Ingestion API
title: Gentrace API
description: These API routes are designed to ingest events from clients.
version: ${npm_package_version}

tags:
- name: Gentrace
description: The Gentrace REST API for capturing pipeline events
- name: Ingestion
description: Endpoints for capturing pipeline events
- name: Feedback
description: Endpoints for capturing user feedback

servers:
- url: https://gentrace.ai/api/v1
Expand All @@ -19,7 +21,7 @@ paths:
/pipeline-run:
post:
tags:
- Gentrace
- Ingestion
summary: Create a pipeline run
requestBody:
required: true
Expand Down Expand Up @@ -171,6 +173,66 @@ paths:
{
"pipelineRunId": "13448D47-BD5D-4664-B6C3-0CB07D8CF2D2"
}
/feedback:
post:
tags:
- Feedback
summary: Submit feedback for a pipeline run
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/FeedbackRequest"
responses:
"200":
description: Feedback submitted successfully
content:
application/json:
schema:
$ref: "#/components/schemas/FeedbackResponse"
"400":
description: Invalid feedback payload
"500":
description: Server error

x-gentraceMeta:
name: Store feedback event
group: ingestion
path: feedback
examples:
curl: |
curl -X POST \
-H 'Authorization: Bearer gen_api_NkztHpkHvl5Z8CXIHZJq3bFPHwO4eLj2dtkh9HGt' \
-H 'Content-Type: application/json' \
-d '{
"pipelineRunId": "cc22e63c-1c9a-4cbb-a8ee-7f764eabf97d",
"rating": "positive",
"recordedTime": "2023-03-31T15:00:00.000Z",
"details": "This generated output communicated my voice wonderfully!"
}' \
https://gentrace.ai/api/v1/feedback
node.js: |
const { Configuration, Gentrace } = require("@gentrace/node");
const configuration = new Configuration({
apiKey: process.env.GENTRACE_API_KEY,
});
const gentrace = new Gentrace(configuration);
gentrace.feedback({
pipelineRunId: "cc22e63c-1c9a-4cbb-a8ee-7f764eabf97d",
rating: "positive",
recordedTime: "2023-03-31T15:00:00.000Z",
details: "This generated output communicated my voice wonderfully!"
});
response: |
{
"pipelineRunId": "13448D47-BD5D-4664-B6C3-0CB07D8CF2D2"
}
components:
securitySchemes:
Expand Down Expand Up @@ -233,3 +295,33 @@ components:
type: string
example:
pipelineRunId: 13448D47-BD5D-4664-B6C3-0CB07D8CF2D2

FeedbackRequest:
type: object
properties:
pipelineRunId:
type: string
format: uuid
rating:
type: string
enum: [positive, negative, neutral]
recordedTime:
type: string
format: date-time
details:
type: string
nullable: true
required:
- pipelineRunId
- rating
- recordedTime
additionalProperties: false
FeedbackResponse:
type: object
properties:
message:
type: string
example: Success
required:
- message
additionalProperties: false
117 changes: 0 additions & 117 deletions specs/browser.yaml

This file was deleted.

0 comments on commit 4b3ff74

Please sign in to comment.