Skip to content

Commit

Permalink
add model property to Chat
Browse files Browse the repository at this point in the history
  • Loading branch information
RexWzh committed Aug 31, 2023
1 parent 4e3c778 commit 192828e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion openai_api_call/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = """Rex Wang"""
__email__ = '[email protected]'
__version__ = '1.0.1'
__version__ = '1.1.0'

import os, requests
from .chattool import Chat, Resp
Expand Down
14 changes: 13 additions & 1 deletion openai_api_call/chattool.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__( self
raise ValueError("msg should be a list of dict, a string or None")
self._api_key = openai_api_call.api_key if api_key is None else api_key
self._chat_url = chat_url
self._model = 'gpt-3.5-turbo'

def prompt_token(self, model:str="gpt-3.5-turbo-0613"):
"""Get the prompt token for the model
Expand All @@ -47,6 +48,15 @@ def prompt_token(self, model:str="gpt-3.5-turbo-0613"):
"""
return num_tokens_from_messages(self.chat_log, model=model)

@property
def model(self):
return self._model

@model.setter
def model(self, model:str):
# assert model.startswith('gpt-'), f'unsupported model {model}'
self._model = model

@property
def api_key(self):
"""Get API key"""
Expand Down Expand Up @@ -77,7 +87,7 @@ def getresponse( self
, timeout:int = 0
, timeinterval:int = 0
, api_key:Union[str, None]=None
, model:str = "gpt-3.5-turbo"
, model:str = None
, update:bool = True
, **options)->Resp:
"""Get the API response
Expand All @@ -96,6 +106,8 @@ def getresponse( self
if api_key is None:
api_key = self.api_key
assert api_key is not None, "API key is not set!"
if model is None:
model = self.model

# initialize prompt message
msg = self.chat_log
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
with open('README.md') as readme_file:
readme = readme_file.read()

VERSION = '1.0.1'
VERSION = '1.1.0'

requirements = [
'Click>=7.0', 'requests>=2.20',
Expand Down

0 comments on commit 192828e

Please sign in to comment.