Skip to content

Commit e1d62ac

Browse files
fix: Fix proxy usage (box/box-codegen#662) (#476)
1 parent d7954ad commit e1d62ac

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "2c730de", "specHash": "59747aa", "version": "1.11.0" }
1+
{ "engineHash": "59337f7", "specHash": "59747aa", "version": "1.11.0" }

box_sdk_gen/networking/network.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import requests
21
from typing import Dict
32

43
from .network_client import NetworkClient
@@ -26,16 +25,21 @@ def __init__(
2625
retry_strategy = BoxRetryStrategy()
2726
if network_client is None:
2827
network_client = BoxNetworkClient()
29-
self.requests_session = requests.Session()
28+
if (
29+
proxy_url
30+
and hasattr(network_client, 'requests_session')
31+
and network_client.requests_session
32+
):
33+
network_client.requests_session.proxies = {
34+
'http': proxy_url,
35+
'https': proxy_url,
36+
}
3037
self.additional_headers = additional_headers
3138
self.base_urls = base_urls
3239
self.proxy_url = proxy_url
3340
self.network_client = network_client
3441
self.retry_strategy = retry_strategy
3542

36-
proxies = {'http': proxy_url, 'https': proxy_url} if proxy_url else {}
37-
self.requests_session.proxies = proxies
38-
3943
def with_additional_headers(
4044
self, additional_headers: Dict[str, str] = None
4145
) -> 'NetworkSession':
@@ -80,11 +84,11 @@ def with_proxy(self, config: ProxyConfig) -> 'NetworkSession':
8084

8185
proxy_host = config.url.split("//")[1]
8286
proxy_auth = (
83-
f'{config.username}:{config.password}@'
87+
f"{config.username}:{config.password}@"
8488
if config.username and config.password
85-
else ''
89+
else ""
8690
)
87-
proxy_url = f'http://{proxy_auth}{proxy_host}'
91+
proxy_url = f"http://{proxy_auth}{proxy_host}"
8892
return NetworkSession(
8993
network_client=self.network_client,
9094
additional_headers=self.additional_headers,
@@ -112,7 +116,7 @@ def with_retry_strategy(self, retry_strategy: RetryStrategy) -> 'NetworkSession'
112116
"""
113117
Generate a fresh network session by duplicating the existing configuration and network parameters,
114118
while also including a new retry options to be used for each API call.
115-
:param retry_options: RetryOptions object, which contains the retry logic
119+
:param retry_strategy: RetryStrategy object, which contains the retry logic
116120
:return: a new instance of NetworkSession
117121
"""
118122
return NetworkSession(

docs/ai.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ See the endpoint docs at
167167
client.ai.create_ai_extract(
168168
"firstName, lastName, location, yearOfBirth, company",
169169
[AiItemBase(id=file.id)],
170-
ai_agent=ai_extract_agent_config,
170+
ai_agent=agent_ignoring_overriding_embeddings_model,
171171
)
172172
```
173173

test/ai.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484

8585
from box_sdk_gen.schemas.ai_agent_extract_structured import AiAgentExtractStructured
8686

87+
from box_sdk_gen.schemas.ai_agent_long_text_tool import AiAgentLongTextTool
88+
8789
client: BoxClient = get_default_client()
8890

8991

@@ -216,6 +218,17 @@ def testAIExtract():
216218
ai_extract_agent_config: AiAgentExtract = client.ai.get_ai_agent_default_config(
217219
GetAiAgentDefaultConfigMode.EXTRACT, language='en-US'
218220
)
221+
long_text_config_with_no_embeddings: AiAgentLongTextTool = AiAgentLongTextTool(
222+
system_message=ai_extract_agent_config.long_text.system_message,
223+
prompt_template=ai_extract_agent_config.long_text.prompt_template,
224+
model=ai_extract_agent_config.long_text.model,
225+
num_tokens_for_completion=ai_extract_agent_config.long_text.num_tokens_for_completion,
226+
llm_endpoint_params=ai_extract_agent_config.long_text.llm_endpoint_params,
227+
)
228+
agent_ignoring_overriding_embeddings_model: AiAgentExtract = AiAgentExtract(
229+
basic_text=ai_extract_agent_config.basic_text,
230+
long_text=long_text_config_with_no_embeddings,
231+
)
219232
uploaded_files: Files = client.uploads.upload_file(
220233
UploadFileAttributes(
221234
name=''.join([get_uuid(), '.txt']),
@@ -230,7 +243,7 @@ def testAIExtract():
230243
response: AiResponse = client.ai.create_ai_extract(
231244
'firstName, lastName, location, yearOfBirth, company',
232245
[AiItemBase(id=file.id)],
233-
ai_agent=ai_extract_agent_config,
246+
ai_agent=agent_ignoring_overriding_embeddings_model,
234247
)
235248
expected_response: str = (
236249
'{"firstName": "John", "lastName": "Doe", "location": "San Francisco", "yearOfBirth": "1990", "company": "Box"}'
@@ -246,14 +259,12 @@ def testAIExtractStructuredWithFields():
246259
GetAiAgentDefaultConfigMode.EXTRACT_STRUCTURED, language='en-US'
247260
)
248261
)
249-
long_text_config_with_no_embeddings: AiAgentExtractStructured = (
250-
AiAgentExtractStructured(
251-
system_message=ai_extract_structured_agent_config.long_text.system_message,
252-
prompt_template=ai_extract_structured_agent_config.long_text.prompt_template,
253-
model=ai_extract_structured_agent_config.long_text.model,
254-
num_tokens_for_completion=ai_extract_structured_agent_config.long_text.num_tokens_for_completion,
255-
llm_endpoint_params=ai_extract_structured_agent_config.long_text.llm_endpoint_params,
256-
)
262+
long_text_config_with_no_embeddings: AiAgentLongTextTool = AiAgentLongTextTool(
263+
system_message=ai_extract_structured_agent_config.long_text.system_message,
264+
prompt_template=ai_extract_structured_agent_config.long_text.prompt_template,
265+
model=ai_extract_structured_agent_config.long_text.model,
266+
num_tokens_for_completion=ai_extract_structured_agent_config.long_text.num_tokens_for_completion,
267+
llm_endpoint_params=ai_extract_structured_agent_config.long_text.llm_endpoint_params,
257268
)
258269
agent_ignoring_overriding_embeddings_model: AiAgentExtractStructured = (
259270
AiAgentExtractStructured(

test/box_network_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ def test_proxy_config():
955955
ProxyConfig(url="http://127.0.0.1:3128/", username="user", password="pass")
956956
)
957957
assert client.network_session.proxy_url == "http://user:[email protected]:3128/"
958-
requests_session = client.network_session.requests_session
958+
requests_session = client.network_session.network_client.requests_session
959959
assert requests_session.proxies["http"] == "http://user:[email protected]:3128/"
960960
assert requests_session.proxies["https"] == "http://user:[email protected]:3128/"
961961

0 commit comments

Comments
 (0)