Hello Everyone !
I am Learning ACP Agent Communication Protocal ! i Ran into error like** Litellm,** i tried with gemini, huggingface and other model still i am facing error with** litellm provider , sometimes it might be api issue, sometimes it might be embedding issue, i am so clueless about this litellm . **
here is my code please help me setup this rag tool using hugging face api and opensource models, any guidence also would be much helpful and most needed in this stage for me.
!pip install crewai crewai-tools
!pip install transformers langchain-huggingface sentence-transformers
This i have implemented, by referring to the embedder site
from langchain_huggingface import HuggingFaceEmbeddings
embeddings = HuggingFaceEmbeddings(
model_name=âsentence-transformers/all-MiniLM-L6-v2â
)
yaml_content = ââ"
llm:
provider: huggingface
config:
model: âhuggingface/deepseek-ai/DeepSeek-R1â
api_key : RAG_HF_key
temperature: 0.7
max_tokens: 2048
top_p: 0.5
stream: false
embedder:
provider: huggingface
config:
model: âsentence-transformers/all-mpnet-base-v2â
model_kwargs:
trust_remote_code: True # Only use if you trust your embedder
ââ"
file_path = âconfig.yamlâ
with open(file_path, âwâ) as f:
f.write(yaml_content)
print(f"Configuration saved to {file_path}")
from embedchain import App
load embedding model configuration from config.yaml file
app = App.from_config(config_path=âconfig.yamlâ)
from crewai_tools import RagTool
config = {
âllmâ: {
âproviderâ: âhuggingfaceâ,
âconfigâ: {
âmodelâ: âhuggingface/mistralai/Mistral-7B-Instruct-v0.1â,
âapi_keyâ: âRAG_HF_keyâ,
âtemperatureâ: 0.7,
âmax_tokensâ: 2048,
âtop_pâ: 0.5,
âstreamâ: False
}
},
âembedding_modelâ: {
âproviderâ: âhuggingfaceâ,
âconfigâ: {
âmodelâ: âsentence-transformers/all-mpnet-base-v2â
}
}
}
rag_tool = RagTool(config=config)
rag_tool.add(âGitHub - ericyangyu/PPO-for-Beginners: A simple and well styled PPO implementation. Based on my Medium series: https://medium.com/@eyyu/coding-ppo-from-scratch-with-pytorch-part-1-4-613dfc1b14c8.â, data_type=âweb_pageâ)
rag_tool.add(âProximal Policy Optimization (PPO)â, data_type=âweb_pageâ)
This was worked , rag but integrating to llm and agent is not working
Inserting batches in chromadb: 100%|ââââââââââ| 1/1 [00:13<00:00
#====================== Setting crew ai agent and task ===================
llm_free = LLM(
model=âhuggingface/microsoft/DialoGPT-mediumâ, # Works with HF Inference API
api_key=RAG_HF_key,
temperature=0.7,
max_tokens=1024
)
#========================= Agent =============
from crewai import Task
task1 = Task(
description=âRead and analyze articles and research papers on Proximal Policy Optimization (PPO) for fine-tuning LLMs. Then, help the user implement PPO from scratch with reasoning and comments, using libraries where appropriate. Keep the code under 300 lines.â,
expected_output=âA well-commented PPO implementation for LLM fine-tuning, under 300 lines, with clear reasoning steps.â,
agent=researcher1,
tools=[rag_tool]
)
from crewai import Task
task1 = Task(
description=âRead and analyze articles and research papers on Proximal Policy Optimization (PPO) for fine-tuning LLMs. Then, help the user implement PPO from scratch with reasoning and comments, using libraries where appropriate. Keep the code under 300 lines.â,
expected_output=âA well-commented PPO implementation for LLM fine-tuning, under 300 lines, with clear reasoning steps.â,
agent=researcher1,
tools=[rag_tool]
)
crew = Crew(
agents=[researcher1],
tasks =[task1],
tools = [rag_tool],
verbose = True
)
result = crew.kickoff()
print(âTask Description:â, task1.description)
print(âOutput:\nâ, result)
#=================ERROR =================================
APIError: litellm.APIError: HuggingfaceException - {âerrorâ:âTemplate error: syntax error: After the optional system message, conversation roles must alternate user/assistant/user/assistant/⌠(in :11)â,âerror_typeâ:âtemplate_errorâ}
==================== PLEASE HELP ME HOW TO SET UP THIS, TEACH ============
** THANK YOU **