ХабрПостыНовостиМегапосты?

Apple выпустила руководство по промптингу локальных моделей из Foundation Models

Apple обновила документацию по работе с Foundation Models и добавила страницу с руководством по промптингу локальных языковых моделей. В документе подчёркивают, что правила немного отличаются от принципов промптинга облачных моделей из-за ограниченных ресурсов устройств.

Foundation Models — фреймворк от Apple, который позволяет разработчикам использовать в проектах локальные языковые модели. Благодаря этому можно реализовывать несложные нейросетевые функции с офлайн-доступом.

Чтобы локальные модели лучше следовали запросам, инженеры Apple рекомендуют соблюдать следующие рекомендации:

Запросы с несколькими условиями инженеры Apple рекомендуют разделять с помощью управляющих конструкций. Это поможет модели не отвлекаться на условия, которые неприменимы в конкретной ситуации. 

Например, следующий запрос в проекте:

let instructions = """
    You are a friendly innkeeper. Generate a greeting to a new guest that walks in the door.
    IF the guest is a sorcerer, comment on their magical appearance.
    IF the guest is a bard, ask if they're willing to play music for the inn tonight.
    IF the guest is a soldier, ask if there’s been any dangerous activity in the area.
    There is one single and one double room available.
    """

Можно разделить с помощью конструкции switch-case:

var customGreeting = ""
switch role {
case .bard:
    customGreeting = """
        This guest is a bard. Ask if they’re willing to play music for the inn tonight.
        """
case .soldier:
    customGreeting = """
        This guest is a soldier. Ask if there’s been any dangerous activity in the area.
        """
case .sorcerer:
    customGreeting = """
        This guest is a sorcerer. Comment on their magical appearance.
        """
default:
    customGreeting = "This guest is a weary traveler."
}


let instructions = """
    You are a friendly inn keeper. Generate a greeting to a new guest that walks in the door.
    \(customGreeting)
    There is one single and one double room available.
    """

Если нужен особый формат ответа, то его лучше явно указать. Можно перечислить несколько возможных вариантов, например, так:

// Instructions that contain JSON key-value pairs that represent the structure
// of a customer. The structure tells the model that each customer must have
// a `name`, `imageDescription`, and `coffeeOrder` fields.
let instructions = """
    Create an NPC customer with a fun personality suitable for the dream realm. \
    Have the customer order coffee. Here are some examples to inspire you:

    {name: "Thimblefoot", imageDescription: "A horse with a rainbow mane", \
    coffeeOrder: "I would like a coffee that's refreshing and sweet, like the grass in a summer meadow."}
    {name: "Spiderkid", imageDescription: "A furry spider with a cool baseball cap", \
    coffeeOrder: "An iced coffee please, that's as spooky as I am!"}
    {name: "Wise Fairy", imageDescription: "A blue, glowing fairy that radiates wisdom and sparkles", \
    coffeeOrder: "Something simple and plant-based, please. A beverage that restores my wise energy."}
    """
@daniilshat
23.01.2026 03:08 UTC
Первоисточник

Комментарии

@achekalin
23.01.2026 04:48 UTC
0

Странно, что дока только сейчас добавлена.

Мне вот все интересно: а обновление моделей как-то планировалось? Сегодня почти через день представляют все более продуманные модели, а тут речь про что-то "встроенное"...

@weerf
23.01.2026 06:36 UTC
0

Наконец-то пошли толковые советы.

А то как не откроешь книгу - а там пол релевантного ответа и дальше та же джинса больших американских ии.