XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Add custom instrutions to cli client

1a7a1338
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +12 -2
Modified g4f/cli/client.py +12 -2
@@ -92,12 +92,17 @@ async def stream_response(
92 92 client: AsyncClient,
93 93 input_text: str,
94 94 conversation: ConversationManager,
95 output_file: Optional[Path] = None
95 output_file: Optional[Path] = None,
96 instructions: Optional[str] = None
96 97 ) -> None:
97 98 """Stream the response from the API and update conversation."""
98 99 input_text = input_text.strip()
99 100 if not input_text:
100 101 raise ValueError("Input text cannot be empty")
102
103 if instructions:
104 # Add system instructions to conversation if provided
105 conversation.add_message("system", instructions)
101 106
102 107 # Add user message to conversation
103 108 conversation.add_message("user", input_text)
@@ -188,6 +193,11 @@ def get_parser():
188 193 nargs='?',
189 194 help="Output file to save the response file."
190 195 )
196 parser.add_argument(
197 '-i', '--instructions',
198 default=None,
199 help="Add custom system instructions."
200 )
191 201 parser.add_argument(
192 202 '-c', '--cookies-dir',
193 203 type=Path,
@@ -237,7 +247,7 @@ async def run_args(input_text: str, args):
237 247 client = AsyncClient(provider=conversation.provider)
238 248
239 249 # Stream response and update conversation
240 await stream_response(client, input_text, conversation, args.output)
250 await stream_response(client, input_text, conversation, args.output, args.instructions)
241 251
242 252 # Save conversation state
243 253 conversation.save()