Skip to content
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

Fix broken link to existing directory and Update code with latest version of openai #249

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions Evol_Instruct/openai_access.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import openai
import time
import requests

openai.api_key = 'your api key'

client = openai.OpenAI(
api_key = 'your api key')

def get_oai_completion(prompt):

try:
response = openai.ChatCompletion.create(
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
Expand All @@ -21,19 +22,17 @@ def get_oai_completion(prompt):
presence_penalty=0,
stop=None
)
res = response["choices"][0]["message"]["content"]

gpt_output = res
return gpt_output
res = response.model_dump(mode='python')['choices'][0]['message']['content']
return res
except requests.exceptions.Timeout:
# Handle the timeout error here
print("The OpenAI API request timed out. Please try again later.")
return None
except openai.error.InvalidRequestError as e:
except openai.BadRequestError as e:
# Handle the invalid request error here
print(f"The OpenAI API request was invalid: {e}")
return None
except openai.error.APIError as e:
except openai.APIError as e:
if "The operation was timeout" in str(e):
# Handle the timeout error here
print("The OpenAI API request timed out. Please try again later.")
Expand All @@ -43,7 +42,7 @@ def get_oai_completion(prompt):
# Handle other API errors here
print(f"The OpenAI API returned an error: {e}")
return None
except openai.error.RateLimitError as e:
except openai.RateLimitError as e:
return get_oai_completion(prompt)

def call_chatgpt(ins):
Expand All @@ -58,4 +57,4 @@ def call_chatgpt(ins):
except:
time.sleep(5)
print('retry for sample:', ins)
return ans
return ans
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ We welcome everyone to use your professional and difficult instructions to evalu

## Overview of Evol-Instruct

[Evol-Instruct](https://github.com/nlpxucan/evol-instruct) is a novel method using LLMs instead of humans to automatically mass-produce open-domain instructions of various difficulty levels and skills range, to improve the performance of LLMs. You can easily embark on your own evolutionary journey with the [Evol Script](https://github.com/nlpxucan/WizardLM/tree/main/Evol-Instruct) we provide.
[Evol-Instruct](https://github.com/nlpxucan/evol-instruct) is a novel method using LLMs instead of humans to automatically mass-produce open-domain instructions of various difficulty levels and skills range, to improve the performance of LLMs. You can easily embark on your own evolutionary journey with the [Evol Script](https://github.com/nlpxucan/WizardLM/tree/main/Evol_Instruct) we provide.

<p align="center" width="100%">
<a ><img src="imgs/git_overall.png" alt="WizardLM" style="width: 86%; min-width: 300px; display: block; margin: auto;"></a>
Expand Down