使用DeepSeek-R1 Distill LLaMA-70B构建谈判代理

使用DeepSeek-R1 Distill LLaMA-70B构建谈判代理

谈判是一门艺术,影响着从工作机会到商业交易的方方面面。无论您是在谈判薪水、完成商业交易,还是在解决合同纠纷,适当的技巧都可能是成功与牺牲之间的分水岭。为了简化和精简谈判过程,我开发了一个人工智能驱动的谈判代理(AI-Powered Negotiation Agent),这是一个基于 LangChain 和 DeepSeek-R1 的 Streamlit 网络应用程序。它能根据你的输入为你提供智能谈判策略,让你通过谈判达成最佳协议。

学习目标

  • 了解人工智能在加强各领域谈判策略中的作用。
  • 了解 DeepSeek R1 Distill Llama 70B 如何实现实时 AI 驱动的谈判洞察。
  • 探索人工智能谈判代理的关键功能,包括还价和风险评估。
  • 亲身体验在 Streamlit 中设置和使用人工智能驱动的谈判工具。
  • 了解人工智能生成的策略如何优化薪资讨论、商业交易和合同谈判。

什么是DeepSeek R1 Distill Llama 70b?

DeepSeek-R1-Distill-Llama-70B 是一个高性能的 GroqCloud AI 模型。它是 Llama 3.3 70B 的蒸馏版本,可智能高效地回答数学、编码和事实问题。

该模型按部就班地进行推理,因此适用于高层决策。借助 Groq 极其快速的推理能力,用户可以体验到无延迟的实时人工智能推理,为高端人工智能应用带来新的可能性。

问题陈述

由于缺乏信息、情感偏差或论证结构薄弱,人们很难进行有效的谈判。

  • 由于谈判技巧不佳,员工可能会选择低薪。
  • 企业可能因为不了解对方的需求而无法达成交易。
  • 自由职业者和初创企业在定价和合同方面举步维艰。

目标:创建一个人工智能代理,分析谈判场景,预测还价,并根据逻辑和过去的数据提出最佳谈判策略。

AI谈判代理的主要功能

下面让我们了解一下 AI 谈判代理的主要功能:

  • 支持多种谈判类型(薪资、商业交易、自由职业、合同纠纷)
  • 人工智能生成还价,并提供理由和风险评估
  • 可定制的输入字段,用于个性化谈判场景
  • 为人工智能建议的策略进行置信度评分
  • 使用 Groq API 进行快速高效的处理

该代理如何工作

用户首先打开 Streamlit 应用程序,选择所需的谈判类型。然后输入报价详情,提供关键信息供人工智能模型处理。点击 “生成人工智能策略 ”按钮后,系统将初始化并加载大型语言模型(DeepSeek-R1)。然后使用预定义的提示模板处理输入数据,确保人工智能有效地理解谈判背景。

处理完成后,人工智能会根据提供的细节生成量身定制的谈判策略。最后,系统会显示人工智能建议的策略,提供见解和建议,帮助用户完成谈判过程。

谈判代理工作流

选择谈判类型

从四个预定义选项中进行选择:

  • 薪资谈判
  • 商业交易
  • 自由职业者定价
  • 合同纠纷

输入您的报价和限制条件

填写:

  • 您建议的出价(₹ 或 %)
  • 对方的预期报价
  • 关键限制,如最低工资、投资限制或截止日期

人工智能生成策略

提交后,人工智能会分析您的谈判,并提供

  • 基于输入的最佳还价
  • 还价理由
  • 风险评估(被接受的可能性)
  • 信心分数(满分 100)

利用人工智能洞察力进行谈判

利用人工智能生成的策略,自信地进行谈判并达成更好的交易。

设置基础

下面我们将通过首先设置环境,然后安装库来设置基础:

