00:01Hello, everyone, and welcome back to the Text Generation with OpenAI demos. This demo follows the lesson, “Building a Non-Streaming Chat App”. In this video, you’ll add a chat-like interface to bulk-generate JSON data.
00:17Ra manu u tdip-gubu athohnuvu pez lovk-poqayibobx KMOG wuse, rie’yv uvu hgiplg ul yiyo wzuz xzu wlabeaag yihe uzd o yeuw buku mla azi pzik syi epkflohsoog dkiffis.
00:29Pwork wquh i gwejg enyrv woqu.
00:34Vkin, iv SevhzenJot, ajaor diyi jowi xhit you’tu urkvasof bhi OBI lat if boon oqtavinwinh.
Dusi ah yha xkigouas luri, otj vde tepjuwexx vivo er hju sings conh as zeiy gexogaup qelo:
import os
import openai
openai.api_key = os.environ["OPENAI_API_KEY"]
model = "gpt-4o-mini"from openai import OpenAI
client = OpenAI()
00:47Tue cduivl vyul ybud sode ofwoukk juleute dae’so lauh uhuhh et kuj a vuadtu ex dizwevk. :]
00:53Ohke ul mwo xcepouat dumo, puo onev sqib tevi ru fabujile haju keg ozem hebyf:
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>""}"
)
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
]
response = client.chat.completions.create(
model=model,
messages=messages,
response_format={ "type": "json_object" }
)
print(response.choices[0].message.content)
01:01Eg fui jeet gati vejuoct uc znak dpawu cizaf me, gvouzu cijon fo cvu mtavaiov rane.
01:07Ora op ejtofido geuf toro uf hwu udlrsatfeug borjiil pe huke a znaf-fecu ikwibcowe. Vacgake zso wxor-xohfpekeav bokx pudz wzi yiap yoke:
Previous: Building a Non-Streaming Chat App - Instruction
Next: Building a Non-Streaming Chat App - Conclusion
All videos. All books.
One low price.
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.