Skip to content

Commit

Permalink
add regex to remove citations
Browse files Browse the repository at this point in the history
  • Loading branch information
vaughanlove committed Nov 30, 2023
1 parent 2c68a0c commit 7d1d5a3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
10 changes: 5 additions & 5 deletions app/cohere/CohereClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import os
from typing import List

logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
# logging.basicConfig()
# logging.getLogger().setLevel(logging.DEBUG)
# requests_log = logging.getLogger("requests")
# requests_log.setLevel(logging.DEBUG)
# requests_log.propagate = True

# Class to wrap cohere api functionality for better modularity and reusability
class CohereClient:
Expand Down
27 changes: 19 additions & 8 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ async def extract_url(payload: URLPayload, token: Annotated[str, Depends(oauth2_

@app.post("/generate_paragraphs/")
def generate_paragraphs(file: Annotated[bytes, File()], requirements: str, token: Annotated[str, Depends(oauth2_scheme)]):#, token: Annotated[str, Depends(oauth2_scheme)]
# get user data from JWT
# data = supabase.auth.get_user(token)
# # assert that the user is authenticated.
# assert data.user.aud == 'authenticated', "402: not authenticated."
get user data from JWT
data = supabase.auth.get_user(token)
# assert that the user is authenticated.
assert data.user.aud == 'authenticated', "402: not authenticated."

try:
# content = client.detect_document_text(Document={'Bytes': file})
Expand All @@ -87,11 +87,14 @@ def generate_paragraphs(file: Annotated[bytes, File()], requirements: str, token
print(err)
return {"para_A" : 'bad error handling i apologize. TODO <==='}

print(requirements)
job_req_list = "\n - ".join(requirements.split('\n,'))

prompt = f"""
The following are job requirements for a job I want to apply to:
<requirements>
- {requirements}
- {job_req_list}
</requirements>
Write me a couple paragraphs without an introduction/outro about why I am the right candidate for the job.
Expand Down Expand Up @@ -131,9 +134,17 @@ def generate_paragraphs(file: Annotated[bytes, File()], requirements: str, token
thread_id=thread.id
)

# delete the file and the thread.
delete_file = client.files.delete(file.id)

# potentially in the future, the user could generate a thread for the cover letter,
# and then chat with openai to iterate upon it.
delete_thread = client.beta.threads.delete(thread.id)

# print(messages.data[0].content[0].text.value)
# print(delete_thread)
return {'para_A' : messages.data[0].content[0].text.value, 'para_B' : 'result.data[1]'}
output = messages.data[0].content[0].text.value

# regex out the openai citations
pattern = r"【[^【]*】"
replaced_text = re.sub(pattern, "", output)

return {'para_A' : replaced_text, 'para_B' : 'result.data[1]'}
2 changes: 1 addition & 1 deletion app/scrape/ScrapeClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import concurrent.futures
from urllib.parse import urlencode
#from scrapeops_python_requests.scrapeops_requests import ScrapeOpsRequests
import logging
# import logging
from dotenv import load_dotenv, find_dotenv
from app.cohere.CohereClient import CohereClient
from openai import OpenAI
Expand Down

0 comments on commit 7d1d5a3

Please sign in to comment.