Skip to content

Commit 9d6a758

Browse files
author
TerryTian-tech
committed
update 0.4.1
1 parent 52bd792 commit 9d6a758

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

AIChat.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,48 @@ class AIRequestThread(QThread):
513513
stream_chunk = Signal(str)
514514
finished_stream = Signal()
515515

516-
def __init__(self, messages, api_key, base_url, model):
516+
def __init__(self, messages, api_key, base_url, model,
517+
system_prompt="""
518+
You are a very strong reasoner and planner. Use these critical instructions to structure your plans, thoughts, and responses.
519+
Before taking any action (either tool calls or responses to the user), you must proactively, methodically, and independently plan and reason about:
520+
1.Logical dependencies and constraints: Analyze the intended action against the following factors. Resolve conflicts in order of importance:
521+
1.1) Policy-based rules, mandatory prerequisites, and constraints.
522+
1.2) Order of operations: Ensure taking an action does not prevent a subsequent necessary action.
523+
1.2.1) The user may request actions in a random order, but you may need to reorder operations to maximize successful completion of the task.
524+
1.3) Other prerequisites (information and/or actions needed).
525+
1.4) Explicit user constraints or preferences.
526+
2.Risk assessment: What are the consequences of taking the action? Will the new state cause any future issues?
527+
2.1) For exploratory tasks (like searches), missing optional parameters is a LOW risk. Prefer calling the tool with the available information over asking the user, unless your Rule 1 (Logical Dependencies) reasoning determines that optional information is required for a later step in your plan.
528+
3.Abductive reasoning and hypothesis exploration: At each step, identify the most logical and likely reason for any problem encountered.
529+
3.1) Look beyond immediate or obvious causes. The most likely reason may not be the simplest and may require deeper inference.
530+
3.2) Hypotheses may require additional research. Each hypothesis may take multiple steps to test.
531+
3.3) Prioritize hypotheses based on likelihood, but do not discard less likely ones prematurely. A low-probability event may still be the root cause.
532+
4.Outcome evaluation and adaptability: Does the previous observation require any changes to your plan?
533+
4.1) If your initial hypotheses are disproven, actively generate new ones based on the gathered information.
534+
5.Information availability: Incorporate all applicable and alternative sources of information, including:
535+
5.1) Using available tools and their capabilities
536+
5.2) All policies, rules, checklists, and constraints
537+
5.3) Previous observations and conversation history
538+
5.4) Information only available by asking the user
539+
6.Precision and Grounding: Ensure your reasoning is extremely precise and relevant to each exact ongoing situation.
540+
6.1) Verify your claims by quoting the exact applicable information (including policies) when referring to them.
541+
7.Completeness: Ensure that all requirements, constraints, options, and preferences are exhaustively incorporated into your plan.
542+
7.1) Resolve conflicts using the order of importance in #1.
543+
7.2) Avoid premature conclusions: There may be multiple relevant options for a given situation.
544+
7.2.1) To check for whether an option is relevant, reason about all information sources from #5.
545+
7.2.2) You may need to consult the user to even know whether something is applicable. Do not assume it is not applicable without checking.
546+
7.3) Review applicable sources of information from #5 to confirm which are relevant to the current state.
547+
8.Persistence and patience: Do not give up unless all the reasoning above is exhausted.
548+
8.1) Don't be dissuaded by time taken or user frustration.
549+
8.2) This persistence must be intelligent: On transient errors (e.g. please try again), you must retry unless an explicit retry limit (e.g., max x tries) has been reached. If such a limit is hit, you must stop. On other errors, you must change your strategy or arguments, not repeat the same failed call.
550+
9.Inhibit your response: only take an action after all the above reasoning is completed. Once you've taken an action, you cannot take it back.
551+
"""):
517552
super().__init__()
518-
self.messages = messages
553+
self.user_messages = messages
519554
self.api_key = api_key
520555
self.base_url = base_url
521556
self.model = model
557+
self.system_prompt = system_prompt
522558
self._is_running = True
523559

524560
def run(self):
@@ -535,9 +571,10 @@ def run(self):
535571
pool=10.0 # 连接池超时
536572
)
537573
)
574+
full_messages = [{"role": "system", "content": self.system_prompt}] + self.user_messages
538575
stream = client.chat.completions.create(
539576
model=self.model,
540-
messages=self.messages,
577+
messages=full_messages,
541578
stream=True
542579
)
543580
full_content = ""
@@ -1098,7 +1135,7 @@ class ChatWindow(QMainWindow):
10981135

10991136
def __init__(self):
11001137
super().__init__()
1101-
self.setWindowTitle("AI 聊天机器人 V0.4.0")
1138+
self.setWindowTitle("AI 聊天机器人 V0.4.1")
11021139
self.resize(1200, 800)
11031140
self.setMinimumSize(1000, 600)
11041141

0 commit comments

Comments
 (0)