@@ -24,20 +24,19 @@ def __init__(self) -> None:
2424 )
2525
2626 self .client = AsyncOpenAI (api_key = settings .OPENAI_API_KEY )
27- self ._model = "gpt-5-nano-2025-08-07 "
27+ self ._model = "gpt-4o-mini "
2828
2929 async def extract_keywords (self , user_text : str ) -> List [str ]:
3030 """
3131 Extracts a list of keywords from a given user text using the OpenAI model.
3232 Returns a list of strings. If parsing fails, returns an empty list.
3333 """
3434
35- response = await self .client .responses .create (
35+ response = await self .client .chat . completions .create (
3636 model = self ._model ,
37- reasoning = {"effort" : "low" },
38- input = [
37+ messages = [
3938 {
40- "role" : "developer " ,
39+ "role" : "system " ,
4140 "content" : KEYWORD_PROMPT ,
4241 },
4342 {
@@ -48,7 +47,7 @@ async def extract_keywords(self, user_text: str) -> List[str]:
4847 )
4948
5049 try :
51- keyword_list = json .loads (response .output_text )
50+ keyword_list = json .loads (response .choices [ 0 ]. message . content or "[]" )
5251 except json .decoder .JSONDecodeError :
5352 keyword_list = []
5453
@@ -67,12 +66,11 @@ async def extract_keywords_from_pdf(
6766
6867 user_content = f"User focus (optional): { user_focus } \n \n " f"Paper text: \n { pdf_text } "
6968
70- response = await self .client .responses .create (
69+ response = await self .client .chat . completions .create (
7170 model = self ._model ,
72- reasoning = {"effort" : "medium" },
73- input = [
71+ messages = [
7472 {
75- "role" : "developer " ,
73+ "role" : "system " ,
7674 "content" : PDF_KEYWORD_PROMPT ,
7775 },
7876 {
@@ -83,7 +81,7 @@ async def extract_keywords_from_pdf(
8381 )
8482
8583 try :
86- keyword_list = json .loads (response .output_text )
84+ keyword_list = json .loads (response .choices [ 0 ]. message . content or "[]" )
8785 except json .decoder .JSONDecodeError :
8886 keyword_list = []
8987
@@ -126,35 +124,27 @@ async def summarise_paper(self, paper_text: str, query: str) -> Dict[str, Any]:
126124 if has_query :
127125 prompt_content += f"\n \n User query: { query } "
128126
129- response = await self .client .responses .create (
127+ response = await self .client .chat . completions .create (
130128 model = self ._model ,
131- reasoning = {"effort" : "medium" },
132- input = [
129+ messages = [
133130 {
134- "role" : "developer " ,
131+ "role" : "system " ,
135132 "content" : prompt_content ,
136133 },
137134 {
138135 "role" : "user" ,
139136 "content" : paper_text ,
140137 },
141138 ],
142- text = {
143- "format" : {
144- "type" : "json_schema" ,
145- "name" : "paper_summary" ,
146- "schema" : schema ,
147- "strict" : False ,
148- }
149- },
139+ response_format = {"type" : "json_object" },
150140 )
151141
152142 try :
153- data = json .loads (response .output_text )
143+ data = json .loads (response .choices [ 0 ]. message . content or "{}" )
154144 except (json .decoder .JSONDecodeError , KeyError ):
155145 data = {
156146 "title" : "Summary (Parsing Fallback)" ,
157- "executive_summary" : response .output_text .strip (),
147+ "executive_summary" : ( response .choices [ 0 ]. message . content or "" ) .strip (),
158148 "methodology_points" : [],
159149 "results_points" : [],
160150 "limitations" : "Parsing failed." ,
@@ -171,18 +161,18 @@ async def chat_about_paper(
171161 Handles a chat turn using the full paper text as context.
172162 """
173163
174- input_messages : List [Dict [str , str ]] = [
175- {"role" : "developer " , "content" : CHAT_PROMPT },
176- {"role" : "developer " , "content" : f"RESEARCH PAPER TEXT:\n \n { paper_text } " },
164+ messages : List [Dict [str , str ]] = [
165+ {"role" : "system " , "content" : CHAT_PROMPT },
166+ {"role" : "system " , "content" : f"RESEARCH PAPER TEXT:\n \n { paper_text } " },
177167 ]
178168
179169 if chat_history :
180- input_messages .extend (chat_history )
170+ messages .extend (chat_history )
181171
182- input_messages .append ({"role" : "user" , "content" : user_query })
172+ messages .append ({"role" : "user" , "content" : user_query })
183173
184- response = await self .client .responses .create (
185- model = self ._model , reasoning = { "effort" : "medium" }, input = cast (Any , input_messages )
174+ response = await self .client .chat . completions .create (
175+ model = self ._model , messages = cast (Any , messages )
186176 )
187177
188- return response .output_text .strip ()
178+ return ( response .choices [ 0 ]. message . content or "" ) .strip ()
0 commit comments