Skip to content

Commit

Permalink
fix some ssl issues
Browse files Browse the repository at this point in the history
Signed-off-by: pengzhile <[email protected]>
  • Loading branch information
pengzhile committed Mar 1, 2023
1 parent e2f7098 commit e9bdce9
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 34 deletions.
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
<summary>

![alt Screenshot5](https://github.com/pengzhile/pandora/raw/master/doc/images/s05.png)
![alt Screenshot10](https://github.com/pengzhile/pandora/raw/master/doc/images/s10.jpeg)

</summary>

![alt Screenshot1](https://github.com/pengzhile/pandora/raw/master/doc/images/s01.png)
![alt Screenshot2](https://github.com/pengzhile/pandora/raw/master/doc/images/s02.png)
![alt Screenshot3](https://github.com/pengzhile/pandora/raw/master/doc/images/s03.png)
![alt Screenshot4](https://github.com/pengzhile/pandora/raw/master/doc/images/s04.png)
![alt Screenshot11](https://github.com/pengzhile/pandora/raw/master/doc/images/s11.jpeg)
![alt Screenshot6](https://github.com/pengzhile/pandora/raw/master/doc/images/s06.png)

</details>
Expand Down Expand Up @@ -97,7 +99,7 @@
## HTTP服务文档

* 如果你以`http`服务方式启动,现在你可以打开一个极简版的`ChatGPT`了。通过你指定的`http://ip:port`来访问。
* API文档见 [doc/HTTP-API.md](https://github.com/pengzhile/pandora/blob/master/doc/HTTP-API.md)
* API文档见[doc/HTTP-API.md](https://github.com/pengzhile/pandora/blob/master/doc/HTTP-API.md)

## 操作命令

Expand All @@ -115,13 +117,6 @@
* `/version` 打印`Pandora`的版本信息。
* `/exit` 退出`潘多拉`

## macOS的神奇问题

* 如果你界面报错:`certificate verify failed: unable to get local issuer certificate`
* 第一步:同时按键盘`Command`+`Space`,或手动打开`Spotlight`
* 第二步:输入`Install Certificates.command`执行它。
* 问题解决。

## 其他说明

* 项目是站在其他巨人的肩膀上,感谢!
Expand Down
11 changes: 3 additions & 8 deletions doc/README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
<summary>

![alt Screenshot5](https://github.com/pengzhile/pandora/raw/master/doc/images/s05.png)
![alt Screenshot10](https://github.com/pengzhile/pandora/raw/master/doc/images/s10.jpeg)

</summary>

![alt Screenshot1](https://github.com/pengzhile/pandora/raw/master/doc/images/s01.png)
![alt Screenshot2](https://github.com/pengzhile/pandora/raw/master/doc/images/s02.png)
![alt Screenshot3](https://github.com/pengzhile/pandora/raw/master/doc/images/s03.png)
![alt Screenshot4](https://github.com/pengzhile/pandora/raw/master/doc/images/s04.png)
![alt Screenshot11](https://github.com/pengzhile/pandora/raw/master/doc/images/s11.jpeg)
![alt Screenshot6](https://github.com/pengzhile/pandora/raw/master/doc/images/s06.png)

</details>
Expand Down Expand Up @@ -96,7 +98,7 @@
## HTTP Server Doc

* If you start the `http` server, you can access a minimalist version of ChatGPT by visiting the URL you specified with `http://ip:port`.
* Visit API doc [doc/HTTP-API.md](https://github.com/pengzhile/pandora/blob/master/doc/HTTP-API.md)
* Visit API doc: [doc/HTTP-API.md](https://github.com/pengzhile/pandora/blob/master/doc/HTTP-API.md)

## Command Operations

Expand All @@ -114,13 +116,6 @@
* `/version` print the version of `Pandora`.
* `/exit` exits `Pandora`.

## macOS specific issues

* If you get an error: `certificate verify failed: unable to get local issuer certificate`
* First: Press `Command`+`Space` buttons or open `Spotlight`.
* Second:type `Install Certificates.command` and execute it.
* Problem solved.

## Other Information

* `Pandora` is an open-source project that stands on the shoulders of other giants, thank you!
Expand Down
Binary file added doc/images/s10.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/s11.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
certifi
aiohttp==3.8.4
pyreadline==2.1
requests[socks]==2.28.2
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package_dir={'pandora': 'src/pandora'},
include_package_data=True,
install_requires=[
'certifi',
'aiohttp == 3.8.4',
'pyreadline == 2.1; platform_system == "Windows"',
'requests[socks] == 2.28.2',
Expand Down
2 changes: 1 addition & 1 deletion src/pandora/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

__version__ = '0.4.1'
__version__ = '0.4.2'
32 changes: 16 additions & 16 deletions src/pandora/openai/api.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# -*- coding: utf-8 -*-

import json
from ssl import create_default_context

import aiohttp
import requests as requests
import requests
from certifi import where


class ChatGPT:
def __init__(self, access_token, proxy=None):
self.access_token = access_token
self.session = requests.Session()
self.session.trust_env = False
self.session.verify = where()
self.proxy = proxy
self.session.proxies = self.proxies = {
self.session.proxies = {
'http': self.proxy,
'https': self.proxy,
} if self.proxy else None
self.ssl_context = create_default_context(cafile=self.session.verify)

self.user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) ' \
'Chrome/109.0.0.0 Safari/537.36'
Expand All @@ -28,8 +33,7 @@ def __init__(self, access_token, proxy=None):

def list_models(self, raw=False):
url = 'https://apps.openai.com/api/models'
resp = self.session.get(url=url, headers=self.basic_headers, allow_redirects=False,
timeout=100, proxies=self.proxies)
resp = self.session.get(url=url, headers=self.basic_headers, allow_redirects=False, timeout=100)

if raw:
return resp
Expand All @@ -45,8 +49,7 @@ def list_models(self, raw=False):

def list_conversations(self, offset, limit, raw=False):
url = 'https://apps.openai.com/api/conversations?offset={}&limit={}'.format(offset, limit)
resp = self.session.get(url=url, headers=self.basic_headers, allow_redirects=False,
timeout=100, proxies=self.proxies)
resp = self.session.get(url=url, headers=self.basic_headers, allow_redirects=False, timeout=100)

if raw:
return resp
Expand All @@ -58,8 +61,7 @@ def list_conversations(self, offset, limit, raw=False):

def get_conversation(self, conversation_id, raw=False):
url = 'https://apps.openai.com/api/conversation/' + conversation_id
resp = self.session.get(url=url, headers=self.basic_headers, allow_redirects=False,
timeout=100, proxies=self.proxies)
resp = self.session.get(url=url, headers=self.basic_headers, allow_redirects=False, timeout=100)

if raw:
return resp
Expand All @@ -75,8 +77,7 @@ def clear_conversations(self, raw=False):
}

url = 'https://apps.openai.com/api/conversations'
resp = self.session.patch(url=url, headers=self.basic_headers, json=data, allow_redirects=False,
timeout=100, proxies=self.proxies)
resp = self.session.patch(url=url, headers=self.basic_headers, json=data, allow_redirects=False, timeout=100)

if raw:
return resp
Expand All @@ -103,8 +104,7 @@ def gen_conversation_title(self, conversation_id, model, message_id, raw=False):
'model': model,
'message_id': message_id,
}
resp = self.session.post(url=url, headers=self.basic_headers, json=data, allow_redirects=False,
timeout=100, proxies=self.proxies)
resp = self.session.post(url=url, headers=self.basic_headers, json=data, allow_redirects=False, timeout=100)

if raw:
return resp
Expand Down Expand Up @@ -179,8 +179,9 @@ async def __request_conversation_content(self, data, raw=False):
headers = {**self.session.headers, **self.basic_headers,
'Accept': 'text/event-stream', 'Content-Type': 'application/json'}

async with aiohttp.ClientSession() as session:
async with session.post(url, json=data, headers=headers, timeout=600, proxy=self.proxy) as resp:
async with aiohttp.ClientSession(trust_env=False) as session:
async with session.post(url, json=data, headers=headers, timeout=600, proxy=self.proxy,
ssl=self.ssl_context) as resp:
if resp.status != 200:
raise Exception('request conversation failed: ' + str(resp.status))

Expand All @@ -198,8 +199,7 @@ async def __request_conversation_content(self, data, raw=False):

def __update_conversation(self, conversation_id, data, raw=False):
url = 'https://apps.openai.com/api/conversation/' + conversation_id
resp = self.session.patch(url=url, headers=self.basic_headers, json=data, allow_redirects=False,
timeout=100, proxies=self.proxies)
resp = self.session.patch(url=url, headers=self.basic_headers, json=data, allow_redirects=False, timeout=100)

if raw:
return resp
Expand Down
5 changes: 4 additions & 1 deletion src/pandora/openai/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from datetime import datetime as dt
from urllib.parse import urlparse, parse_qs

import requests as requests
import requests
from certifi import where


class Auth0:
Expand All @@ -16,6 +17,8 @@ def __init__(self, email: str, password: str, proxy: str = None, use_cache: bool
self.proxy = proxy
self.use_cache = use_cache
self.session = requests.Session()
self.session.trust_env = False
self.session.verify = where()
self.access_token = None
self.expires = None
self.user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) ' \
Expand Down

0 comments on commit e9bdce9

Please sign in to comment.