环境设置

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# Create a Environment
python -m venv env
# Activate it on Windows
.\env\Scripts\activate
# Activate in MacOS/Linux
source env/bin/activate
# Create a Environment python -m venv env # Activate it on Windows .\env\Scripts\activate # Activate in MacOS/Linux source env/bin/activate
# Create a Environment
python -m venv env
# Activate it on Windows
.\env\Scripts\activate
# Activate in MacOS/Linux
source env/bin/activate

安装Requirements.txt

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
pip install -r https://raw.githubusercontent.com/Gouravlohar/Negotiation-Agent/refs/heads/main/requirements.txt
pip install -r https://raw.githubusercontent.com/Gouravlohar/Negotiation-Agent/refs/heads/main/requirements.txt
pip install -r https://raw.githubusercontent.com/Gouravlohar/Negotiation-Agent/refs/heads/main/requirements.txt

设置API密钥

访问 Groq 获取 API 密钥。

访问 Groq 获取 API 密钥。 

粘贴 API 密钥到 .env 文件中:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
GROQ_API_KEY="Your API KEY PASTE HERE"
GROQ_API_KEY="Your API KEY PASTE HERE"
GROQ_API_KEY="Your API KEY PASTE HERE"

使用DeepSeek-R1 Distill LLaMA-70B构建谈判代理

下面,我们将引导您使用DeepSeek-R1 Distill LLaMA-70B和Streamlit构建人工智能谈判代理,让您毫不费力地生成智能、数据驱动的谈判策略。让我们开始吧!

第一步:导入必要的库

导入必要的库,包括用于 UI 的 Streamlit、用于 AI 处理的 LangChain 和用于环境变量管理的 dotenv,以建立谈判代理。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import os
import streamlit as st
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain_groq import ChatGroq
from dotenv import load_dotenv
import os import streamlit as st from langchain.prompts import PromptTemplate from langchain.chains import LLMChain from langchain_groq import ChatGroq from dotenv import load_dotenv
import os
import streamlit as st
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain_groq import ChatGroq
from dotenv import load_dotenv

第二步:加载Groq API密钥

应用程序会从环境文件中加载 Groq API 密钥。如果缺少密钥,系统将显示错误信息,并停止执行以防止未经授权的访问。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
load_dotenv()
groq_api_key = os.getenv("GROQ_API_KEY")
if not groq_api_key:
st.error("Groq API Key not found in .env file")
st.stop()
load_dotenv() groq_api_key = os.getenv("GROQ_API_KEY") if not groq_api_key: st.error("Groq API Key not found in .env file") st.stop()
load_dotenv()
groq_api_key = os.getenv("GROQ_API_KEY")
if not groq_api_key:
st.error("Groq API Key not found in .env file")
st.stop()

第三步:设置Streamlit界面

Streamlit 应用程序采用标题和宽版面设计。这确保了与谈判代理接触的界面结构合理、用户友好。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
st.set_page_config(page_title="AI Negotiation Agent", layout="wide")
st.title("🤝 AI-Powered Negotiation Agent")
st.set_page_config(page_title="AI Negotiation Agent", layout="wide") st.title("🤝 AI-Powered Negotiation Agent")
st.set_page_config(page_title="AI Negotiation Agent", layout="wide")
st.title("🤝 AI-Powered Negotiation Agent")

第四步:设置谈判代理侧边栏

在侧边栏中,用户可以选择自己喜欢的谈判类型–薪资谈判、商业交易、自由定价或合同纠纷,从而定制人工智能生成的策略。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
st.sidebar.header("Negotiation Settings")
st.sidebar.markdown("Select your negotiation type and explore the details below.")
negotiation_type = st.sidebar.selectbox("Negotiation Type", [
"Salary Negotiation",
"Business Deal",
"Freelance Pricing",
"Contract Dispute"
])
st.sidebar.header("Negotiation Settings") st.sidebar.markdown("Select your negotiation type and explore the details below.") negotiation_type = st.sidebar.selectbox("Negotiation Type", [ "Salary Negotiation", "Business Deal", "Freelance Pricing", "Contract Dispute" ])
st.sidebar.header("Negotiation Settings")
st.sidebar.markdown("Select your negotiation type and explore the details below.")
negotiation_type = st.sidebar.selectbox("Negotiation Type", [
"Salary Negotiation", 
"Business Deal", 
"Freelance Pricing", 
"Contract Dispute"
])
  • 添加侧边栏,供用户选择协商类型。
  • 可用选项:薪资、商业交易、自由职业者定价、合同纠纷: 薪资、商业交易、自由定价、合同纠纷。

