Skip to content

Commit 36a85d5

Browse files
author
handong
committed
openai client
1 parent 64778c6 commit 36a85d5

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

KAG_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.8.0.20250623
1+
0.8.0.20250616.18

kag/common/llm/openai_client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
logging.getLogger("openai").setLevel(logging.ERROR)
2424
logging.getLogger("httpx").setLevel(logging.ERROR)
2525
logger = logging.getLogger(__name__)
26+
import json
2627

2728
AzureADTokenProvider = Callable[[], str]
2829

@@ -148,6 +149,15 @@ def __call__(self, prompt: str = "", image_url: str = None, **kwargs):
148149
rsp = response.choices[0].message.content
149150
tool_calls = response.choices[0].message.tool_calls
150151
usages.append(response.usage)
152+
if self.model in ["corpus_tianchang_qwen2_5_72b_instruct"]:
153+
# 特殊模型格式处理
154+
message_content = response.choices[0].message.content
155+
data_dict = json.loads(message_content)
156+
rsp = data_dict["choices"][0]["message"]["content"]
157+
tool_calls = data_dict["choices"][0]["message"]["tool_calls"]
158+
else:
159+
rsp = response.choices[0].message.content
160+
tool_calls = response.choices[0].message.tool_calls
151161
else:
152162
rsp = ""
153163
tool_calls = None # TODO: Handle tool calls in stream mode
@@ -234,6 +244,15 @@ async def acall(self, prompt: str = "", image_url: str = None, **kwargs):
234244
rsp = response.choices[0].message.content
235245
tool_calls = response.choices[0].message.tool_calls
236246
usages.append(response.usage)
247+
if self.model in ["corpus_tianchang_qwen2_5_72b_instruct"]:
248+
# 特殊模型格式处理
249+
message_content = response.choices[0].message.content
250+
data_dict = json.loads(message_content)
251+
rsp = data_dict["choices"][0]["message"]["content"]
252+
tool_calls = data_dict["choices"][0]["message"]["tool_calls"]
253+
else:
254+
rsp = response.choices[0].message.content
255+
tool_calls = response.choices[0].message.tool_calls
237256
else:
238257
rsp = ""
239258
tool_calls = None

kag/solver/executor/deduce/kag_output_executor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def invoke(self, query: str, task: Any, context: Context, **kwargs):
9595
dep_context = []
9696
for p in task.parents:
9797
dep_context.append(p.get_task_context())
98+
if not dep_context:
99+
logger.warning(f"no dep context the query is:{query}")
98100
result = self.llm_module.invoke(
99101
{"question": query, "context": dep_context},
100102
self.summary_prompt,

kag/solver/pipeline/kag_static_pipeline.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ async def ainvoke(self, query, **kwargs):
124124
finished = False
125125
while True:
126126
context: Context = Context()
127-
tasks = await self.planning(query, context, **kwargs)
128-
127+
tasks,think_response = await self.planning(query, context, **kwargs)
128+
if not tasks:
129+
answer = await self.generator.ainvoke(query+"\n"+think_response, context, **kwargs)
130+
return answer
129131
for task in tasks:
130132
context.add_task(task)
131133

0 commit comments

Comments
 (0)