I am using flask-restx
Given the code below , I expect to see create_prompt_model in the Swagger UI for POST/prompts/create, but I see update_prompt_model in the Swagger UI
Swagger UI screenshot for POST/prompts/create
My code for the prompts namesppce that I am adding to my api.py:
from uuid import uuid4
from flask import jsonify, request
from flask_restx import Resource, Namespace, fields, reqparse
from datastore.azure_cosmosdb.store import CosmosDb
import os
import yaml
from prompts.service import PromptsService
prompts_namespace = Namespace('prompts', description='Prompts CRUD')
AZURE_COSMOS_DB_ENDPOINT = os.getenv("AZURE_COSMOS_DB_ENDPOINT")
AZURE_COSMOS_DB_KEY = os.getenv("AZURE_COSMOS_DB_KEY")
with open(r'config/config.yml', 'r') as f:
all_configs = yaml.safe_load(f)
space = all_configs['space']
cosmos_db_name = all_configs["cosmos_db"]["DB_NAME"]
container_name = all_configs["prompt_store"]["CONTAINER_NAME"]
prompt_store_config = {"DB_NAME": cosmos_db_name,
"CONTAINER_NAME":container_name,
"URL":AZURE_COSMOS_DB_ENDPOINT,
"KEY":AZURE_COSMOS_DB_KEY}
prompts_store = CosmosDb(config=prompt_store_config)
prompt_service = PromptsService(db=prompts_store)
get_query_model = prompts_namespace.model('GetQuery', {
'filters': fields.String(description='Query values', required=True)
})
create_prompt_model = prompts_namespace.model('Prompts', {
'description': fields.String(description='Desc of prompt', required=True),
'prompt_set': fields.Raw(description='Dictionary consisting of the keys short_prompt and long_prompt', required=True)
})
update_prompt_model = prompts_namespace.model('Prompts', {
'root_prompt_id': fields.String(description='The id of the root prompt for which we need to create a new version', required=True),
'description': fields.String(description='Desc of prompt', required=False),
'updated_prompt_set': fields.Raw(description='Dictionary consisting of the keys short_prompt and long_prompt', required=True)
})
@prompts_namespace.route('/<string:prompt_id>')
class Prompt(Resource):
@prompts_namespace.doc(params={'prompt_id':'id of the prompt'})
def get(self,prompt_id):
"""
get a prompt set with provided prompt_id
Parameters
----------
prompt_id: id of the prompt set
Returns
-------
A prompt set with the provided prompt_id
"""
result = prompt_service.get(prompt_id)
print(result)
return jsonify(result)
@prompts_namespace.route('/create')
class CreatePrompt(Resource):
@prompts_namespace.expect(create_prompt_model)
def post(self):
"""
Upserts an item (consisting of the given prompt set and description) in the prompt store
Parameters
---------
prompt_set: A dictionary consisting of the Long and short prompt templates
description: Description of the prompt set
Returns
-------
id of the prompt upserted in the the prompt store
"""
body = request.json
description = body['description']
prompt_set = body['prompt_set']
prompt_id = prompt_service.create(prompt_set,description)
return prompt_id
@prompts_namespace.route('/update')
class UpdatePrompt(Resource):
@prompts_namespace.expect(update_prompt_model)
def post(self):
"""
Given an existing prompt id, Create a new prompt set with provided description and updated_prompt_set.
The version of this newly created prompt set will be (latest version among all the prompt sets with the specified prompt id) + 1
Parameters
----------
root_prompt_id: The id of the root prompt for which we need to create a new version
description: description of the prompt set
updated_prompt_set: updated prompt set to be created for the descripiton
Returns
-------
message:tells whether the updated happened
"""
body = request.json
description = body.get('description')
updated_prompt_set = body.get('updated_prompt_set')
root_prompt_id = body.get('root_prompt_id')
return prompt_service.update(root_prompt_id=root_prompt_id,
description=description,
updated_prompt_set=updated_prompt_set)
I expect to see create_prompt_model in the Swagger UI for POST/prompts/create, but I see update_prompt_model in the Swagger UI