第五步:用户说明

一个可扩展的部分提供了如何使用应用程序的逐步指导。用户输入报价详情,点击“Generate AI Strategy”按钮,并根据需要调整谈判设置。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
with st.expander("How to use this app"):
st.markdown("""
- Fill in your offer, the opposing offer, and key constraints.
- Click **Generate AI Strategy** to receive suggestions.
- Use the sidebar to adjust the negotiation type.
""")
with st.expander("How to use this app"): st.markdown(""" - Fill in your offer, the opposing offer, and key constraints. - Click **Generate AI Strategy** to receive suggestions. - Use the sidebar to adjust the negotiation type. """)
with st.expander("How to use this app"):
st.markdown("""
- Fill in your offer, the opposing offer, and key constraints.
- Click **Generate AI Strategy** to receive suggestions.
- Use the sidebar to adjust the negotiation type.
""")

第六步:AI处理的提示模板

定义一个结构化的提示模板,以确保人工智能模型收到关键的谈判细节。其中包括谈判类型、出价、限制以及预期的人工智能输出,如还价、风险评估和信心分数。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
negotiation_template = """
You are an expert negotiator. Analyze this scenario and suggest the best negotiation strategy:
- **Negotiation Type:** {negotiation_type}
- **Your Offer:** {your_offer}
- **Other Party's Expected Offer:** {other_party_stance}
- **Key Constraints:** {key_constraints}
### Provide:
1. The best counteroffer.
2. Justification with reasoning.
3. Risk assessment (if any).
4. Confidence score (out of 100%).
"""
negotiation_template = """ You are an expert negotiator. Analyze this scenario and suggest the best negotiation strategy: - **Negotiation Type:** {negotiation_type} - **Your Offer:** {your_offer} - **Other Party's Expected Offer:** {other_party_stance} - **Key Constraints:** {key_constraints} ### Provide: 1. The best counteroffer. 2. Justification with reasoning. 3. Risk assessment (if any). 4. Confidence score (out of 100%). """
negotiation_template = """
You are an expert negotiator. Analyze this scenario and suggest the best negotiation strategy:
- **Negotiation Type:** {negotiation_type}
- **Your Offer:** {your_offer}
- **Other Party's Expected Offer:** {other_party_stance}
- **Key Constraints:** {key_constraints}
### Provide:
1. The best counteroffer.
2. Justification with reasoning.
3. Risk assessment (if any).
4. Confidence score (out of 100%).
"""
  • 为人工智能处理定义结构化提示。
  • 人工智能将生成:还价、推理、风险评估、置信度评分。

第七步:加载AI模型的函数

我们使用 ChatGroq API 实现了一个函数来初始化 DeepSeek R1(Distill LLaMA-70B)模型。参数 streaming=True 可实现实时响应生成。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
def load_LLM(groq_api_key):
"""Loads the ChatGroq model for processing."""
llm = ChatGroq(groq_api_key=groq_api_key, model_name="deepseek-r1-distill-llama-70b", streaming=True)
return llm
def load_LLM(groq_api_key): """Loads the ChatGroq model for processing.""" llm = ChatGroq(groq_api_key=groq_api_key, model_name="deepseek-r1-distill-llama-70b", streaming=True) return llm
def load_LLM(groq_api_key):
"""Loads the ChatGroq model for processing."""
llm = ChatGroq(groq_api_key=groq_api_key, model_name="deepseek-r1-distill-llama-70b", streaming=True)
return llm
  • 通过 ChatGroq API 初始化 DeepSeek R1(Distill LLaMA 70B)。
  • Streaming=True 允许实时响应。

