Update shortGPT/gpt/gpt_utils.py
Browse files
shortGPT/gpt/gpt_utils.py
CHANGED
@@ -8,15 +8,15 @@ import tiktoken
|
|
8 |
import yaml
|
9 |
|
10 |
from shortGPT.config.api_db import ApiKeyManager
|
|
|
11 |
|
12 |
-
|
13 |
-
def num_tokens_from_messages(texts, model="cosmosrp"):
|
14 |
"""Returns the number of tokens used by a list of messages."""
|
15 |
try:
|
16 |
encoding = tiktoken.encoding_for_model(model)
|
17 |
except KeyError:
|
18 |
encoding = tiktoken.get_encoding("cl100k_base")
|
19 |
-
if model
|
20 |
if isinstance(texts, str):
|
21 |
texts = [texts]
|
22 |
score = 0
|
@@ -82,12 +82,12 @@ def gpt3Turbo_completion(chat_prompt="", system="You are an AI that can give the
|
|
82 |
{"role": "system", "content": system},
|
83 |
{"role": "user", "content": chat_prompt}
|
84 |
]
|
85 |
-
response = openai.
|
86 |
model=model,
|
87 |
messages=messages,
|
88 |
max_tokens=max_tokens,
|
89 |
temperature=temp)
|
90 |
-
text = response
|
91 |
if remove_nl:
|
92 |
text = re.sub('\s+', ' ', text)
|
93 |
filename = '%s_gpt3.txt' % time()
|
@@ -101,4 +101,4 @@ def gpt3Turbo_completion(chat_prompt="", system="You are an AI that can give the
|
|
101 |
if retry >= max_retry:
|
102 |
raise Exception("GPT3 error: %s" % oops)
|
103 |
print('Error communicating with OpenAI:', oops)
|
104 |
-
sleep(1)
|
|
|
8 |
import yaml
|
9 |
|
10 |
from shortGPT.config.api_db import ApiKeyManager
|
11 |
+
openai.base_url="https://api.pawan.krd/cosmosrp/v1"
|
12 |
|
13 |
+
def num_tokens_from_messages(texts, model="gpt-3.5-turbo-0301"):
|
|
|
14 |
"""Returns the number of tokens used by a list of messages."""
|
15 |
try:
|
16 |
encoding = tiktoken.encoding_for_model(model)
|
17 |
except KeyError:
|
18 |
encoding = tiktoken.get_encoding("cl100k_base")
|
19 |
+
if model != "gpt-3.5-turbo-0301": # note: future models may deviate from this
|
20 |
if isinstance(texts, str):
|
21 |
texts = [texts]
|
22 |
score = 0
|
|
|
82 |
{"role": "system", "content": system},
|
83 |
{"role": "user", "content": chat_prompt}
|
84 |
]
|
85 |
+
response = openai.chat.completions.create(
|
86 |
model=model,
|
87 |
messages=messages,
|
88 |
max_tokens=max_tokens,
|
89 |
temperature=temp)
|
90 |
+
text = response.choices[0].message.content.strip()
|
91 |
if remove_nl:
|
92 |
text = re.sub('\s+', ' ', text)
|
93 |
filename = '%s_gpt3.txt' % time()
|
|
|
101 |
if retry >= max_retry:
|
102 |
raise Exception("GPT3 error: %s" % oops)
|
103 |
print('Error communicating with OpenAI:', oops)
|
104 |
+
sleep(1)
|