1010
1111from jao_backend_schemas .advice import AdviceResponse
1212from jao_backend_schemas .advice import AdviceRequest
13+ from jao_backend_schemas .draft import DraftResponse
14+ from jao_backend_schemas .draft import DraftRequest
1315from jao_backend_schemas .maps import AreaFrequenciesResponse
1416from jao_backend_schemas .plots import PlotlyFiguresResponse
1517from jao_backend_schemas .vacancies import SimilarVacanciesResponse
1921from jao_backend .common .text_processing .clean_oleeo import parse_oleeo_bbcode
2022from jao_backend .embeddings .models import EmbeddingTag
2123from jao_backend .vacancies .models import VacancyEmbedding
22- from jao_backend .advice . advice import AdviceService
23- advice_service = AdviceService ()
24+ from jao_backend .llm . llm_service import LLMService
25+ llm_service = LLMService ()
2426
2527logger = logging .getLogger (__name__ )
2628
@@ -78,6 +80,23 @@ def get_similar_vacancies(text, top_n=10):
7880 ]
7981
8082
83+ @api .post ("/similar_adverts" , response = SimilarVacanciesResponse )
84+ def similar_adverts (
85+ request : HttpRequest , payload : JobDescriptionRequest
86+ ) -> SimilarVacanciesResponse :
87+ similar_vacancies_list = [
88+ VacancyListing .model_validate (
89+ {
90+ "job_title" : vacancy .title ,
91+ "full_job_desc" : parse_oleeo_bbcode (vacancy .description ),
92+ "vacancy_id" : vacancy .pk ,
93+ }
94+ )
95+ for vacancy in get_similar_vacancies_cached (payload .description , top_n = 10 )
96+ ]
97+ return SimilarVacanciesResponse (similar_vacancies = similar_vacancies_list )
98+
99+
81100@api .post ("/advice" )
82101def advice (request : HttpRequest , payload : AdviceRequest ) -> StreamingHttpResponse :
83102 formatted_vacancies = [
@@ -88,9 +107,9 @@ def advice(request: HttpRequest, payload: AdviceRequest) -> StreamingHttpRespons
88107
89108 def generate ():
90109 """Generator for streaming response"""
91- for chunk in advice_service .get_advice (payload .description ,
92- formatted_vacancies ,
93- payload .advice_type ):
110+ for chunk in llm_service .get_advice (payload .description ,
111+ formatted_vacancies ,
112+ payload .advice_type ):
94113 logger .debug (f"Streaming chunk: { chunk } " )
95114 yield f"data: { json .dumps ({'content' : chunk })} \n \n "
96115
@@ -101,69 +120,71 @@ def generate():
101120 )
102121
103122
104- @api .post ("/similar_adverts" , response = SimilarVacanciesResponse )
105- def similar_adverts (
106- request : HttpRequest , payload : JobDescriptionRequest
107- ) -> SimilarVacanciesResponse :
108- similar_vacancies_list = [
109- VacancyListing .model_validate (
110- {
111- "job_title" : vacancy .title ,
112- "full_job_desc" : parse_oleeo_bbcode (vacancy .description ),
113- "vacancy_id" : vacancy .pk ,
114- }
115- )
116- for vacancy in get_similar_vacancies_cached (payload .description , top_n = 10 )
123+ @api .post ("/draft" )
124+ def draft (request : HttpRequest , payload : DraftResponse ) -> StreamingHttpResponse :
125+ formatted_vacancies = [
126+ f"Job Title: { vacancy .job_title } \n Description: {
127+ parse_oleeo_bbcode (vacancy .full_job_desc )} "
128+ for vacancy in payload .similar_vacancies
117129 ]
118- return SimilarVacanciesResponse (similar_vacancies = similar_vacancies_list )
119-
120- # Write a query using the similar vacancies data from application stastics -
121- # aggregated application statistic model
122-
123130
124- @api .post ("/similar_advert_plots" )
125- def similar_advert_plots (
126- request : HttpRequest , payload : JobDescriptionRequest
127- ) -> PlotlyFiguresResponse :
128- """
129- Get a graph of the job description.
130- """
131- # Stub: this required aggregated data
132- logger .info (
133- "STUB: similar_advert_plots endpoint called with description: %s" ,
134- payload .description ,
131+ def generate ():
132+ for chunk in llm_service .get_draft (payload .description , formatted_vacancies ):
133+ yield f"data: { json .dumps ({'content' : chunk })} \n \n "
134+ yield "data: [DONE]\n \n "
135+ return StreamingHttpResponse (
136+ generate (),
137+ content_type = 'text/event-stream'
135138 )
136- graphs = []
137- return PlotlyFiguresResponse (plotly_figures = graphs )
138-
139- # ADD Skills Ingester to write skills to DB
140139
141140
142- @api .post ("/skills_plots" )
143- def skills_plots (request , payload : JobDescriptionRequest ) -> PlotlyFiguresResponse :
144- """
145- Get a graph of the job description.
146- """
147- # Stub: skills are not ingested right now.
148- logger .info (
149- "STUB: skills_plots endpoint called with description: %s" , payload .description
150- )
151- graphs = []
152- result = PlotlyFiguresResponse (plotly_figures = graphs )
153- return result
154-
155- # Maybe REMOVE the location response
141+ # Write a query using the similar vacancies data from application stastics -
142+ # aggregated application statistic model
156143
157144
158- @api .post ("/applicant_locations" )
159- def applicant_locations (
160- request , payload : JobDescriptionRequest
161- ) -> AreaFrequenciesResponse :
162- # Stub: OLEEO ingestion of locations is TBD
163- logger .info (
164- "STUB: applicant_locations endpoint called with description: %s" ,
165- payload .description ,
166- )
167- area_frequencies : AreaFrequencyProperties = []
168- # TODO: populate area_frequencies with instances of AreaFrequencyProperties from the database.
169- return AreaFrequenciesResponse (area_frequencies = area_frequencies )
145+ # @api.post("/similar_advert_plots")
146+ # def similar_advert_plots(
147+ # request: HttpRequest, payload: JobDescriptionRequest
148+ # ) -> PlotlyFiguresResponse:
149+ # """
150+ # Get a graph of the job description.
151+ # """
152+ # # Stub: this required aggregated data
153+ # logger.info(
154+ # "STUB: similar_advert_plots endpoint called with description: %s",
155+ # payload.description,
156+ # )
157+ # graphs = []
158+ # return PlotlyFiguresResponse(plotly_figures=graphs)
159+ #
160+ # # ADD Skills Ingester to write skills to DB
161+ #
162+ #
163+ # @api.post("/skills_plots")
164+ # def skills_plots(request, payload: JobDescriptionRequest) -> PlotlyFiguresResponse:
165+ # """
166+ # Get a graph of the job description.
167+ # """
168+ # # Stub: skills are not ingested right now.
169+ # logger.info(
170+ # "STUB: skills_plots endpoint called with description: %s", payload.description
171+ # )
172+ # graphs = []
173+ # result = PlotlyFiguresResponse(plotly_figures=graphs)
174+ # return result
175+ #
176+ # # Maybe REMOVE the location response
177+ #
178+ #
179+ # @api.post("/applicant_locations")
180+ # def applicant_locations(
181+ # request, payload: JobDescriptionRequest
182+ # ) -> AreaFrequenciesResponse:
183+ # # Stub: OLEEO ingestion of locations is TBD
184+ # logger.info(
185+ # "STUB: applicant_locations endpoint called with description: %s",
186+ # payload.description,
187+ # )
188+ # area_frequencies: AreaFrequencyProperties = []
189+ # # TODO: populate area_frequencies with instances of AreaFrequencyProperties from the database.
190+ # return AreaFrequenciesResponse(area_frequencies=area_frequencies)
0 commit comments