使用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)。如果任何欄位為空,程式會顯示錯誤資訊,以確保完整的資料輸入。

評論留言