lihuigu commited on
Commit
23add18
·
1 Parent(s): fe93e75

update prompt

Browse files
Files changed (2) hide show
  1. prompt/prompt_reader.py +82 -0
  2. prompt/summarizing.xml +43 -0
prompt/prompt_reader.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+ # Author: Frank Kang
4
+ # Data: 16 July 2024
5
+
6
+ import xml.etree.ElementTree as ET
7
+ from xml.etree.ElementTree import Element
8
+
9
+
10
+ class Query(object):
11
+ def __init__(self, query_node: Element) -> None:
12
+ super(Query, self).__init__()
13
+ self.rank = int(query_node.get('rank'))
14
+ self.title = query_node.find('title').text
15
+ self.text = query_node.find('text').text
16
+
17
+ @staticmethod
18
+ def Get_Title(query_node: Element) -> str:
19
+ return query_node.find('title').text
20
+
21
+
22
+ class AssistantCreateQuery(Query):
23
+ TITLE = 'System Message'
24
+
25
+ def __init__(self, query_node: Element) -> None:
26
+ super(AssistantCreateQuery, self).__init__(query_node)
27
+
28
+ def __call__(self, name, *args, tools=[{"type": "code_interpreter"}], model="gpt-4-1106-preview", **kwds) -> dict:
29
+ """Get parameters used for client.beta.assistants.create
30
+
31
+ Returns:
32
+ dict: parameters used for client.beta.assistants.create
33
+ """
34
+ return {'name': name, 'instructions': self.text.format(*args, **kwds), 'tools': tools, 'model': model}
35
+
36
+
37
+ class MessageQuery(Query):
38
+ TITLE = 'User Message'
39
+
40
+ def __init__(self, query_node: Element) -> None:
41
+ super(MessageQuery, self).__init__(query_node)
42
+
43
+ def __call__(self, *args, **kwds) -> dict:
44
+ """Using like str.format
45
+
46
+ Returns:
47
+ dict: _description_
48
+ """
49
+ return {'role': 'user', 'content': self.text.format(*args, **kwds)}
50
+
51
+
52
+ class Prompt(object):
53
+ def __init__(self, path) -> None:
54
+ """Init Prompy by xml file
55
+
56
+ Args:
57
+ path (_type_): _description_
58
+ """
59
+ super(Prompt, self).__init__()
60
+ self.path = path
61
+ tree = ET.parse(path)
62
+ body = tree.getroot()
63
+ self.queries = {}
64
+ for query in body.findall('query'):
65
+ self.__read_query__(query)
66
+
67
+ def __read_query__(self, query_node: Element):
68
+ title = Query.Get_Title(query_node)
69
+ query: Query
70
+ if title == AssistantCreateQuery.TITLE:
71
+ query = AssistantCreateQuery(query_node)
72
+ elif title == MessageQuery.TITLE:
73
+ query = MessageQuery(query_node)
74
+ else:
75
+ raise TypeError('Title not supported!')
76
+
77
+ if query.rank not in self.queries:
78
+ self.queries[query.rank] = [query]
79
+ else:
80
+ self.queries[query.rank].append(query)
81
+
82
+ # def __call__(self, *args: ET.Any, **kwds: ET.Any) -> list:
prompt/summarizing.xml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE body [
3
+ <!ENTITY warning "Warning: Something bad happened... please refresh and try again.">
4
+ ]>
5
+ <body>
6
+ <query rank="0">
7
+ <title>User Message</title>
8
+ <text>
9
+ Task Description:
10
+
11
+ You are provided with the title, abstract, and introduction of a research paper. Your task is to generate a concise summary of what kind of problem does this paper aim to solve and what methods are proposed to address it. The summary should follow this format:
12
+ The problem of [problem] can be addressed by [main idea/approach].
13
+
14
+ Instructions:
15
+
16
+ Title: Read the title to understand the general topic of the paper.
17
+ Abstract: Read the abstract to get a concise summary of the research, including the problem addressed, the methods used, and the main findings.
18
+ Introduction: Read the introduction to gain a deeper understanding of the background, significance, and specific problem the paper addresses, as well as the proposed approach or solution.
19
+ Based on the provided information, generate a single sentence that captures the essence of the paper, following the format specified above.
20
+
21
+ Your Turn:
22
+
23
+ Given the following paper information:
24
+ Title: {title}
25
+ Abstract: {abstract}
26
+ Introduction: {introduction}
27
+
28
+ Output:
29
+ The problem of [problem] can be addressed by [main idea/approach].
30
+ </text>
31
+ </query>
32
+ <query rank="1">
33
+ <title>User Message</title>
34
+ <text>
35
+ Please read the title, abstract, and introduction of the paper again, as well as the summary you provided. Complete the following two tasks:
36
+ 1.Briefly provide the two most critical motivations behind proposing these methods to address the problems.
37
+ 2.Briefly provide the three most critical or innovative details of the paper that were not mentioned in your summary (It's best if these details are the new methods or techniques adopted in this paper).
38
+
39
+ Output:
40
+ Motivations:1.[motivation1]. 2.[motivation2]. Details:1.[detail1]. 2.[detail2]. 3.[detail3].
41
+ </text>
42
+ </query>
43
+ </body>