nanoPyCodeAgent 0.2.0__py3-none-any.whl → 0.3.0__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.
- nanopycodeagent/agent.py +13 -6
- {nanopycodeagent-0.2.0.dist-info → nanopycodeagent-0.3.0.dist-info}/METADATA +1 -1
- nanopycodeagent-0.3.0.dist-info/RECORD +7 -0
- nanopycodeagent-0.2.0.dist-info/RECORD +0 -7
- {nanopycodeagent-0.2.0.dist-info → nanopycodeagent-0.3.0.dist-info}/WHEEL +0 -0
- {nanopycodeagent-0.2.0.dist-info → nanopycodeagent-0.3.0.dist-info}/entry_points.txt +0 -0
- {nanopycodeagent-0.2.0.dist-info → nanopycodeagent-0.3.0.dist-info}/licenses/LICENSE +0 -0
nanopycodeagent/agent.py
CHANGED
|
@@ -9,6 +9,7 @@ import os
|
|
|
9
9
|
from pathlib import Path
|
|
10
10
|
|
|
11
11
|
import anthropic
|
|
12
|
+
import httpx
|
|
12
13
|
from anthropic.types import MessageParam
|
|
13
14
|
|
|
14
15
|
# The model used when ANTHROPIC_MODEL is set in neither the environment nor the
|
|
@@ -144,17 +145,20 @@ def run() -> None:
|
|
|
144
145
|
|
|
145
146
|
try:
|
|
146
147
|
print("\nAgent> ", end="", flush=True)
|
|
147
|
-
|
|
148
|
+
# Stream the reply so text shows up as it is generated, then grab
|
|
149
|
+
# the accumulated message for the conversation history.
|
|
150
|
+
with client.messages.stream(
|
|
148
151
|
model=model,
|
|
149
152
|
max_tokens=MAX_TOKENS,
|
|
150
153
|
system=SYSTEM_PROMPT,
|
|
151
154
|
messages=messages,
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
+
) as stream:
|
|
156
|
+
for text in stream.text_stream:
|
|
157
|
+
print(text, end="", flush=True)
|
|
158
|
+
message = stream.get_final_message()
|
|
155
159
|
print()
|
|
156
160
|
except KeyboardInterrupt:
|
|
157
|
-
# Ctrl-C while
|
|
161
|
+
# Ctrl-C while streaming the reply cancels cleanly, mirroring the
|
|
158
162
|
# graceful quit offered at the input prompt.
|
|
159
163
|
print()
|
|
160
164
|
break
|
|
@@ -163,7 +167,10 @@ def run() -> None:
|
|
|
163
167
|
"\nAuthentication failed. Check that ANTHROPIC_API_KEY is set correctly."
|
|
164
168
|
)
|
|
165
169
|
break
|
|
166
|
-
except anthropic.APIError as exc:
|
|
170
|
+
except (anthropic.APIError, httpx.HTTPError) as exc:
|
|
171
|
+
# httpx.HTTPError: the SDK wraps transport errors only around the
|
|
172
|
+
# initial send, so a network failure mid-stream surfaces as a raw
|
|
173
|
+
# httpx error during iteration rather than an anthropic.APIError.
|
|
167
174
|
print(f"\nRequest failed: {exc}")
|
|
168
175
|
messages.pop() # drop the unanswered user turn so history stays valid
|
|
169
176
|
continue
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nanoPyCodeAgent
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: A nano code agent built from scratch in pure Python.
|
|
5
5
|
Project-URL: Homepage, https://github.com/minixalpha/nanoPyCodeAgent
|
|
6
6
|
Project-URL: Repository, https://github.com/minixalpha/nanoPyCodeAgent
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
nanopycodeagent/__init__.py,sha256=pYFCw7WNkZsGXbqNLkXituX4iBy86RJ4LKKAr78XwM8,70
|
|
2
|
+
nanopycodeagent/agent.py,sha256=ceIw3HuZD3UHPtyxS3eGbfOE6FrKABcGybFIyOMrcmU,7074
|
|
3
|
+
nanopycodeagent-0.3.0.dist-info/METADATA,sha256=BJqRCUQaABx8q8-MKeMKKkBqUgx-CS6KGvvguADFcPY,3028
|
|
4
|
+
nanopycodeagent-0.3.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
5
|
+
nanopycodeagent-0.3.0.dist-info/entry_points.txt,sha256=4gU7YNzQaf2RKlOdfebOWYNYIUk2LDoyhu3G4Vgole8,57
|
|
6
|
+
nanopycodeagent-0.3.0.dist-info/licenses/LICENSE,sha256=g24TppoiLdeF_1_-Y7H2H_eOavKseWA5utuK83Vq1sA,1067
|
|
7
|
+
nanopycodeagent-0.3.0.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
nanopycodeagent/__init__.py,sha256=pYFCw7WNkZsGXbqNLkXituX4iBy86RJ4LKKAr78XwM8,70
|
|
2
|
-
nanopycodeagent/agent.py,sha256=aAY60px0CuXllg3qICFFOz9_iJKIjf2OWWjmo6PDfzk,6628
|
|
3
|
-
nanopycodeagent-0.2.0.dist-info/METADATA,sha256=etl0E9_jsVOXrRHhTD7lcODGNzSY1VjJ5t-LKxP5adE,3028
|
|
4
|
-
nanopycodeagent-0.2.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
5
|
-
nanopycodeagent-0.2.0.dist-info/entry_points.txt,sha256=4gU7YNzQaf2RKlOdfebOWYNYIUk2LDoyhu3G4Vgole8,57
|
|
6
|
-
nanopycodeagent-0.2.0.dist-info/licenses/LICENSE,sha256=g24TppoiLdeF_1_-Y7H2H_eOavKseWA5utuK83Vq1sA,1067
|
|
7
|
-
nanopycodeagent-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|