Skip to content

Commit

Permalink
feat: update openai for gpt-4 (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
dilyararimovna authored May 15, 2023
1 parent 77029f9 commit 27d9174
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion services/openai_api_lm/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ sentry-sdk[flask]==0.14.1
healthcheck==1.3.3
jinja2<=3.0.3
Werkzeug<=2.0.3
openai==0.27.0
openai==0.27.6
7 changes: 4 additions & 3 deletions services/openai_api_lm/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"gpt-4": json.load(open("generative_configs/openai-chatgpt.json", "r")),
"gpt-4-32k": json.load(open("generative_configs/openai-chatgpt.json", "r")),
}
CHAT_COMPLETION_MODELS = ["gpt-3.5-turbo", "gpt-4", "gpt-4-32k"]


def generate_responses(context, openai_api_key, openai_org, prompt, generation_params, continue_last_uttr=False):
Expand All @@ -38,8 +39,8 @@ def generate_responses(context, openai_api_key, openai_org, prompt, generation_p
openai.api_key = openai_api_key
openai.organization = openai_org if openai_org else None

if PRETRAINED_MODEL_NAME_OR_PATH == "gpt-3.5-turbo":
logger.info("model=gpt-3.5-turbo, use special chat completion endpoint")
if PRETRAINED_MODEL_NAME_OR_PATH in CHAT_COMPLETION_MODELS:
logger.info("Use special chat completion endpoint")
s = len(context) % 2
messages = [
{"role": "system", "content": prompt},
Expand Down Expand Up @@ -78,7 +79,7 @@ def generate_responses(context, openai_api_key, openai_org, prompt, generation_p
elif isinstance(response, str):
outputs = [response.strip()]

if PRETRAINED_MODEL_NAME_OR_PATH != "gpt-3.5-turbo":
if PRETRAINED_MODEL_NAME_OR_PATH not in CHAT_COMPLETION_MODELS:
# post-processing of the responses by all models except of ChatGPT
outputs = [GENERATIVE_ROBOT_TEMPLATE.sub("\n", resp).strip() for resp in outputs]
return outputs
Expand Down

0 comments on commit 27d9174

Please sign in to comment.