Skip to content

Commit

Permalink
Merge pull request #95 from BaranEkin/main
Browse files Browse the repository at this point in the history
Update openai chat completions api
  • Loading branch information
jeremyxu1998 authored May 8, 2024
2 parents e0e4803 + e11894b commit 030265c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions challenge/gpt_eval.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import openai
import pickle
import pdb
import numpy as np
import torch
import json
import argparse
from multiprocessing import Pool
from openai import OpenAI


class GPTEvaluation:
def __init__(self):
openai.api_key = "you need to use your own openai key for evaluation on your local machine"
self.client = OpenAI(api_key="you need to use your own openai key for evaluation on your local machine")

def call_chatgpt(self, chatgpt_messages, max_tokens=40, model="gpt-3.5-turbo"):
response = openai.ChatCompletion.create(
response = self.client.chat.completions.create(
model=model, messages=chatgpt_messages, temperature=0.6, max_tokens=max_tokens
)
reply = response["choices"][0]["message"]["content"]
total_tokens = response["usage"]["total_tokens"]
reply = response.choices[0].message.content
total_tokens = response.usage.total_tokens
return reply, total_tokens

def prepare_chatgpt_message(self, prompt):
Expand Down Expand Up @@ -55,4 +55,4 @@ def forward(self, data):
with Pool(5) as p: # Change the number based on your CPU cores
scores = p.map(eval.forward, data)

print(scores)
print(scores)

0 comments on commit 030265c

Please sign in to comment.