第八步:收集用户输入

表单可捕获用户输入,包括他们的出价、对手的预期出价和关键限制条件。这些信息对于人工智能模型生成有效的谈判策略至关重要。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
st.header(f"💼 {negotiation_type}")
st.markdown("Enter details of your negotiation scenario below:")
with st.form(key="negotiation_form"):
col1, col2 = st.columns(2)
with col1:
your_offer = st.text_input("Your Offer (₹ or %):", placeholder="Enter your proposed offer...")
with col2:
other_party_stance = st.text_input("Other Party's Expected Offer (₹ or %):", placeholder="Enter expected counteroffer...")
key_constraints = st.text_area("Key Constraints", height=150, placeholder="List deal-breakers, goals, must-haves...")
submit_button = st.form_submit_button("Generate AI Strategy")
st.header(f"💼 {negotiation_type}") st.markdown("Enter details of your negotiation scenario below:") with st.form(key="negotiation_form"): col1, col2 = st.columns(2) with col1: your_offer = st.text_input("Your Offer (₹ or %):", placeholder="Enter your proposed offer...") with col2: other_party_stance = st.text_input("Other Party's Expected Offer (₹ or %):", placeholder="Enter expected counteroffer...") key_constraints = st.text_area("Key Constraints", height=150, placeholder="List deal-breakers, goals, must-haves...") submit_button = st.form_submit_button("Generate AI Strategy")
st.header(f"💼 {negotiation_type}")
st.markdown("Enter details of your negotiation scenario below:")
with st.form(key="negotiation_form"):
col1, col2 = st.columns(2)
with col1:
your_offer = st.text_input("Your Offer (₹ or %):", placeholder="Enter your proposed offer...")
with col2:
other_party_stance = st.text_input("Other Party's Expected Offer (₹ or %):", placeholder="Enter expected counteroffer...")
key_constraints = st.text_area("Key Constraints", height=150, placeholder="List deal-breakers, goals, must-haves...")
submit_button = st.form_submit_button("Generate AI Strategy")

创建一个供用户输入的表单:

  • 他们的报价
  • 预期还价
  • 任何限制条件或交易破坏者

第九步:生成基于AI的谈判策略

