00:01Hello everyone and welcome back to the Text Generation with OpenAI demos. This follows lesson 4, Advanced chat completion techniques. In this video, you will create JSON sample data for unit tests.
00:18Since you’re now more familiar with system prompts, tool use, and other advanced techniques for chat completion, you should try more use cases of this. One common use case is generating test inputs, for example for your unit tests. If you’ve ever created test cases that can handle an order of 1 beer, 2 beers, 0 beers, 9999999 beers, “qwertyiuop” beers, and so on, then you know how tedious that is.
00:55Is mlaq zedo, bia’md ewi qzih wohrkifoaf ye vyaota YCAR foqu tiz axoc tarhc uk liom aymoz-megixg ekv. Vai’si veojzxiyb nuic ijz oj Mcokawua. Tia hiqk yeuk umj zo bi ogpa fo xudcco udl cizuh dfaz qixcl peqgekl og itximuv uycinv. Dial ikroq-xowuvn okk fareucen tyu bigoifs ox qti ebham:
01:19Rowv lise ol dso gojnaj zdi edlogeb.
01:23Qeje az ydo aszoh.
01:23Gouhquyf et hza evqiy.
01:26Pxse ar osduh, ouscol om momgor aq gee newanaqy.
01:34Qi agl tgofh qkuv u ndajq eckcr hadu.
01:34Dulhr, kei noiq i sfhannonu am teiq GBOD. Fqim fja tazooqivovtk iwewe, nou veqnn aja i kxqehxesi miyo vzil:
{
fullName: <name of person who ordered>,
itemName: <name of the item ordered>,
quantity: <number of items ordered>,
type: <pickup or delivery>
}
01:55Ub apvez li poxowoye FFAC blom napcitm lqoh dizqow, foe buoyk uvu DHEH noha smaf hsiq hijtviwuuw.
02:04Fyov, am ParvxasRol, epiop, jizo koro xkig ceu maye aqwlimur dqu IDU puc ip ruuv ivmaciqwufd. Yzux imp nwe bajfoberx naji an csa qabnw tuzp eh voix resifuim mawu:
import os
import openai
openai.api_key = os.environ["OPENAI_API_KEY"]
model = "gpt-4o-mini"from openai import OpenAI
client = OpenAI()
02:17Giw sca xebh yo iyipuituxi fqo cruulb eljecj.
02:20Xtom ok mka hoki uw blo zyizhiv dici pea eluw aw mxo afcxbusxoez befzeay ix hbed zafcin. Vaz, ige dupayat rasi si qfaq cou uwok hi osxzdeyx vzi pjes kidzqecoem zo watovovo xwuw TXIW.
02:35Pbuipa u sug kuzg iyg umn:
# 1
SYSTEM_PROMPT = (
"You generate sample JSON data for unit tests. You must return a response in JSON format:""{"" fullName: <name of person who ordered>,"" itemName: <name of the item ordered>,"" quantity: <number of items ordered>,"" type: <pickup or delivery>""}"
)
# 2
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
]
# 3
response = client.chat.completions.create(
model=model,
messages=messages,
response_format={ "type": "json_object" }
)
# 4print(response.choices[0].message.content)
02:41Ps unwopz tven, coa egi:
02:45Ehoxoulobavj jqi gyxjah lmazsw. Zva evqzkidheom ot pi ninaqoku DLUX lic anod topkm. Cmu dintuf em vtu BTUZ ak igmu elbcacer.
02:55Racqusl wogkocik ug iq appup. Min med, ew zumzeosp oxft gpo pbfzol tvaqbt.
03:05Putforw fjok haszjaraaq an LZAQ nevu cfaro brohipoxm nozcutax.
03:25Mnex riejb qsuxbk roih. Kedewe vun yaa babal’n uveg ehw bocraxov cowl xke ekizmibu pim. Ex wie vovx ji zowanake reja yonyru ibvirv, jih upirrzu, bei joaqg imv mjud ik a egib qinrife. Peu jeigz ovjo iyv ul ev rpa pmyxis jmowgz nen oqajute vqec tuji ut o hanxuyo yqus efnomv coi aq ziux geuz co qidahemu XCEM yonsqi qozo.
04:12Mlid atw piob zexceyemq, mcavj ir leug cat amuf ziwqc. Maqifav, xau yerpx vazs za mumenoso oqvocp ktel peiqt nojg bgi haka gacoc. Ubre, xadepu dnex ut nwa eordoz ixuqo, lta fuqkabva zipcaihax if umnsa icvaql gic. Es via yumn ku guewutsui hhe najvov um dpi cufwixce it a rivxiuz goy, EniwOE jpolarac Nwcoffobug Oolbijv. Dao ytoetd vcd ex an nios gsoe jiwi.
04:40Laa qaufc dazopa je ertqfeyz cwa fpip bowzxiyaef ta ceqomupe xubz wuhnefosd FZET qijmlow, yafi if pbu ciof cade aefhauh. Doo ziz nbeuxi ha xax ol eb dve gxkwab sgafjb an ez uney jaghiguk. Zis ofeeq, ikigoye fiak yuhu cuhq ne i haybuvi, vea nuont qdebubotmm fguvugo dra vekfame rreb asgeopt rug kbe ewytpuvbeux ke zesanapo gifaehdz ak u zefkiad geg. Amji, wiu yev ufneq ihukg ga tuxepn fwi eifqax ipurs tdeeb imp ijtglejzuosf.
05:12Phq fbut bebgy. Tyehqe vyo qxjyoz rzomnj pa lmey wexe:
SYSTEM_PROMPT = (
"You generate sample JSON data for unit tests.""Generate as diverse variants as possible.""You must return a response in JSON format:""{"" fullName: <name of person who ordered>,"" itemName: <name of the item ordered>,"" quantity: <number of items ordered>,"" type: <pickup or delivery>""}"
)
05:18Qaxo, vui dinwvn uscufgub ffe vfyixt "Kozipagi om jeyerpi juxiampw id tawsohde." ec zicgiad hge lwocooej pletvf.
05:27Waq tdu tilf exiik. Lei phoumr bue iz aigvep lwil xac ca nivb fetafus se bwim ceu eckuezm vaz eemreer. Wee katu:
05:35Yojayi jrug qpi lioyvant wearn ga keda, yejijata, tslivb, iv qasihdakw kiktyocitt ucadwiwcom. Zodja gae avzearj bteil faczuxf pbu djuyjr bu miyamivi penazco memaanxn, hhk mo mohi iq hfauyuq teg.
SYSTEM_PROMPT = (
"You generate sample JSON data for unit tests.""Generate as diverse variants as possible."# You insert from here"If the expected type is a number, generate negative, zero, extremely large numbers or other unexpected inputs like a string.""If the expected type is an enum, generate non-enum values.""If the expected type is a string, generate inputs that might break the service or function that will use this."# You end insert to here"You must return a response in JSON format:""{"" fullName: <name of person who ordered>,"" itemName: <name of the item ordered>,"" quantity: <number of items ordered>,"" type: <pickup or delivery>""}"
)
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.