...
| 코드 블럭 | ||
|---|---|---|
| ||
from promptflow import tool
# The inputs section will change based on the arguments of the tool function, after you save the code
# Adding type to arguments and return value will help the system show the types properly
# Please update the function name/signature per need
@tool
def my_python_tool(search_result: dict):
# print(search_result[0]['original_entity']['text'])
# 검색된 여러개의 문서에서 original_entity의 text 부분만 배열로 만들어서 반환
return [entity['original_entity']['text'] for entity in search_result]
|
| 코드 블럭 |
|---|
# 참고
@tool
def generate_prompt_context(search_result: List[dict]) -> str:
def format_doc(doc: dict):
return f"Content: {doc['Content']}\nSource: {doc['Source']}"
SOURCE_KEY = "source"
URL_KEY = "url"
retrieved_docs = []
for item in search_result:
entity = SearchResultEntity.from_dict(item)
content = entity.text or ""
source = ""
if entity.metadata is not None:
if SOURCE_KEY in entity.metadata:
if URL_KEY in entity.metadata[SOURCE_KEY]:
source = entity.metadata[SOURCE_KEY][URL_KEY] or ""
retrieved_docs.append({
"Content": content,
"Source": source
})
doc_string = "\n\n".join([format_doc(doc) for doc in retrieved_docs])
return doc_string |
| 코드 블럭 | ||
|---|---|---|
| ||
system:
Summary result for question in Korean.
Never use your knowledge and only use the text displayed in ```.
If the question asks for a comparison, display it as a table.
user:
question: {{question}}
search_results:
```
{% for item in search_results %}
{{item}}
{% endfor %}
``` |
...