Skip to content

Commit

Permalink
Merge pull request #7 from drexelai/conversation-summarization
Browse files Browse the repository at this point in the history
conversation summary fix
  • Loading branch information
azavalny authored Nov 10, 2024
2 parents 49b6fe3 + d46b5e4 commit bed6db1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
14 changes: 8 additions & 6 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
```
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
```

and do `python ./server.py` to run the backend
`python -m venv .venv`

`.venv\Scripts\activate` if on windows or `source .venv\bin\activate` if on mac/linux

`pip install -r requirements.txt`


and do `python ./server.py` to run the backend. You'll need someone from the team to send you the `keys.env` file
29 changes: 11 additions & 18 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@
CORS(app, origins=["http://localhost:3000", "https://drexelai.github.io"], supports_credentials=True)# Allowing for future credential usage

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
INSTRUMENTATION_KEY = os.environ.get("APPINSIGHTS_INSTRUMENTATIONKEY")
INSTRUMENTATION_CONNECTION_STRING = os.environ.get("APPINSIGHTS_CONNECTION_STRING")
tracer = Tracer(
exporter=AzureExporter(connection_string=f"InstrumentationKey={INSTRUMENTATION_KEY}"),
exporter=AzureExporter(connection_string=INSTRUMENTATION_CONNECTION_STRING),
sampler=ProbabilitySampler(1.0)
)

# Set up the logger to send logs to Application Insights
handler = AzureLogHandler(connection_string=f"InstrumentationKey={INSTRUMENTATION_KEY}")
handler = AzureLogHandler(connection_string=INSTRUMENTATION_CONNECTION_STRING)
logger = logging.getLogger(__name__)
logger.addHandler(handler)
logger.setLevel(logging.INFO)


def check_rag_with_openai_api(RAG, query):
check_prompt = f"Does the following context answer the query?\n\nContext: {RAG}\n\nQuery: {query}\n\nAnswer with 'yes' or 'no' in lowercase only please."
check_response = client.chat.completions.create(
Expand Down Expand Up @@ -132,24 +133,16 @@ def generate():

@app.route("/summarize-convo", methods=["POST"])
def summarize_convo():

firstMessage = request.get_json()["message"]

def generate2():
stream = client.chat.completions.create(
chatrename = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a message summarizer who summarizes a given message into 2-3 words"},
{"role": "user", "content": firstMessage + "\n\nSummarize this message into 2-3 words and just return the message"}
],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
content = chunk.choices[0].delta.content
#print(content) # Print the content for debugging purposes
yield content
return Response(generate2(), content_type="text/plain-text")
]
).choices[0].message.content

return {"messageSummary": chatrename}


@app.route("/blackboard", methods=["POST"])
Expand All @@ -158,7 +151,7 @@ def query_blackboard():
response2 = "Your assignments this week: ENTP 205 Ready, Set, Fail: Discussion board post on business idea due Friday 11:59PM. ENTP 325 Early Stage Venture Funding: Cap table assignment due Wednesday 11:59PM. MATH 121: Problem Set 4 pages 79-81 textbook due Thursday before class. Suggested Time Budgeting Plan: Monday (Today) – Focus: Start and finish Cap Table Assignment for ENTP 325. Time Required: 2-3 hours (including research and calculations). Goal: Complete most, if not all, of this assignment since it’s due soonest. Tuesday – Focus: Finish up the Cap Table Assignment if any parts remain. Time Required: 1 hour (if needed for final touch-ups). Begin: MATH 121 Problem Set 4 to avoid rushing before class on Thursday. Time Required: 1-2 hours. Goal: Get at least halfway through the problem set. Wednesday – Focus: Complete the remaining part of MATH 121 Problem Set 4. Time Required: 1-2 hours. Goal: Finish the problem set and review answers if time allows. Thursday – Focus: Write the Discussion Board Post for ENTP 205. Time Required: 1-2 hours for writing and revising. Goal: Complete the post in time for submission on Friday. This plan ensures you’re prioritizing based on due dates and spreading out your workload for a balanced approach."


def generate3():
def generateblackboard():
stream = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
Expand All @@ -172,7 +165,7 @@ def generate3():
content = chunk.choices[0].delta.content
#print(content) # Print the content for debugging purposes
yield content
return Response(generate3(), content_type="text/plain-text")
return Response(generateblackboard(), content_type="text/plain-text")


if __name__ == "__main__":
Expand Down

0 comments on commit bed6db1

Please sign in to comment.