提交后,应用程序会先验证输入字段,然后再处理数据。加载人工智能模型,并发送生成策略的提示。回复包括还价、理由、风险评估和信心分数。如果缺少任何字段,错误信息会提示用户填写表格。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
if submit_button:
if your_offer and other_party_stance and key_constraints:
with st.spinner("Generating negotiation strategy..."):
llm = load_LLM(groq_api_key)
prompt_obj = PromptTemplate(
input_variables=["negotiation_type", "your_offer", "other_party_stance", "key_constraints"],
template=negotiation_template
)
chain = LLMChain(llm=llm, prompt=prompt_obj)
result = chain.run(
negotiation_type=negotiation_type,
your_offer=your_offer,
other_party_stance=other_party_stance,
key_constraints=key_constraints
)
st.success("Strategy generated successfully!")
st.subheader("💡 AI's Suggested Strategy:")
st.markdown(result)
else:
st.error("Please fill in all fields before generating a strategy.")
if submit_button: if your_offer and other_party_stance and key_constraints: with st.spinner("Generating negotiation strategy..."): llm = load_LLM(groq_api_key) prompt_obj = PromptTemplate( input_variables=["negotiation_type", "your_offer", "other_party_stance", "key_constraints"], template=negotiation_template ) chain = LLMChain(llm=llm, prompt=prompt_obj) result = chain.run( negotiation_type=negotiation_type, your_offer=your_offer, other_party_stance=other_party_stance, key_constraints=key_constraints ) st.success("Strategy generated successfully!") st.subheader("💡 AI's Suggested Strategy:") st.markdown(result) else: st.error("Please fill in all fields before generating a strategy.")
if submit_button:
if your_offer and other_party_stance and key_constraints:
with st.spinner("Generating negotiation strategy..."):
llm = load_LLM(groq_api_key)
prompt_obj = PromptTemplate(
input_variables=["negotiation_type", "your_offer", "other_party_stance", "key_constraints"],
template=negotiation_template
)
chain = LLMChain(llm=llm, prompt=prompt_obj)
result = chain.run(
negotiation_type=negotiation_type, 
your_offer=your_offer, 
other_party_stance=other_party_stance, 
key_constraints=key_constraints
)
st.success("Strategy generated successfully!")
st.subheader("💡 AI's Suggested Strategy:")
st.markdown(result)
else:
st.error("Please fill in all fields before generating a strategy.")
  • 用户提交谈判方案(出价、对手出价、限制条件)。
  • 代码检查所有字段是否填写完毕。
  • 人工智能处理输入时,会出现一个加载旋转器。
  • DeepSeek AI 根据提示生成谈判策略。
  • 策略会显示出来,包括还价、风险和理由。
  • 如果缺少输入,则会显示错误信息。

在 GitHub 上获取完整代码

AI谈判代理工作界面

测试AI谈判代理

输入

谈判类型:薪资谈判

  • 您的报价:₹15LPA(百万年薪)
  • 对方的预期报价:₹12 LPA

关键制约因素:

  • 最低₹14 LPA 以满足开支。
  • 喜欢混合工作的灵活性。
  • 对基于绩效的激励机制持开放态度。

输出

AI谈判代理建议

小结

无论是在工作中还是在个人生活中,谈判都是一项宝贵的技能,而使用 DeepSeek-R1 的“谈判代理”可以利用数据来帮助您改善交易谈判。无论您是在谈判加薪、商业投资还是合同条款,这款应用程序都能通过人工智能生成的还价、风险水平和信心分数帮助您做出更好的决定。

该工具利用 DeepSeek-R1 Distill LLaMA-70B、LangChain 和 Streamlit 来促进谈判。它能帮助您最大限度地减少不确定性,最大限度地提高成功率。

有了人工智能,您不必再猜测自己的最佳策略,而是可以满怀信心地进行谈判!

  • 该程序可分析报价和限制条件,提供智能还价。
  • 支持薪资谈判、商业交易、自由职业者定价和合同纠纷。
  • 人工智能会评估谈判的成功概率和潜在风险。
  • 用户可以输入报价和关键限制条件,生成量身定制的策略。
  • 通过使用 DeepSeek R1 Distill Llama 70b 和 LangChain,该应用程序可快速处理数据并提供可行的策略。

常见问题

Q1. load_LLM() 函数的作用是什么?

A. load_LLM() 函数使用 ChatGroq API 初始化 DeepSeek R1 Distill Llama 70b 模型。它返回一个 LLM(语言模型),用于处理用户输入并生成协商策略。

Q2. PromptTemplate 的作用是什么?

A. PromptTemplate 定义了发送给人工智能的提示结构。它确保人工智能收到所有必要的详细信息(报价、限制条件、谈判类型),以生成有意义的回复。

Q3. 为什么 API 密钥存储在 .env 文件中?

A. API 密钥是敏感数据,将其存储在 .env 文件中可以保证安全。dotenv 软件包会将此密钥加载到环境中,而不会在代码中暴露。

Q4. 应用程序如何处理丢失的用户输入?

A. 在提交之前,应用程序会验证输入字段(your_offer、other_party_stance、key_constraints)。如果任何字段为空,程序会显示错误信息,以确保完整的数据输入。

评论留言