@@ -59,6 +59,7 @@ layout: top-title-two-cols
5959columns: is-5-7
6060align: l-lt-lt
6161color: violet-light
62+ hideInToc: true
6263---
6364
6465
@@ -88,6 +89,7 @@ layout: top-title-two-cols
8889columns: is-7-5
8990align: l-lt-lt
9091color: violet-light
92+ hideInToc: true
9193---
9294
9395[ ^ ref1 ] : <div class =" ns-c-cite " ><a href =" https://arxiv.org/abs/1706.03762 " >Attention Is All You Need</a ></div >
@@ -118,6 +120,7 @@ layout: top-title-two-cols
118120columns: is-6
119121align: l-lt-lt
120122color: violet-light
123+ hideInToc: true
121124---
122125
123126
@@ -148,6 +151,7 @@ layout: top-title-two-cols
148151columns: is-8
149152align: l-lt-lt
150153color: violet-light
154+ hideInToc: true
151155---
152156
153157
@@ -175,6 +179,7 @@ layout: top-title-two-cols
175179columns: is-5
176180align: l-lt-lt
177181color: violet-light
182+ hideInToc: true
178183---
179184
180185
@@ -202,6 +207,7 @@ layout: top-title-two-cols
202207columns: is-6
203208align: l-lt-lt
204209color: violet-light
210+ hideInToc: true
205211---
206212
207213
@@ -228,6 +234,7 @@ Reasoning LLMs have been trained to imitate thought processes[^ref1]
228234layout: top-title-two-cols
229235columns: is-6
230236color: violet-light
237+ hideInToc: true
231238---
232239
233240
@@ -264,6 +271,7 @@ sequenceDiagram
264271---
265272layout: top-title
266273color: violet-light
274+ hideInToc: true
267275---
268276
269277:: title ::
@@ -329,10 +337,59 @@ curl -X POST "https://ai-gateway.apps.cloud.rt.nyu.edu/v1/chat/completions " \
329337</v-switch >
330338
331339
340+ ---
341+ layout: top-title-two-cols
342+ columns: is-6
343+ color: violet-light
344+ hideInToc: true
345+ ---
346+
347+ :: title ::
348+
349+ # Message Roles
350+
351+ :: left ::
352+
353+ Each message within the conversation thread has a ** role** associated with it.
354+
355+ Head back to the tokenizer playgrond and look for the these special tokens:
356+ <div class =" ns-c-tight " >
357+
358+ - ` system ` <br />
359+ - ` assistant ` <br />
360+ - ` user ` <br />
361+
362+ </div >
363+
364+ :: right ::
365+
366+ <SpeechBubble position =" l " color =" cyan-light " textAlign =" left " shape =" round " maxWidth =" 400px " >
367+
368+ ** system:** Affects the tone and shapes the behaviour of the assistant messages
369+
370+ </SpeechBubble >
371+ <br />
372+
373+ <SpeechBubble position =" l " color =" emerald-light " shape =" round " maxWidth =" 400px " >
374+
375+ ** user:** Messages sent by you to the LLM
376+
377+ </SpeechBubble >
378+ <br />
379+
380+ <SpeechBubble position =" r " color =" violet-light " textAlign =" right " shape =" round " maxWidth =" 400px " >
381+
382+ ** assistant:** Messages by the LLM to you
383+
384+ </SpeechBubble >
385+
386+
387+
332388---
333389layout: top-title-two-cols
334390columns: is-4
335391color: violet-light
392+ hideInToc: true
336393---
337394
338395:: title ::
@@ -378,6 +435,7 @@ Head over to app.portkey.ai and choose the "Login with SSO" option with your Net
378435layout: top-title-two-cols
379436columns: is-8
380437color: violet-light
438+ hideInToc: true
381439---
382440
383441:: title ::
@@ -402,6 +460,7 @@ Stick to user keys unless you're developing a service.
402460layout: top-title-two-cols
403461columns: is-3
404462color: violet-light
463+ hideInToc: true
405464---
406465
407466:: title ::
@@ -429,6 +488,7 @@ color: violet-light
429488layout: top-title-two-cols
430489columns: is-7
431490color: violet-light
491+ hideInToc: true
432492---
433493
434494:: title ::
@@ -454,6 +514,248 @@ color: violet-light
454514 </template >
455515</v-switch >
456516
517+ ---
518+ layout: top-title-two-cols
519+ columns: is-6
520+ color: violet-light
521+ hideInToc: true
522+ ---
523+
524+
525+ :: title ::
526+
527+ # Sending a request in Python
528+
529+ :: left ::
530+ - We will use the ` portkey-ai ` package for this using an API key created from the UI and the following ` base_url ` : ` https://ai-gateway.apps.cloud.rt.nyu.edu/v1/ ` (or to ` http://ai-gateway.jhub/v1 ` if you're using JupyterHub today).
531+
532+ <AdmonitionType type =" warning " width =" 325px " >
533+
534+ Whenever you instantiate a ` Portkey ` client, the ` base_url ` must be set. If you miss this parameter you would be connecting to the vendor's SaaS platform and NYU provisioned virtual keys will not work.
535+
536+ </AdmonitionType >
537+
538+ :: right ::
539+
540+ ``` python !children:text-xs
541+ from portkey_ai import Portkey
542+
543+ portkey = Portkey(
544+ base_url = " https://ai-gateway.apps.cloud.rt.nyu.edu/v1/" ,
545+ api_key = " ..." ,
546+ )
547+
548+ completion = portkey.chat.completions.create(
549+ model = " @vertexai/gemini-2.5-flash" ,
550+ messages = [
551+ {" role" : " system" , " content" : " You are not a helpful assistant" },
552+ {
553+ " role" : " user" ,
554+ " content" : " Complete the following sentence: \
555+ The sun is shining and the sky is" ,
556+ },
557+ ],
558+ )
559+
560+ print (completion.choices[0 ][" message" ][" content" ])
561+ ```
562+
563+
564+ ---
565+ layout: top-title-two-cols
566+ columns: is-6
567+ color: violet-light
568+ hideInToc: true
569+ ---
570+
571+ :: title ::
572+
573+ # Inconsistent response formats
574+
575+ :: left ::
576+
577+ For instance, running the prompt below with various LLMs shows us that the response format is not consistent among them.
578+
579+
580+ ``` python
581+ prompt = prompt = """
582+ Extract data from the following text:
583+
584+ <text>
585+ # Structured Data
586+ By Carson Sievert
587+ </text>
588+ """
589+ """
590+ ```
591+
592+ :: right ::
593+
594+ <SpeechBubble position="r" color="cyan-light" textAlign="left" shape="round" maxWidth="475px">
595+
596+ **gemini-2.5-flash-lite**
597+ ```json
598+ [
599+ {"data": "Structured Data", "type": "title"},
600+ {"data": "Carson Sievert", "type": "author"}
601+ ]
602+ ```
603+ </SpeechBubble>
604+ <SpeechBubble position="r" color="fuchsia-light" textAlign="left" shape="round" maxWidth="475px">
605+
606+ **gemini-3-pro-preview**
607+ ```
608+ **Title:** Structured Data
609+ **Author:** Carson Sievert
610+ ```
611+ </SpeechBubble>
612+ <SpeechBubble position="r" color="yellow-light" textAlign="left" shape="round" maxWidth="475px">
613+
614+ **gpt-5-mini**
615+ ```
616+ {
617+ "title": "Structured Data",
618+ "author": "Carson Sievert",
619+ "raw": "# Structured Data\n By Carson Sievert"
620+ }
621+ ```
622+ </SpeechBubble>
623+
624+ ---
625+ layout: top-title-two-cols
626+ columns: is-6
627+ color: violet-light
628+ hideInToc: true
629+ ---
630+ :: title ::
631+
632+ # Structured outputs
633+
634+ :: left ::
635+
636+ You can specify a response format to ease integration of LLM outputs into your workflows.
637+
638+ ```python
639+ class ArticleSpec(BaseModel):
640+ """ Information about an article written in markdown"""
641+
642+ title: str = Field(description="Article title")
643+ author: str = Field(description="Name of the author")
644+ ```
645+ and call the LLM with the response schema passed alongside the prompt:
646+ ```python
647+ completion = portkey.beta.chat.completions.parse(
648+ model="@vertexai/gemini-2.5-flash-lite",
649+ messages=[
650+ {"role": "user", "content": f"{prompt}"}
651+ ],
652+ response_format=ArticleSpec,
653+ )
654+ print(completion.choices[0].message.content)
655+ ```
656+
657+ :: right ::
658+
659+ <SpeechBubble position="r" color="cyan-light" textAlign="left" shape="round" maxWidth="400px">
660+
661+ **gemini-2.5-flash-lite**
662+ ```
663+ {
664+ "title": "Structured Data",
665+ "author": "Carson Sievert"
666+ }
667+ ```
668+ </SpeechBubble>
669+ <SpeechBubble position="r" color="fuchsia-light" textAlign="left" shape="round" maxWidth="400px">
670+
671+ **gemini-3-pro-preview**
672+ ```
673+ {
674+ "title": "Structured Data",
675+ "author": "Carson Sievert"
676+ }
677+ ```
678+ </SpeechBubble>
679+ <SpeechBubble position="r" color="yellow-light" textAlign="left" shape="round" maxWidth="400px">
680+
681+ **gpt-5-mini**
682+ ```
683+ {
684+ "title":"Structured Data",
685+ "author":"Carson Sievert"
686+ }
687+ ```
688+ </SpeechBubble>
689+
690+
691+ ---
692+ layout: top-title-two-cols
693+ columns: is-4
694+ color: violet-light
695+ hideInToc: true
696+ ---
697+ :: title ::
698+
699+ # Structured outputs
700+
701+ :: left ::
702+
703+ This does not prevent LLMs from hallucinating. For instance, you can add a date field to the schema and see what happens.
704+ ```python
705+ class ArticleSpec(BaseModel):
706+ """ Information about an article written in markdown"""
707+
708+ title: str = Field(description="Article title")
709+ author: str = Field(description="Name of the author")
710+ date: str = Field(description="Date written in YYYY-MM-DD format.")
711+
712+ prompt = prompt = """
713+ Extract data from the following text:
714+
715+ < text>
716+ # Structured Data
717+ By Carson Sievert
718+ < / text>
719+ """
720+ ```
721+
722+ The `date` field is missing in the prompt, put some LLMs hallucinate one.
723+
724+ :: right ::
725+
726+ <SpeechBubble position="r" color="cyan-light" textAlign="left" shape="round" maxWidth="400px">
727+
728+ **gemini-2.5-flash-lite**
729+ ```
730+ {
731+ "title": "Structured Data",
732+ "author": "Carson Sievert",
733+ "date": "2023-10-26"
734+ }
735+ ```
736+ </SpeechBubble>
737+ <SpeechBubble position="r" color="fuchsia-light" textAlign="left" shape="round" maxWidth="400px">
738+
739+ **gemini-3-pro-preview**
740+ ```
741+ {
742+ "title": "Structured Data",
743+ "author": "Carson Sievert",
744+ "date": "null"
745+ }
746+ ```
747+ </SpeechBubble>
748+ <SpeechBubble position="r" color="yellow-light" textAlign="left" shape="round" maxWidth="400px">
749+
750+ **gpt-5-mini**
751+ ```
752+ {
753+ "title":"Structured Data",
754+ "author":"Carson Sievert",
755+ "date":""
756+ }
757+ ```
758+ </SpeechBubble>
457759
458760
459761---
0 commit comments