Documentation

Conditions

Inside a preprompt, similar to software programming, you can use if conditions andswitch conditionals.

Conditions


Example:

Tell a joke.
@if (engine.code = ChatGPT)
Speak as robot.
@else
Speak as human.
@endif

As the result, depending on the provider selected at the portal, final preprompt will differ.

Overview of what you can write in the @if () condition is provided below.


Note: the case and excessive Space characters have no significance.


System fields

  • engine.code – provider code (ChatGPT, ThirdParty ThirdParty – "third party". A third-party code can be used here, developed by various partner companies. );
  • engine.category – can have values "text" or "image". However, currently CoPilot preprompts work for texts only;
  • context.module – module that calls CoPilot. For example, you can supplement the preprompt with details if the query is sent from CRM module.

Example of a condition for system field was provided at the page start. Here's another example:

@if (engine.code = ChatGPT)
Do not forget, that you are ChatGPT
@endif

Null check

@if (author.name = null)
speak as anonymous
@endif

Negation

@if (engine.code != ChatGPT)
{context_messages}
@endif

Handling the basic markers

These are basic markers, as well as markers preset by developer. Because the fact that they contain user content, the user ta в силу того, что в них содержится пользовательский контент, использовать их имеет смысл только для проверки на непустоту.

@if (marker.original_message != null)
compliment for {original_message}
@else
compliment for {user_message}
@endif

On the other hand, for the marker check you can use a system preset marker that is always defined by the developer upon specific conditions.

@if (marker.role = vip)
write as if you are very important
@endif

Handling the markers for result

Result marker details can be found in the markers documentation.

How to apply markers in conditions? Based on the adopted logic, you can use them only in hull check tasks. For example:

@if (current_result0 != null)
This is not the first user clarification, be more attentive please!
@endif

Important! You can check the marker availability for your logic only. The entry as follows:

@if (current_result0 != null)
{current_result0}
@endif

makes no sense, because with empty marker, it will be removed from text automatically.

Branching


This is switch, well-known in software programming. It will be helpful when you have various prompt blocks, but each is executed strictly in a specific sequence. A good example, when you have various prompt texts for different providers. See the example below.

@switch (engine.code)
@case(ChatGPT)
**instruction for GPT**
@case(ChatGPT)
**instruction for ChatGPT**
@default
**instruction for the rest of providers**
@endswitch

What can be inserted into 'switch'? The same as for 'if'.

Branching condition has the highest priority. This means that 'if' conditions can also be contained inside case-blocks. There can be several switch blocks, although it will reduce readability.

Example of combined use of 'switch' and 'if':

@switch (engine.code)
@case(ChatGPT)
you're a porky 
@if(author.personalgender = m) pink color @else blue color @endif
@case(ChatGPT)
you're a bear
@default
you're a wolf
@endswitch

@switch (engine.code)
@case(ChatGPT)
from Pluto
@case(ChatGPT)
from Jupiter
@default
@if(author.personalgender = m) from Mars @else from Venus @endif
@endswitch


© «Bitrix24», 2001-2024
Up