-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenAI eval #81
Draft
pseudotensor
wants to merge
1
commit into
main
Choose a base branch
from
openai_eval
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
OpenAI eval #81
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# import the OpenAI Python library for calling the OpenAI API | ||
import os | ||
import openai | ||
|
||
SYSTEM0 = """You are a helpful assistant that measures the accuracy of large language model responses to a prompt.""" | ||
|
||
INSTRUCTION = """Your task is to evaluate another assistant's response to a prompt. | ||
Evaluation criteria include: response's helpfulness, relevance, accuracy, and level of detail. | ||
An overall numeric score of 0 means the response did not answer the question, or did poorly in a criteria. | ||
An overall numeric score of 0.5 means the response somewhat answered the question, or somewhat satisfied the criteria. | ||
An overall numeric score of 1.0 means the response perfectly answered the question, and satisfied all criteria. | ||
Let AAA be the overall score you evaluated the response, | ||
BBB be the numeric score for helpfulness, | ||
CCC be the numeric score for relevance, | ||
DDD be the numeric score for accuracy, | ||
EEE be the numeric score for level of detail. | ||
Let DETAILS be an additional paragraph containing a comprehensive explanation of your evaluation. | ||
Format your response as: | ||
==== | ||
AAA, BBB, CCC, EEE | ||
==== | ||
DETAILS | ||
""" | ||
RESPONSE = "Text to Score" | ||
END_KEY = "### End" | ||
INTRO = ( | ||
"Below is an instruction that describes a task. Write a response that appropriately completes the request." | ||
) | ||
PROMPT0 = """{intro} | ||
{instruction_key} | ||
{instruction} | ||
{response_key} | ||
""".format( | ||
intro=INTRO, | ||
instruction_key=INSTRUCTION, | ||
instruction="{prompt}", | ||
response_key=RESPONSE, | ||
) | ||
|
||
def get_gpt_score(prompt, system=SYSTEM0, api_key=None, model="gpt-3.5-turbo", | ||
max_tokens_prompt=384): | ||
api_key = api_key or os.environ.get("OPENAI_KEY") | ||
openai.api_key = api_key | ||
|
||
# Example OpenAI Python library request | ||
# can be chain of role's that will continue with | ||
response = openai.ChatCompletion.create( | ||
model=model, | ||
messages=[ | ||
{"role": "system", | ||
"content": system}, | ||
{"role": "user", | ||
"content": prompt[:max_tokens_prompt*4]}, | ||
], | ||
temperature=0.1, | ||
max_tokens=1024, | ||
) | ||
# get | ||
response1 = response['choices'][0]['message']['content'] | ||
response_split = response1.split("\n") | ||
score = response_split[0] | ||
score = score.lower().replace("score:", "").strip() | ||
score = float(score) | ||
return score |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,6 @@ pypandoc==1.11 | |
openpyxl==3.1.2 | ||
lm_dataformat==0.0.20 | ||
bioc==2.0 | ||
|
||
# eval | ||
openai==0.27.4 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no DDD?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, still very much WIP as title says. I just wanted to post before I lost changes.