auto-coder 0.1.345__py3-none-any.whl → 0.1.347__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of auto-coder might be problematic. Click here for more details.

@@ -1,6 +1,7 @@
1
1
  from abc import ABC, abstractmethod
2
- from typing import List, Dict, Any,Generator
2
+ from typing import List, Dict, Any, Generator
3
3
  import byzerllm
4
+ from autocoder.common import AutoCoderArgs
4
5
 
5
6
  class QAConversationStrategy(ABC):
6
7
  """
@@ -26,6 +27,9 @@ class MultiRoundStrategy(QAConversationStrategy):
26
27
  Multi-round strategy: First let the model read documents, then do Q&A.
27
28
  Creates multiple conversation turns.
28
29
  """
30
+ def __init__(self, args: AutoCoderArgs):
31
+ self.args = args
32
+
29
33
  def create_conversation(self, documents: List[Any], conversations: List[Dict[str,str]], local_image_host: str) -> List[Dict]:
30
34
  messages = []
31
35
  messages.extend([
@@ -36,7 +40,7 @@ class MultiRoundStrategy(QAConversationStrategy):
36
40
  return messages
37
41
 
38
42
  @byzerllm.prompt()
39
- def _read_docs_prompt(
43
+ def _read_docs_prompt_old(
40
44
  self, relevant_docs: List[str], local_image_host: str
41
45
  ) -> Generator[str, None, None]:
42
46
  """
@@ -68,6 +72,76 @@ class MultiRoundStrategy(QAConversationStrategy):
68
72
  例如:/path/to/images/image.png, 返回 http://{{ local_image_host }}/static/path/to/images/image.png
69
73
  {% endif %}
70
74
  """
75
+
76
+ @byzerllm.prompt()
77
+ def _read_docs_prompt(
78
+ self, relevant_docs: List[str], local_image_host: str
79
+ ) -> Generator[str, None, None]:
80
+ """
81
+ You are a knowledgeable assistant capable of answering any user question strictly based on the retrieved documents.
82
+
83
+ ====
84
+
85
+ FILES CONTEXT
86
+
87
+ The following files are provided to you as context for the user's task. Use these files to understand the project and answer questions strictly based on their content.
88
+
89
+ <documents>
90
+ {% for doc in relevant_docs %}
91
+ {{ doc }}
92
+ {% endfor %}
93
+ </documents>
94
+
95
+ ====
96
+ {% endif %}
97
+
98
+ INSTRUCTIONS
99
+
100
+ - Use ONLY the information from the provided documents and extension docs.
101
+ - If the documents do not contain enough information to answer, reply: "抱歉,文档中没有足够的信息来回答这个问题。"
102
+ - Do NOT invent, guess, or add information beyond what is provided.
103
+
104
+ - For Markdown images like ![image](/path/to/image.png):
105
+ - Analyze surrounding text to determine relevance.
106
+ - Include relevant images naturally in your answer, preserving image paths.
107
+ - Convert Windows paths to Linux style (e.g., C:\\path\\to\\img.png -> C:/path/to/img.png)
108
+ {% if local_image_host %}
109
+ - Prefix image URLs with http://{{ local_image_host }}/static/
110
+ {% endif %}
111
+
112
+ - Format your answer with Markdown for readability.
113
+ - Always use the language used by the user in their question.
114
+
115
+ {% if extra_docs %}
116
+ ====
117
+
118
+ RULES PROVIDED BY USER
119
+
120
+ The following rules are provided by the user, and you must follow them strictly.
121
+
122
+ {% for key, value in extra_docs.items() %}
123
+ ### {{ key }}
124
+ {{ value }}
125
+ {% endfor %}
126
+ {% endif %}
127
+
128
+ """
129
+
130
+ import os
131
+ extra_docs = {}
132
+ rules_dir = os.path.join(self.args.source_dir, ".autocoderrules")
133
+ if os.path.isdir(rules_dir):
134
+ for fname in os.listdir(rules_dir):
135
+ if fname.endswith(".md"):
136
+ fpath = os.path.join(rules_dir, fname)
137
+ try:
138
+ with open(fpath, "r", encoding="utf-8") as f:
139
+ content = f.read()
140
+ key = os.path.splitext(fname)[0]
141
+ extra_docs[key] = content
142
+ except Exception:
143
+ continue
144
+ return {"extra_docs": extra_docs}
71
145
 
72
146
  class SingleRoundStrategy(QAConversationStrategy):
73
147
  """
@@ -81,7 +155,7 @@ class SingleRoundStrategy(QAConversationStrategy):
81
155
  return messages
82
156
 
83
157
  @byzerllm.prompt()
84
- def _single_round_answer_question(
158
+ def _single_round_answer_question_old(
85
159
  self, relevant_docs: List[str], conversations: List[Dict[str, str]], local_image_host: str
86
160
  ) -> Generator[str, None, None]:
87
161
  """
@@ -120,26 +194,105 @@ class SingleRoundStrategy(QAConversationStrategy):
120
194
  例如:/path/to/images/image.png, 返回 http://{{ local_image_host }}/static/path/to/images/image.png
121
195
  {% endif %}
122
196
  """
197
+
198
+ @byzerllm.prompt()
199
+ def _single_round_answer_question(
200
+ self, relevant_docs: List[str], conversations: List[Dict[str, str]], local_image_host: str
201
+ ) -> Generator[str, None, None]:
202
+ """
203
+ You are a knowledgeable assistant capable of answering any user question strictly based on the retrieved documents.
204
+
205
+ ====
123
206
 
124
- def get_qa_strategy(strategy_name: str) -> QAConversationStrategy:
207
+ FILES CONTEXT
208
+
209
+ The following files are provided to you as context for the user's task. Use these files to understand the project and answer questions strictly based on their content.
210
+
211
+ <documents>
212
+ {% for doc in relevant_docs %}
213
+ {{ doc }}
214
+ {% endfor %}
215
+ </documents>
216
+
217
+ ====
218
+ {% endif %}
219
+
220
+ USER CONVERSATION HISTORY
221
+
222
+ {% for msg in conversations %}
223
+ <{{ msg.role }}>: {{ msg.content }}
224
+ {% endfor %}
225
+
226
+ ====
227
+
228
+ INSTRUCTIONS
229
+
230
+ - Use ONLY the information from the provided documents and extension docs.
231
+ - If the documents do not contain enough information to answer, reply: "抱歉,文档中没有足够的信息来回答这个问题。"
232
+ - Do NOT invent, guess, or add information beyond what is provided.
233
+
234
+ - For Markdown images like ![image](/path/to/image.png):
235
+ - Analyze surrounding text to determine relevance.
236
+ - Include relevant images naturally in your answer, preserving image paths.
237
+ - Convert Windows paths to Linux style (e.g., C:\\path\\to\\img.png -> C:/path/to/img.png)
238
+ {% if local_image_host %}
239
+ - Prefix image URLs with http://{{ local_image_host }}/static/
240
+ {% endif %}
241
+
242
+ - Format your answer with Markdown for readability.
243
+ - Always use the language used by the user in their question.
244
+
245
+ {% if extra_docs %}
246
+ ====
247
+
248
+ RULES PROVIDED BY USER
249
+
250
+ The following rules are provided by the user, and you must follow them strictly.
251
+
252
+ {% for key, value in extra_docs.items() %}
253
+ ### {{ key }}
254
+ {{ value }}
255
+ {% endfor %}
256
+ {% endif %}
257
+
258
+ """
259
+ import os
260
+ extra_docs = {}
261
+ rules_dir = os.path.join(getattr(self, 'args', None).source_dir if getattr(self, 'args', None) else ".", ".autocoderrules")
262
+ if os.path.isdir(rules_dir):
263
+ for fname in os.listdir(rules_dir):
264
+ if fname.endswith(".md"):
265
+ fpath = os.path.join(rules_dir, fname)
266
+ try:
267
+ with open(fpath, "r", encoding="utf-8") as f:
268
+ content = f.read()
269
+ key = os.path.splitext(fname)[0]
270
+ extra_docs[key] = content
271
+ except Exception:
272
+ continue
273
+ return {"extra_docs": extra_docs}
274
+
275
+ def get_qa_strategy(args: AutoCoderArgs) -> QAConversationStrategy:
125
276
  """
126
- Factory method to get the appropriate conversation strategy
127
-
277
+ Factory method to get the appropriate conversation strategy based on AutoCoderArgs
278
+
128
279
  Args:
129
- strategy_name: Name of the strategy to use
130
-
280
+ args: AutoCoderArgs instance containing configuration, including strategy name in `rag_qa_conversation_strategy`
281
+
131
282
  Returns:
132
283
  An instance of the requested strategy
133
-
284
+
134
285
  Raises:
135
286
  ValueError: If the requested strategy doesn't exist
136
287
  """
288
+ strategy_name = getattr(args, 'rag_qa_conversation_strategy', None) or "multi_round"
289
+
137
290
  strategies = {
138
291
  "multi_round": MultiRoundStrategy,
139
292
  "single_round": SingleRoundStrategy,
140
293
  }
141
-
294
+
142
295
  if strategy_name not in strategies:
143
296
  raise ValueError(f"Unknown strategy: {strategy_name}. Available strategies: {list(strategies.keys())}")
144
-
297
+
145
298
  return strategies[strategy_name]()
autocoder/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.345"
1
+ __version__ = "0.1.347"