فالإعلان هو اسم ووصف ومخطط معياري، والنموذج لا يعمل أي شيء: فهو يجيب بقرار، ويشغله هو لك - وهو أيضا ما يجعل من الآمن أن نفضح أشياء من الخطر أن ننقلها إلى أي شخص آخر.
إعلان واحد
{
name: "weather",
description: "Current weather for a city.",
parameters: {
city: { type: "string", description: "City name", required: true },
unit: { type: "string", enum: ["c", "f"] },
},
}{
"name": "weather",
"description": "Current weather for a city.",
"parameters": {
"city": {"type": "string", "description": "City name", "required": True},
"unit": {"type": "string", "enum": ["c", "f"]},
},
}طريقتان لكتابة الـ
الشكل القصير هو خريطة لحقول، كل منها مع required الشكل الكامل هو كائن JSON وكلاهما مقبول؛ والقصير موجود لأن كتابة مخطط بثلاثة بارامترات باليد لا يتناسب مع ذلك.
// Short
parameters: {
city: { type: "string", required: true },
unit: { type: "string", enum: ["c", "f"] },
}
// Full — reach for this when it gets complicated
parameters: {
type: "object",
properties: {
city: { type: "string" },
unit: { type: "string", enum: ["c", "f"] },
},
required: ["city"],
}# Short
parameters = {
"city": {"type": "string", "required": True},
"unit": {"type": "string", "enum": ["c", "f"]},
}
# Full — reach for this when it gets complicated
parameters = {
"type": "object",
"properties": {
"city": {"type": "string"},
"unit": {"type": "string", "enum": ["c", "f"]},
},
"required": ["city"],
}| الأنواع التي لم يُبت فيها | |
|---|---|
| عدد عدد عدد عدد عدد صحيح polean | -السلسلات |
| (م) | مع العناصر و الخصائص |
كل إعلان يدفع ثمنه كل دور
يتم إرسال الأدوات مع كل نداء، لذلك فهي جزء من المدخلات التي تمّت تأليفها - أداة النموذج لا يختارها أبداً
تضييق القائمة بما تدور حوله المحادثة هو أرخص أفضل تكبير متاح في حلقة اتصال بأداة، ويجعل النموذج يختار أفضل.
const ALL = { weather: weatherTool, invoices: invoiceTool, calendar: calendarTool };
// Pick per turn rather than declaring the catalogue
const tools = Object.entries(ALL)
.filter(([name]) => relevant(name, conversation))
.map(([, tool]) => tool);ALL = {"weather": weather_tool, "invoices": invoice_tool, "calendar": calendar_tool}
# Pick per turn rather than declaring the catalogue
tools = [tool for name, tool in ALL.items() if relevant(name, conversation)]الوصف هو التعليمات
هو الشيء الوحيد الذي يخبر النموذج متى يصل لهذا بدلاً من الإجابة مباشرة. قل ما يفعله، ما يحتاجه، ومتى غير لاستخدامه.
| ن ن | مُحسن |
|---|---|
| } يحصل على بيانات } | ‹ الطقس الحالي للمدينة - يستخدم اليوم فقط - لا يوجد أي تنبؤات. □ □ |
| } البحث عن | "يبحث في سجل منتجاتنا بالاسم وليس في سجلات العملاء. |
| ’ يرسل رسالة بريد إلكتروني ’ | □ يرسل رسالة إلكترونية، فقط بعد أن يؤكد المستخدم المتلقي والنص. □ |
جاري تحميل التوقيع
أداة نداء يمكن أن يأتي مرة أخرى signatureاعيدها بدون تغيير في المنعطف التالي أو يُرفض الدور. احفظ الرسالة المساعدة بأكملها وادفعها للخلف كما تتعامل مع هذا بدون أن تفكر فيها.
// Right: the message goes back whole
messages.push(turn.message);
// Wrong: rebuilt, and the signature is gone
messages.push({ role: "assistant", content: turn.message.content,
toolCalls: turn.message.toolCalls.map(({ id, name, args }) => ({ id, name, args })) });# Right: the message goes back whole
messages.append(turn["message"])
# Wrong: rebuilt, and the signature is gone
messages.append({"role": "assistant", "content": turn["message"]["content"],
"toolCalls": [{"id": c["id"], "name": c["name"], "args": c["args"]}
for c in turn["message"]["toolCalls"]]})عدة نداءات في كل مرة
منعطف يمكن أن يطلب أكثر من أداة واحدة دفعة واحدة. tool . . . .
const results = await Promise.all(
turn.message.toolCalls.map((call) => run(call.name, call.args).catch((e) => `Error: ${e.message}`)),
);
turn.message.toolCalls.forEach((call, i) => {
messages.push({ role: "tool", toolCallId: call.id, name: call.name, content: String(results[i]) });
});from concurrent.futures import ThreadPoolExecutor
def safe_run(call):
try:
return run(call["name"], call["args"])
except Exception as error:
return f"Error: {error}"
calls = turn["message"]["toolCalls"]
with ThreadPoolExecutor() as pool:
results = list(pool.map(safe_run, calls))
for call, result in zip(calls, results):
messages.append({"role": "tool", "toolCallId": call["id"], "name": call["name"], "content": str(result)})النموذج يختار، لا يصرح. أي شيء يرسل أو ينشر أو يحذف أو ينفق يجب أن يمرر شيكاً من تلقاء نفسه قبل تشغيله -- فئات أذون المحرك هي طريقة واحدة للتفكير في أي منها.
الأخطاء
| الرمز | الحالة | متى |
|---|---|---|
| invalid_tools | 400 | كانت الأدوات موجودة ولكن لم تكن مصفوفة. |
| turn_failed | 502 | ورفض مقدم الإعلان الإعلانات - وعادة ما يكون ذلك مخططا لا يمكن أن يقبله. |
حافظ على chemas programmarmary chemas Sil. عن كل دوران، ليس فقط ذلك الواحد أداة.