markqiu commited on
Commit
886091f
·
1 Parent(s): 636fc2d

尝试用百度的库实现ernie.py

Browse files
Files changed (2) hide show
  1. modules/models/ERNIE.py +11 -5
  2. requirements.txt +1 -0
modules/models/ERNIE.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  from ..presets import *
2
  from ..utils import *
3
 
@@ -5,12 +7,16 @@ from .base_model import BaseLLMModel
5
 
6
 
7
  class ERNIE_Client(BaseLLMModel):
8
- def __init__(self, model_name, api_key, secret_key) -> None:
9
  super().__init__(model_name=model_name)
10
- self.api_key = api_key
11
- self.api_secret = secret_key
12
- if None in [self.api_secret, self.api_key]:
13
- raise Exception("请在配置文件或者环境变量中设置文心一言的API Key 和 Secret Key")
 
 
 
 
14
 
15
  if self.model_name == "ERNIE-Bot-turbo":
16
  self.ERNIE_url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token="
 
1
+ import erniebot as eb
2
+
3
  from ..presets import *
4
  from ..utils import *
5
 
 
7
 
8
 
9
  class ERNIE_Client(BaseLLMModel):
10
+ def __init__(self, model_name, api_key, secret_key, api_type: str = "aistudio", access_token: str = None) -> None:
11
  super().__init__(model_name=model_name)
12
+ self.auth_config = {
13
+ "api_type": api_type,
14
+ }
15
+ self.auth_config["ak"] = api_key
16
+ self.auth_config["sk"] = secret_key
17
+ if access_token:
18
+ self.auth_config["access_token"] = access_token
19
+ self.eb = eb.ChatCompletion
20
 
21
  if self.model_name == "ERNIE-Bot-turbo":
22
  self.ERNIE_url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token="
requirements.txt CHANGED
@@ -33,3 +33,4 @@ pydantic==2.5.2
33
  google-search-results
34
  anthropic==0.3.11
35
  Pillow>=10.1.0
 
 
33
  google-search-results
34
  anthropic==0.3.11
35
  Pillow>=10.1.0
36
+ erniebot