链载Ai

标题: Llama3实操的正确打开方式:RAG,Agent,Function Calling! [打印本页]

作者: 链载Ai    时间: 4 小时前
标题: Llama3实操的正确打开方式:RAG,Agent,Function Calling!

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;border-left: 4px solid rgb(248, 57, 41);line-height: 1.5em;visibility: visible;">基于Llama3的RAG

https://github.com/langchain-ai/langgraph/blob/main/examples/rag/langgraph_rag_agent_llama3_local.ipynb

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;border-left: 4px solid rgb(248, 57, 41);line-height: 1.5em;visibility: visible;">Llama3微调

https://github.com/hiyouga/LLaMA-Factory

https://colab.research.google.com/drive/135ced7oHytdxu3N2DNe1Z0kqjyYIkDXp?usp=sharing

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;border-left: 4px solid rgb(248, 57, 41);line-height: 1.5em;visibility: visible;margin-top: 16px;">基于Llama3的function calling/Agent

目前官方的说法是Llama3不支持function calling

https://huggingface.co/Trelis/Meta-Llama-3-8B-Instruct-function-calling

prompt模板:

<|begin_of_text|><|start_header_id|>function_metadata<|end_header_id|>
You have access to the following functions. Use them if required:[{"type": "function","function": {"name": "get_stock_price","description": "Get the stock price of an array of stocks","parameters": {"type": "object","properties": {"names": {"type": "array","items": {"type": "string"},"description": "An array of stocks"}},"required": ["names"]}}},{"type": "function","function": {"name": "get_big_stocks","description": "Get the names of the largest N stocks by market cap","parameters": {"type": "object","properties": {"number": {"type": "integer","description": "The number of largest stocks to get the names of, e.g. 25"},"region": {"type": "string","description": "The region to consider, can be \"US\" or \"World\"."}},"required": ["number"]}}}]<|eot_id|><|start_header_id|>user<|end_header_id|>
Get the names of the five largest stocks by market cap<|eot_id|><|start_header_id|>assistant<|end_header_id|>
Generated Response:{"name": "get_big_stocks","arguments": {"number": 5,"region": "US"}}<|eot_id|>

项目地址

https://github.com/themrzmaster/llama-cpp-python/blob/4a4b67399b9e5ee872e2b87068de75e2908d5b11/llama_cpp/llama_chat_format.py#L2866

调用示例

from openai import OpenAIclient = OpenAI(base_url="http://localhost:8000/v1", api_key="s")
response = client.chat.completions.create(model="m", messages = [{"role": "system","content": "You are a digital waiter Pay attention to the user requests and use the tools to help you."}, {"role": "user","content": "search for burguer and a maximum price of 10 dollars. at the sime time, look for merchant named 'Burger King'"}, ],tools=[{"type": "function","function": {"name": "search_merchant","description": "Search for merchants in the catalog based on the term","parameters": {"type": "object","properties": {"name": {"type": "string","description": "name to be searched for finding merchants.",}},"required": ["name"],},},},{"type": "function","function": {"name": "search_item","description": "Search for items in the catalog based on various criteria.","parameters": {"type": "object","properties": {"term": {"type": "string","description": "Term to be searched for finding items, with removed accents.",},"item_price_to": {"type": "integer","description": "Maximum price the user is willing to pay for an item, if specified.",},"merchant_delivery_fee_to": {"type": "integer","description": "Maximum delivery fee the user is willing to pay, if specified.",},"merchant_payment_types": {"type": "string","description": "Type of payment the user prefers, if specified.","enum": ["Credit Card","Debit Card","Other",],},},"required": ["term"],},},}], tool_choice="auto")

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;border-left: 4px solid rgb(248, 57, 41);line-height: 1.5em;visibility: visible;">Llama3实操技术选型推荐

https://twitter.com/9hills/status/1781757051838050630


中文RAG选择CommandR+;Agent/FunctionCalling使用Llama3-70B或CommandR+;中文文案写作用Qwen-72B;特定任务的小参数微调base模型用Llama3-8B或Mistral-7B;大参数微调base模型用Yi-34B;代码生成用Llama3-70B或deepseek-coder-33B;特定类编程(比如nl2sql),小参数llama3-8b,大参数deepzeek-coder-33b;生产环境:vLLM、TensorRT-LLM;本地环境:Ollama.









欢迎光临 链载Ai (https://www.lianzai.com/) Powered by Discuz! X3.5