MCPcopy Create free account
hub / github.com/T-duality/PillOCR-python / set_proxy

Method set_proxy

GPTOCRGUI.py:61–104  ·  view source on GitHub ↗

根据服务商设置代理和client

(self, proxy)

Source from the content-addressed store, hash-verified

59 os.environ['OPENAI_API_KEY'] = api_key
60
61 def set_proxy(self, proxy):
62 """根据服务商设置代理和client"""
63 try:
64 if self.current_provider == 'OPENAI':
65 if proxy:
66 self.client = OpenAI(
67 http_client=httpx.Client(
68 transport=httpx.HTTPTransport(proxy=proxy)
69 )
70 )
71 else:
72 self.client = OpenAI()
73 elif self.current_provider == '火山引擎':
74 if proxy:
75 self.client = OpenAI(
76 base_url="https://ark.cn-beijing.volces.com/api/v3",
77 http_client=httpx.Client(
78 transport=httpx.HTTPTransport(proxy=proxy)
79 )
80 )
81 else:
82 self.client = OpenAI(
83 base_url="https://ark.cn-beijing.volces.com/api/v3"
84 )
85 elif self.current_provider == '自定义':
86 # 从app获取用户设置的URL
87 custom_url = self.app.url_var.get().strip()
88 if not custom_url:
89 self.log_callback("自定义URL不能为空")
90
91 if proxy:
92 self.client = OpenAI(
93 base_url=custom_url,
94 http_client=httpx.Client(
95 transport=httpx.HTTPTransport(proxy=proxy)
96 )
97 )
98 else:
99 self.client = OpenAI(
100 base_url=custom_url
101 )
102 except Exception as e:
103 if self.log_callback:
104 self.log_callback(f"设置客户端时出错: {str(e)}")
105
106 def set_gpt_model(self, model_name):
107 if not model_name:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected