newWork / openai_assistant_langchain_gradio.py
samreddy's picture
Update openai_assistant_langchain_gradio.py
cdbba52
from langchain.agents.openai_assistant import OpenAIAssistantRunnable
from langchain.schema.agent import AgentFinish
import gradio as gr
import os
import logging
tools = []
assistant_id = os.environ['assistant_id']
thread_id = None
history = "dummy history"
agent = OpenAIAssistantRunnable(assistant_id=assistant_id, as_agent=True)
examples = ["Develop a eCommerce website with $10k budget", "Kick off New Project", "Search for Freelancers", "More Freelancer Recommendations", "Help me Interview the Freelancers", "Generate new Milestones", "Generate new Contract", "Evaluate a Milestone: <PASTE CODE HERE>", "Restart Conversation"]
def execute_agent(agent, tools, input):
tool_map = {tool.name: tool for tool in tools}
response = agent.invoke(input)
while not isinstance(response, AgentFinish):
tool_outputs = []
for action in response:
tool_output = tool_map[action.tool].invoke(action.tool_input)
print(action.tool, action.tool_input, tool_output, end="\n\n")
tool_outputs.append(
{"output": tool_output, "tool_call_id": action.tool_call_id}
)
response = agent.invoke(
{
"tool_outputs": tool_outputs,
"run_id": action.run_id,
"thread_id": action.thread_id,
}
)
return response
def openai_response(message,history):
global thread_id
global examples
option_1 = "\n"
option_2 = "\n"
option_3 = "\n"
option_4 = "\n"
option_5 = "\n"
option_6 = "\n"
if message == "Kick off New Project":
new_output = "What is the project about?"
thread_id = None
elif message == "Restart Conversation":
new_output = "What project would you like to kickstart?"
thread_id = None
else:
if not thread_id:
context = "Project is to "
enriched_message = context + message
response = execute_agent(agent, tools, {"content": enriched_message})
thread_id = response.return_values["thread_id"]
option_1 = "-> **Search for Freelancers**"
else:
if message == "Search for Freelancers":
context = "Provide brief recommendations, under 200 words, for suitable freelancers with specific skills, using fictitious names. Summarize why each is chosen based on their profile, skills, past jobs, client feedback, portfolio, and cost, ensuring budget considerations are met."
response = execute_agent(agent, tools, {"content": context, "thread_id": thread_id})
option_1 = "-> **More Freelancer Recommendations**"
option_2 = "-> **Help me Interview the Freelancers**"
elif message == "More Freelancer Recommendations":
context = "Kindly offer additional recommendations, under 200 words."
response = execute_agent(agent, tools, {"content": context, "thread_id": thread_id})
option_1 = "-> **More Freelancer Recommendations**"
option_2 = "-> **Help me Interview the Freelancers**"
elif message == "Help me Interview the Freelancers":
context = "Create 5 questions for an interview focusing on the skills required for this project."
response = execute_agent(agent, tools, {"content": context, "thread_id": thread_id})
option_1 = "-> **Kick off New Project**"
option_2 = "-> **Search for Freelancers**"
option_3 = "-> **Generate new Milestones**"
option_4 = "-> **Generate new Contract**"
option_5 = "-> **Evaluate a Milestone: <PASTE CODE HERE>**"
option_6 = "-> **Restart Conversation**"
elif message == "Generate new Milestones":
context = "Create a list of key stages for this software development project, ensuring there are no more than six milestones."
response = execute_agent(agent, tools, {"content": context, "thread_id": thread_id})
option_1 = "-> **Generate new Contract**"
option_2 = "-> **Evaluate a Milestone**"
elif message.startswith("Evaluate a Milestone: ") or message.startswith("Evaluate") or message.startswith("evaluate"):
context = "Please assess the work quality for the milestone in relation to this project. Below is the provided code sample: "
enriched_message = context + message
response = execute_agent(agent, tools, {"content": enriched_message, "thread_id": thread_id})
option_1 = "-> **Kick off New Project**"
option_2 = "-> **Search for Freelancers**"
option_3 = "-> **Generate new Milestones**"
option_4 = "-> **Generate new Contract**"
option_5 = "-> **Evaluate a Milestone: <PASTE CODE HERE>**"
option_6 = "-> **Restart Conversation**"
elif message == "Generate new Contract":
context = "Create a contract for the project, including the key stages, milestones, and payment terms."
response = execute_agent(agent, tools, {"content": context, "thread_id": thread_id})
option_1 = "-> **Kick off New Project**"
option_2 = "-> **Search for Freelancers**"
option_3 = "-> **Generate new Milestones**"
option_4 = "-> **Generate new Contract**"
option_5 = "-> **Evaluate a Milestone: <PASTE CODE HERE>**"
option_6 = "-> **Restart Conversation**"
else:
response = execute_agent(agent, tools, {"content": message, "thread_id": thread_id})
option_1 = "-> **Kick off New Project**"
option_2 = "-> **Search for Freelancers**"
option_3 = "-> **Generate new Milestones**"
option_4 = "-> **Generate new Contract**"
option_5 = "-> **Evaluate a Milestone: <PASTE CODE HERE>**"
option_6 = "-> **Restart Conversation**"
output = response.return_values["output"]
next_options = "πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯ What would like to do next? πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯" +"\n\n" + option_1 + "\n" + option_2 + "\n" + option_3 + "\n" + option_4 + "\n" + option_5 + "\n" + option_6
new_output = output + "\n\n" + next_options
return new_output
problem_statement = """## Can Next-Gen Search Solve My Top 5 Upwork Client Challenges 😑?
### 1. **Lack of Technical Knowledge to do Project Breakdown**
- I used ***Upwork*** for 5 different projects, and more than once I had trouble properly creating a project plan and communicating requirements
- Approach?: Utilize Upwork's database of past projects and reviews. Implement **Next-gen neural search πŸ”Ž** in combination with generative AI to analyze this data and generate effective project breakdowns and requirements.
### 2. **Difficulty in Selecting the Right Technologies**
- Approach?: Employ **Next-gen search** to sift through previous project technologies, generating tailored technology recommendations that consider budget and timeframe constraints.
### 3. **Time and Skill Constraints in Searching for Freelancers**
- Approach?: Go **beyond basic keyword search** to analyze freelancers' galleries, GitHub, etc., for a nuanced understanding of their skills. Offer a few high-confidence recommendations instead of overwhelming search results.
### 4. **Inadequate Skills to Interview and Evaluate Freelancers**
- Approach?: Use **Next-gen Search** to access past client-freelancer interactions. Input this into an LLM to create interview questions and guide the evaluation process.
### 5. **Challenges in Creating Milestone Plans, Payment Breakdowns and Evaluating Progress**
- Approach?: Apply **Next-gen Search** to past interactions for insights into milestone and payment arrangements, and for comparing current progress with similar projects.
**Assumptions**:
- These insights are ONLY based on personal experiences and research on Upwork Forums.
- The focus is on technology projects, but the approach is applicable to other fields like graphics, content writing, admin, and marketing.
- This perspective is from a client's viewpoint, but a similar approach can benefit freelancers in job searches.
- Assumes no privacy constraints in leveraging aggregated platform data to assist clients.
***The following demo illustrates these capabilities using synthetic data, due to lack of access to actual Upwork data.***"""
theme='JohnSmith9982/small_and_pretty'
gr.ChatInterface(openai_response, examples=examples, textbox=gr.Textbox(placeholder="Enter a Project Description or ask a followup question on a project", container=False, scale=7), title="Move37 - Search unlocks Creativity and Intelligence", description=problem_statement, retry_btn= None, undo_btn=None, clear_btn=None, theme=theme, css="custom_style.css").launch(auth=("sree", "search"), share = True)