Skip to content

Commit

Permalink
Add specification generation
Browse files Browse the repository at this point in the history
  • Loading branch information
milesha committed Oct 2, 2024
1 parent cf72601 commit e24285c
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 43 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"generate:api:application-server-specs": "cd server/application-server && mvn verify -DskipTests=true && node ../../scripts/clean-openapi-specs.js",
"generate:api:application-server-client": "npx openapi-generator-cli generate -i server/application-server/openapi.yaml -g typescript-angular -o webapp/src/app/core/modules/openapi --additional-properties fileNaming=kebab-case,withInterfaces=true --generate-alias-as-model",
"generate:api": "npm run generate:api:application-server-specs && npm run generate:api:clean && npm run generate:api:application-server-client",
"generate:api:intelligence-service-client": "npx @openapitools/openapi-generator-cli generate -i server/intelligence-service/openapi.yaml -g java -o server/intelligence-service/java-client"
"generate:api:intelligence-service-specs": "python -m server.intelligence-service.app.generate_openapi_yaml",
"generate:api:intelligence-service-client": "npx @openapitools/openapi-generator-cli generate -i server/intelligence-service/openapi.yaml -g java -o server/intelligence-service/java-client",
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "2.13.5",
Expand Down
30 changes: 30 additions & 0 deletions server/intelligence-service/app/generate_openapi_yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from . import main
from fastapi.openapi.utils import get_openapi
import yaml


def get_openapi_specs():
openapi_json = get_openapi(
title=main.app.title,
version=main.app.version,
description=main.app.description,
contact=main.app.contact,
routes=main.app.routes,
)
openapi_yaml = yaml.dump(openapi_json)
return openapi_yaml


def convert():
try:
yaml_spec = get_openapi_specs()
with open("server/intelligence-service/openapi.yaml", "w") as f:
f.write(yaml_spec)
print("OpenAPI YAML specification generated successfully.")
except Exception as e:
print(f"Error generating OpenAPI specs: {e}")
exit(1)


if __name__ == "__main__":
convert()
8 changes: 7 additions & 1 deletion server/intelligence-service/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
from pydantic import BaseModel
from .model import model

app = FastAPI()

app = FastAPI(
title="Hephaestus Intelligence Service API",
description="API documentation for the Hephaestus Intelligence Service.",
version="0.0.1",
contact={"name": "Felix T.J. Dietrich", "email": "[email protected]"},
)


class ChatRequest(BaseModel):
Expand Down
102 changes: 61 additions & 41 deletions server/intelligence-service/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,62 +1,82 @@
openapi: 3.0.1
components:
schemas:
ChatRequest:
properties:
message:
title: Message
type: string
required:
- message
title: ChatRequest
type: object
ChatResponse:
properties:
response:
title: Response
type: string
required:
- response
title: ChatResponse
type: object
HTTPValidationError:
properties:
detail:
items:
$ref: '#/components/schemas/ValidationError'
title: Detail
type: array
title: HTTPValidationError
type: object
ValidationError:
properties:
loc:
items:
anyOf:
- type: string
- type: integer
title: Location
type: array
msg:
title: Message
type: string
type:
title: Error Type
type: string
required:
- loc
- msg
- type
title: ValidationError
type: object
info:
title: Hephaestus Intelligence API
description: API documentation for the Hephaestus intelligence service.
contact:
name: Felix T.J. Dietrich
email: [email protected]
license:
name: MIT License
url: https://github.com/ls1intum/Hephaestus/blob/develop/LICENSE
name: Felix T.J. Dietrich
description: API documentation for the Hephaestus Intelligence Service.
title: Hephaestus Intelligence Service API
version: 0.0.1
servers:
- url: http://localhost:8080
description: Local development server
openapi: 3.1.0
paths:
/chat:
post:
summary: Chat with LLM
operationId: chatWithLLM
operationId: chat_chat_post
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ChatRequest'
required: true
responses:
'200':
description: Successful response from LLM
content:
application/json:
schema:
$ref: '#/components/schemas/ChatResponse'
'500':
description: Internal Server Error
description: Successful Response
'422':
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
components:
schemas:
ChatRequest:
type: object
properties:
message:
type: string
description: The message to be sent to the LLM
required:
- message
ChatResponse:
type: object
properties:
response:
type: string
description: The response generated by the LLM
required:
- response
ErrorResponse:
type: object
properties:
detail:
type: string
description: Error message in case of failure
$ref: '#/components/schemas/HTTPValidationError'
description: Validation Error
summary: Chat with LLM

0 comments on commit e24285c

Please sign in to comment.