Skip to content

Commit

Permalink
fix(ChatKnowledge): summary support zhipu message_converter (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aries-ckt authored Jan 18, 2024
1 parent 0936856 commit 0162dee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 3 additions & 1 deletion dbgpt/app/knowledge/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,9 @@ async def document_summary(self, request: DocumentSummaryRequest):
assembler = SummaryAssembler(
knowledge=knowledge,
model_name=request.model_name,
llm_client=DefaultLLMClient(worker_manager=worker_manager),
llm_client=DefaultLLMClient(
worker_manager=worker_manager, auto_convert_message=True
),
language=CFG.LANGUAGE,
chunk_parameters=chunk_parameters,
)
Expand Down
4 changes: 2 additions & 2 deletions dbgpt/rag/extractor/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
the summary should be as concise as possible and not overly lengthy.Please keep the answer within approximately 200 characters.
"""

REFINE_SUMMARY_TEMPLATE_ZH = """我们已经提供了一个到某一点的现有总结:{context}\n 请根据你之前推理的内容进行最终的总结,总结回答的时候最好按照1.2.3.进行. 注意:请用<中文>来进行总结。"""
REFINE_SUMMARY_TEMPLATE_ZH = """我们已经提供了一个到某一点的现有总结:{context}\n 请根据你之前推理的内容进行总结,总结回答的时候最好按照1.2.3.进行. 注意:请用<中文>来进行总结。"""

REFINE_SUMMARY_TEMPLATE_EN = """
We have provided an existing summary up to a certain point: {context}, We have the opportunity to refine the existing summary (only if needed) with some more context below.
Expand Down Expand Up @@ -144,7 +144,7 @@ async def _llm_run_tasks(
from dbgpt.core import ModelMessage

prompt = prompt_template.format(context=chunk_text)
messages = [ModelMessage(role=ModelMessageRoleType.SYSTEM, content=prompt)]
messages = [ModelMessage(role=ModelMessageRoleType.HUMAN, content=prompt)]
request = ModelRequest(model=self._model_name, messages=messages)
tasks.append(self._llm_client.generate(request))
summary_results = await run_async_tasks(
Expand Down
13 changes: 6 additions & 7 deletions examples/awel/simple_rag_summary_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,23 @@
.. code-block:: shell
DBGPT_SERVER="http://127.0.0.1:5000"
FILE_PATH="{your_file_path}"
curl -X POST http://127.0.0.1:5555/api/v1/awel/trigger/examples/rag/summary \
-H "Content-Type: application/json" -d '{
"file_path": $FILE_PATH
"url": "https://docs.dbgpt.site/docs/awel"
}'
"""
from typing import Dict

from dbgpt._private.pydantic import BaseModel, Field
from dbgpt.core.awel import DAG, HttpTrigger, MapOperator
from dbgpt.model import OpenAILLMClient
from dbgpt.rag.knowledge.base import KnowledgeType
from dbgpt.rag.operator.knowledge import KnowledgeOperator
from dbgpt.rag.operator.summary import SummaryAssemblerOperator


class TriggerReqBody(BaseModel):
file_path: str = Field(..., description="file_path")
url: str = Field(..., description="url")


class RequestHandleOperator(MapOperator[TriggerReqBody, Dict]):
Expand All @@ -47,7 +46,7 @@ def __init__(self, **kwargs):

async def map(self, input_value: TriggerReqBody) -> Dict:
params = {
"file_path": input_value.file_path,
"url": input_value.url,
}
print(f"Receive input value: {input_value}")
return params
Expand All @@ -58,9 +57,9 @@ async def map(self, input_value: TriggerReqBody) -> Dict:
"/examples/rag/summary", methods="POST", request_body=TriggerReqBody
)
request_handle_task = RequestHandleOperator()
path_operator = MapOperator(lambda request: request["file_path"])
path_operator = MapOperator(lambda request: request["url"])
# build knowledge operator
knowledge_operator = KnowledgeOperator()
knowledge_operator = KnowledgeOperator(knowledge_type=KnowledgeType.URL)
# build summary assembler operator
summary_operator = SummaryAssemblerOperator(
llm_client=OpenAILLMClient(), language="en"
Expand Down

0 comments on commit 0162dee

Please sign in to comment.