Spaces:
Paused
Paused
Sameer Gupta commited on
Commit ·
83d33f9
1
Parent(s): 2b82e2c
remove multiple llm calls
Browse files
main.py
CHANGED
|
@@ -514,45 +514,45 @@ async def chat_endpoint(request: ChatRequest):
|
|
| 514 |
ncon = 3
|
| 515 |
chat_history_str = extract_chats(collection, userid, ncon)
|
| 516 |
|
| 517 |
-
prev_goalandfocus = extract_goalfocus(collection, userid)
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
|
| 541 |
|
| 542 |
-
try:
|
| 543 |
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
|
| 550 |
-
|
| 551 |
-
except json.JSONDecodeError:
|
| 552 |
-
|
| 553 |
|
| 554 |
|
| 555 |
-
goalandfocus = parsed_json
|
| 556 |
|
| 557 |
context_response = f"""
|
| 558 |
User Context:
|
|
@@ -565,9 +565,14 @@ async def chat_endpoint(request: ChatRequest):
|
|
| 565 |
utilise this to give the answer
|
| 566 |
Also, at each step we are determining the topic and goal of the conversation to give a proper direction to the chats. This is to help you (who is acting as a guru to the user)
|
| 567 |
to guide him better
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 568 |
goal is something which defines the next step which you should be taking in the converstaion, don't very rigidly follow it but try to take the direction from it
|
| 569 |
-
|
| 570 |
-
here's the current topic and goal : {goalandfocus}
|
| 571 |
Here is the conversation history of past {ncon} conversations: {chat_history_str}, use this very wisely to extract the best out of them and then follow the goal and focus to guide the user further
|
| 572 |
If you recieve nothing as goal and focus that means convessation has just started shaping
|
| 573 |
Based on user current input, the current topic and goal, and the RAG output, provide a response. It could be anything, maybe a question a follow up you've to carefully decide on that. Also, while giving responses remember to give it such there is a link between the previous conversations and current one. It shouldn't sound like new conversation has started.
|
|
@@ -611,10 +616,10 @@ async def chat_endpoint(request: ChatRequest):
|
|
| 611 |
"human": user_input,
|
| 612 |
"ai": ai_response_text
|
| 613 |
},
|
| 614 |
-
"meta": {
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
}
|
| 618 |
}
|
| 619 |
|
| 620 |
try:
|
|
@@ -642,8 +647,10 @@ async def chat_endpoint(request: ChatRequest):
|
|
| 642 |
|
| 643 |
return ChatResponse(
|
| 644 |
response=ai_response_text,
|
| 645 |
-
topic=
|
| 646 |
-
goal=
|
|
|
|
|
|
|
| 647 |
resources=[]
|
| 648 |
)
|
| 649 |
|
|
|
|
| 514 |
ncon = 3
|
| 515 |
chat_history_str = extract_chats(collection, userid, ncon)
|
| 516 |
|
| 517 |
+
# prev_goalandfocus = extract_goalfocus(collection, userid)
|
| 518 |
+
|
| 519 |
+
# context_goal = f'''
|
| 520 |
+
# Ohk, so you are an expert in navigating paths through human conversations. So, let's say if someone is telling you about how they are feeling, what they did
|
| 521 |
+
# what other people did to them, what are their problems, what are their goals and aspirations in life and all that stuff.
|
| 522 |
+
# Now based on all the above information, you need to figure that as a teacher/Guru (which you are for the person)
|
| 523 |
+
# what should be the topic (or the broad thing that is going on currently as a part of discussion - it could discussion about office, or marriage or house problems or anything) you've to figure this out from based on previous converstaion history.
|
| 524 |
+
# At the same time, you have to ask/suggest/recommend further to the person as well right. So for that you have to define a goal (that is basically what should be the exact next step in this conversation - should you be asking a quuestion or should be recommending something or maybe just chatting normally). again this also you've to decide. But goal has to be something which defines the next step
|
| 525 |
+
# whereas topic is something which is broad and overall defines what is going on in the converstaion.
|
| 526 |
+
# Your response format should be like this:
|
| 527 |
+
# "Topic":" <topic> ",
|
| 528 |
+
# "Goal":" <goal> "
|
| 529 |
+
|
| 530 |
+
# Don't output anything else other than this format.
|
| 531 |
+
# Here is the conversation history of past {ncon} conversations: {chat_history_str}
|
| 532 |
+
# also, here;s the current user question: {user_input}
|
| 533 |
+
# You can also look upon what was the topic and goal defined just previously to get better idea.
|
| 534 |
+
# previous topic and goal : {prev_goalandfocus}
|
| 535 |
+
# Try updating goal on each instance but topic can remain same if the converstaion is still revolving around the same thing. Because obviusly you've to dig deeper with the user, you can't be doing the same thign in the goal
|
| 536 |
+
# ALso, if the user isn't talking anymore about the previous topic, you can change the topic as well. Thats why i am providin gyou the previous focus and goal
|
| 537 |
+
# '''
|
| 538 |
+
|
| 539 |
+
# goal_response = llm.invoke(context_goal)
|
| 540 |
|
| 541 |
|
| 542 |
+
# try:
|
| 543 |
|
| 544 |
+
# clean_content = goal_response.content.replace("```json", "").replace("```", "").strip()
|
| 545 |
+
# if not clean_content.startswith("{"):
|
| 546 |
+
# json_string_to_parse = "{" + clean_content + "}"
|
| 547 |
+
# else:
|
| 548 |
+
# json_string_to_parse = clean_content
|
| 549 |
|
| 550 |
+
# parsed_json = json.loads(json_string_to_parse)
|
| 551 |
+
# except json.JSONDecodeError:
|
| 552 |
+
# parsed_json = {"Topic": "General", "Goal": "Continue conversation"}
|
| 553 |
|
| 554 |
|
| 555 |
+
# goalandfocus = parsed_json
|
| 556 |
|
| 557 |
context_response = f"""
|
| 558 |
User Context:
|
|
|
|
| 565 |
utilise this to give the answer
|
| 566 |
Also, at each step we are determining the topic and goal of the conversation to give a proper direction to the chats. This is to help you (who is acting as a guru to the user)
|
| 567 |
to guide him better
|
| 568 |
+
Ohk, so you are an expert in navigating paths through human conversations. So, let's say if someone is telling you about how they are feeling, what they did
|
| 569 |
+
what other people did to them, what are their problems, what are their goals and aspirations in life and all that stuff.
|
| 570 |
+
Now based on all the above information, you need to figure that as a teacher/Guru (which you are for the person)
|
| 571 |
+
what should be the topic (or the broad thing that is going on currently as a part of discussion - it could discussion about office, or marriage or house problems or anything) you've to figure this out from based on previous converstaion history.
|
| 572 |
+
At the same time, you have to ask/suggest/recommend further to the person as well right. So for that you have to define a goal (that is basically what should be the exact next step in this conversation - should you be asking a quuestion or should be recommending something or maybe just chatting normally). again this also you've to decide. But goal has to be something which defines the next step
|
| 573 |
+
whereas topic is something which is broad and overall defines what is going on in the converstaion.
|
| 574 |
goal is something which defines the next step which you should be taking in the converstaion, don't very rigidly follow it but try to take the direction from it
|
| 575 |
+
Based on whatever topic and goal you've decided, you should continue your discussion along with the conversation history
|
|
|
|
| 576 |
Here is the conversation history of past {ncon} conversations: {chat_history_str}, use this very wisely to extract the best out of them and then follow the goal and focus to guide the user further
|
| 577 |
If you recieve nothing as goal and focus that means convessation has just started shaping
|
| 578 |
Based on user current input, the current topic and goal, and the RAG output, provide a response. It could be anything, maybe a question a follow up you've to carefully decide on that. Also, while giving responses remember to give it such there is a link between the previous conversations and current one. It shouldn't sound like new conversation has started.
|
|
|
|
| 616 |
"human": user_input,
|
| 617 |
"ai": ai_response_text
|
| 618 |
},
|
| 619 |
+
# "meta": {
|
| 620 |
+
# "Topic": parsed_json.get("Topic", "Unknown"),
|
| 621 |
+
# "Goal": parsed_json.get("Goal", "Unknown")
|
| 622 |
+
# }
|
| 623 |
}
|
| 624 |
|
| 625 |
try:
|
|
|
|
| 647 |
|
| 648 |
return ChatResponse(
|
| 649 |
response=ai_response_text,
|
| 650 |
+
topic="Unknown",
|
| 651 |
+
goal="Unknown",
|
| 652 |
+
# topic=parsed_json.get("Topic", "Unknown"),
|
| 653 |
+
# goal=parsed_json.get("Goal", "Unknown"),
|
| 654 |
resources=[]
|
| 655 |
)
|
| 656 |
|