Skip to content

Commit

Permalink
Update API calls and print exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-cse committed Mar 13, 2024
1 parent 4a69771 commit b9f26a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 16 additions & 8 deletions example_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import openai
from openai import OpenAI
import os
import pandas as pd
from tenacity import (
Expand All @@ -21,8 +21,8 @@ def chat(
delay=1 # Seconds to sleep after each request.
):
time.sleep(delay)

response = openai.ChatCompletion.create(
client = OpenAI(api_key='dummy', base_url='https://xk1a3a99x8vvam-8000.proxy.runpod.net/v1')
response = client.chat.completions.create(
model=model,
messages=messages,
temperature=temperature,
Expand All @@ -31,7 +31,7 @@ def chat(
)

if n == 1:
return response['choices'][0]['message']['content']
return response.choices[0].message.content
else:
return [i['message']['content'] for i in response['choices']]

Expand All @@ -46,8 +46,9 @@ def completion(
delay=1 # Seconds to sleep after each request.
):
time.sleep(delay)

response = openai.Completion.create(
client = OpenAI(api_key='dummy', base_url='https://xk1a3a99x8vvam-8000.proxy.runpod.net/v1')

response = client.Completion.create(
model=model,
prompt=prompt,
temperature=temperature,
Expand Down Expand Up @@ -79,8 +80,8 @@ def example_generator(questionnaire, args):
model = args.model
records_file = args.name_exp if args.name_exp is not None else model

openai.organization = args.openai_organization
openai.api_key = args.openai_key
# openai.organization = args.openai_organization
# openai.api_key = args.openai_key

# Read the existing CSV file into a pandas DataFrame
df = pd.read_csv(testing_file)
Expand Down Expand Up @@ -128,6 +129,13 @@ def example_generator(questionnaire, args):
result = chat(model, inputs)
previous_records.append({"role": "user", "content": questionnaire["prompt"] + '\n' + questions_string})
previous_records.append({"role": "assistant", "content": result})
elif model in ['mistralai/Mistral-7B-Instruct-v0.1', 'steve-cse/MelloGPT']:
inputs = previous_records + [
{"role": "user", "content": questionnaire["inner_setting"]+'\n'+questionnaire["prompt"] + '\n' + questions_string}
]
result = chat(model, inputs)
previous_records.append({"role": "user", "content": questionnaire["prompt"] + '\n' + questions_string})
previous_records.append({"role": "assistant", "content": result})
else:
raise ValueError("The model is not supported or does not exist.")

Expand Down
4 changes: 2 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,6 @@ def run_psychobench(args, generator):
if args.mode in ['analysis', 'auto']:
try:
analysis_results(questionnaire, args)
except:
print(f'Unable to analysis {args.testing_file}.')
except Exception as e:
print(f'Unable to analyze {args.testing_file}: {str(e)}')

0 comments on commit b9f26a3

Please sign in to comment.