| POST | /v1/decisions |
|---|
<?php namespace dtos;
use DateTime;
use Exception;
use DateInterval;
use JsonSerializable;
use ServiceStack\{IReturn,IReturnVoid,IGet,IPost,IPut,IDelete,IPatch,IMeta,IHasSessionId,IHasBearerToken,IHasVersion};
use ServiceStack\{ICrud,ICreateDb,IUpdateDb,IPatchDb,IDeleteDb,ISaveDb,AuditBase,QueryDb,QueryDb2,QueryData,QueryData2,QueryResponse};
use ServiceStack\{ResponseStatus,ResponseError,EmptyResponse,IdResponse,ArrayList,KeyValuePair2,StringResponse,StringsResponse,Tuple2,Tuple3,ByteArray};
use ServiceStack\{JsonConverters,Returns,TypeContext};
// @DataContract
class DecisionAnswer implements JsonSerializable
{
public function __construct(
// @DataMember(Name="type")
/** @var string */
public string $type='',
/** @description noul: probability from 0 (no) to 1 (yes) */
// @DataMember(Name="noul")
/** @var float|null */
public ?float $noul=null,
/** @description choice: the selected option */
// @DataMember(Name="choice")
/** @var string|null */
public ?string $choice=null,
/** @description score: position on the scale, 0 = first description */
// @DataMember(Name="score")
/** @var float|null */
public ?float $score=null,
// @DataMember(Name="confidence")
/** @var float|null */
public ?float $confidence=null,
/** @description choice/score: probability of each option (score options are "0", "1", ...) */
// @DataMember(Name="probabilities")
/** @var array<string,float>|null */
public ?array $probabilities=null,
/** @description score: description of each scale position */
// @DataMember(Name="legend")
/** @var array<string,string>|null */
public ?array $legend=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['type'])) $this->type = $o['type'];
if (isset($o['noul'])) $this->noul = $o['noul'];
if (isset($o['choice'])) $this->choice = $o['choice'];
if (isset($o['score'])) $this->score = $o['score'];
if (isset($o['confidence'])) $this->confidence = $o['confidence'];
if (isset($o['probabilities'])) $this->probabilities = JsonConverters::from(JsonConverters::context('Dictionary',genericArgs:['string','float']), $o['probabilities']);
if (isset($o['legend'])) $this->legend = JsonConverters::from(JsonConverters::context('Dictionary',genericArgs:['string','string']), $o['legend']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->type)) $o['type'] = $this->type;
if (isset($this->noul)) $o['noul'] = $this->noul;
if (isset($this->choice)) $o['choice'] = $this->choice;
if (isset($this->score)) $o['score'] = $this->score;
if (isset($this->confidence)) $o['confidence'] = $this->confidence;
if (isset($this->probabilities)) $o['probabilities'] = JsonConverters::to(JsonConverters::context('Dictionary',genericArgs:['string','float']), $this->probabilities);
if (isset($this->legend)) $o['legend'] = JsonConverters::to(JsonConverters::context('Dictionary',genericArgs:['string','string']), $this->legend);
return empty($o) ? new class(){} : $o;
}
}
// @DataContract
class DecisionUsage implements JsonSerializable
{
public function __construct(
// @DataMember(Name="input_tokens")
/** @var int */
public int $input_tokens=0,
// @DataMember(Name="output_tokens")
/** @var int */
public int $output_tokens=0,
// @DataMember(Name="cost")
/** @var float|null */
public ?float $cost=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['input_tokens'])) $this->input_tokens = $o['input_tokens'];
if (isset($o['output_tokens'])) $this->output_tokens = $o['output_tokens'];
if (isset($o['cost'])) $this->cost = $o['cost'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->input_tokens)) $o['input_tokens'] = $this->input_tokens;
if (isset($this->output_tokens)) $o['output_tokens'] = $this->output_tokens;
if (isset($this->cost)) $o['cost'] = $this->cost;
return empty($o) ? new class(){} : $o;
}
}
// @DataContract
class DecisionResponse implements JsonSerializable
{
public function __construct(
// @DataMember(Name="id")
/** @var string|null */
public ?string $id=null,
// @DataMember(Name="model")
/** @var string */
public string $model='',
// @DataMember(Name="provider")
/** @var string|null */
public ?string $provider=null,
/** @description Answers by question name, validated against the submitted questions */
// @DataMember(Name="answers")
/** @var array<string,DecisionAnswer>|null */
public ?array $answers=null,
// @DataMember(Name="usage")
/** @var DecisionUsage|null */
public ?DecisionUsage $usage=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['id'])) $this->id = $o['id'];
if (isset($o['model'])) $this->model = $o['model'];
if (isset($o['provider'])) $this->provider = $o['provider'];
if (isset($o['answers'])) $this->answers = JsonConverters::from(JsonConverters::context('Dictionary',genericArgs:['string','DecisionAnswer']), $o['answers']);
if (isset($o['usage'])) $this->usage = JsonConverters::from('DecisionUsage', $o['usage']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->id)) $o['id'] = $this->id;
if (isset($this->model)) $o['model'] = $this->model;
if (isset($this->provider)) $o['provider'] = $this->provider;
if (isset($this->answers)) $o['answers'] = JsonConverters::to(JsonConverters::context('Dictionary',genericArgs:['string','DecisionAnswer']), $this->answers);
if (isset($this->usage)) $o['usage'] = JsonConverters::to('DecisionUsage', $this->usage);
return empty($o) ? new class(){} : $o;
}
}
// @DataContract
class DecisionQuestion implements JsonSerializable
{
public function __construct(
/** @description noul, choice or score */
// @DataMember(Name="type")
/** @var string */
public string $type='',
/** @description What to decide: text, or a JSON object/array of guidance */
// @DataMember(Name="instructions")
/** @var Object|null */
public ?Object $instructions=null,
/** @description noul: {true,false} descriptions; choice: {option: description}; score: ordered descriptions */
// @DataMember(Name="criteria")
/** @var Object|null */
public ?Object $criteria=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['type'])) $this->type = $o['type'];
if (isset($o['instructions'])) $this->instructions = JsonConverters::from('Object', $o['instructions']);
if (isset($o['criteria'])) $this->criteria = JsonConverters::from('Object', $o['criteria']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->type)) $o['type'] = $this->type;
if (isset($this->instructions)) $o['instructions'] = JsonConverters::to('Object', $this->instructions);
if (isset($this->criteria)) $o['criteria'] = JsonConverters::to('Object', $this->criteria);
return empty($o) ? new class(){} : $o;
}
}
/** @description Decisions API (OpenRouter) */
// @DataContract
class CreateDecision implements IPost, JsonSerializable
{
public function __construct(
/** @description The decision model, e.g. ~typesafe/jev-latest */
// @DataMember(Name="model")
/** @var string */
public string $model='',
/** @description The content to evaluate: a plain string, or a JSON object or array of related context */
// @DataMember(Name="state")
/** @var Object|null */
public ?Object $state=null,
/** @description Named noul (yes/no probability), choice (one option) or score (ordered scale) questions */
// @DataMember(Name="questions")
/** @var array<string,DecisionQuestion>|null */
public ?array $questions=null,
/** @description A unique identifier for grouping related requests */
// @DataMember(Name="session_id")
/** @var string|null */
public ?string $session_id=null,
/** @description End-user identifier sent to OpenRouter. Omitted unless you set it. */
// @DataMember(Name="user")
/** @var string|null */
public ?string $user=null,
/** @description OpenRouter provider routing preferences */
// @DataMember(Name="provider")
/** @var array<string,Object>|null */
public ?array $provider=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['model'])) $this->model = $o['model'];
if (isset($o['state'])) $this->state = JsonConverters::from('Object', $o['state']);
if (isset($o['questions'])) $this->questions = JsonConverters::from(JsonConverters::context('Dictionary',genericArgs:['string','DecisionQuestion']), $o['questions']);
if (isset($o['session_id'])) $this->session_id = $o['session_id'];
if (isset($o['user'])) $this->user = $o['user'];
if (isset($o['provider'])) $this->provider = JsonConverters::from(JsonConverters::context('Dictionary',genericArgs:['string','Object']), $o['provider']);
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->model)) $o['model'] = $this->model;
if (isset($this->state)) $o['state'] = JsonConverters::to('Object', $this->state);
if (isset($this->questions)) $o['questions'] = JsonConverters::to(JsonConverters::context('Dictionary',genericArgs:['string','DecisionQuestion']), $this->questions);
if (isset($this->session_id)) $o['session_id'] = $this->session_id;
if (isset($this->user)) $o['user'] = $this->user;
if (isset($this->provider)) $o['provider'] = JsonConverters::to(JsonConverters::context('Dictionary',genericArgs:['string','Object']), $this->provider);
return empty($o) ? new class(){} : $o;
}
}
To override the Content-type in your clients, use the HTTP Accept Header, append the .xml suffix or ?format=xml
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /v1/decisions HTTP/1.1
Host: vue-spa.web-templates.io
Accept: application/xml
Content-Type: application/xml
Content-Length: length
<CreateDecision xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/ServiceStack.AI">
<model>String</model>
<provider xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d2p1:KeyValueOfstringanyType>
<d2p1:Key>String</d2p1:Key>
<d2p1:Value />
</d2p1:KeyValueOfstringanyType>
</provider>
<questions xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d2p1:KeyValueOfstringDecisionQuestionPZTEmqZr>
<d2p1:Key>String</d2p1:Key>
<d2p1:Value>
<criteria />
<instructions />
<type>String</type>
</d2p1:Value>
</d2p1:KeyValueOfstringDecisionQuestionPZTEmqZr>
</questions>
<session_id>String</session_id>
<state />
<user>String</user>
</CreateDecision>
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: length
<DecisionResponse xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/ServiceStack.AI">
<answers xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d2p1:KeyValueOfstringDecisionAnswerPZTEmqZr>
<d2p1:Key>String</d2p1:Key>
<d2p1:Value>
<choice>String</choice>
<confidence>0</confidence>
<legend>
<d2p1:KeyValueOfstringstring>
<d2p1:Key>String</d2p1:Key>
<d2p1:Value>String</d2p1:Value>
</d2p1:KeyValueOfstringstring>
</legend>
<noul>0</noul>
<probabilities>
<d2p1:KeyValueOfstringdouble>
<d2p1:Key>String</d2p1:Key>
<d2p1:Value>0</d2p1:Value>
</d2p1:KeyValueOfstringdouble>
</probabilities>
<score>0</score>
<type>String</type>
</d2p1:Value>
</d2p1:KeyValueOfstringDecisionAnswerPZTEmqZr>
</answers>
<id>String</id>
<model>String</model>
<provider>String</provider>
<usage>
<cost>0</cost>
<input_tokens>0</input_tokens>
<output_tokens>0</output_tokens>
</usage>
</DecisionResponse>