Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
JiauZhang committed May 21, 2024
1 parent bc7ea5d commit ec67271
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
23 changes: 19 additions & 4 deletions chatchat/baidu.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from chatchat.base import Base
import httpx, time
import httpx, time, json

class Completion(Base):
def __init__(self, jfile, model='ERNIE-Speed-8K'):
Expand Down Expand Up @@ -85,8 +85,23 @@ def create(self, message):
return r.json()

class Chat(Completion):
def __init__(self, jfile, model='ERNIE-Speed-8K'):
def __init__(self, jfile, model='ERNIE-Speed-8K', history=[]):
super().__init__(jfile, model=model)
self.history = history

def chat(self, message):
self.history.append({
"role": "user",
"content": message,
})
message = {"messages": self.history}
payload = json.dumps(message)
url = f'{self.api}?access_token={self.get_access_token()}'
r = self.client.post(url, headers=self.headers, data=payload).json()
if 'result' in r:
self.history.append({
"role": "assistant",
"content": r['result']
})

def chat(self):
...
return r
18 changes: 17 additions & 1 deletion examples/baidu.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,20 @@
# 'total_tokens': 70
# }
# }
print(r)
print(r)

history = [
{
"role": "user",
"content": "简单介绍一下你自己",
},
{
"role": "assistant",
"content": "我是人工智能助手,具备智能问答、自然语言处理等多项功能,致力于为用户提供准确、便捷的解答和服务。",
}
]
chat = cc.baidu.Chat('./data.json', history=history)
r = chat.chat("说的再详细点!")
print(r)
r = chat.chat("给我举个具体的例子。")
print(r)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name = 'chatchat',
packages = find_packages(exclude=['examples']),
version = '0.0.5',
version = '0.0.6',
license = 'GPL-2.0',
description = 'Large Language Model API',
author = 'JiauZhang',
Expand Down

0 comments on commit ec67271

Please sign in to comment.