Skip to content

Commit

Permalink
🚧 fix(wip): add model type to text_classification
Browse files Browse the repository at this point in the history
  • Loading branch information
mxchinegod committed Mar 12, 2024
1 parent 882b5bb commit 3f9ec97
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ dist/
*.egg-info
key.txt
*.ipynb
*.pyc
*/*.pyc
*.pyc
hygiene/__pycache__/singleton.cpython-311.pyc
hygiene/payload/boxing/__pycache__/boxing.cpython-311.pyc
6 changes: 3 additions & 3 deletions hygiene/classify/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from hygiene.utils.globals import _f
from time import sleep

def classify_text(text, user_prompt, api_key="", schema={"original_data": "object", "scores": "list:float", "classes":"list:string"}, verbose=False):
def classify_text(text, user_prompt, model="gpt-4", api_key="", schema={"original_data": "object", "scores": "list:float", "classes":"list:string"}, verbose=False):
"""
Sends a string to the OpenAI GPT-4 API for classification according to the user prompt.
Expand All @@ -18,7 +18,7 @@ def classify_text(text, user_prompt, api_key="", schema={"original_data": "objec

# Call the OpenAI API with the prompt
response = openai.ChatCompletion.create(
model="gpt-4", # Specify the appropriate model for your task
model=model, # Specify the appropriate model for your task
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
Expand All @@ -33,4 +33,4 @@ def classify_text(text, user_prompt, api_key="", schema={"original_data": "objec
except Exception as e:
_f('warn', f"OpenAI didn't listen to our schema instructions, retrying\n{response}\n{e}")
sleep(1)
classify_text(text, user_prompt, api_key, schema)
classify_text(text, user_prompt, model=model, api_key=api_key, schema=schema)

0 comments on commit 3f9ec97

Please sign in to comment.