Package: jinaai
JinaAI Python SDKThe JinaAI Python SDK is an efficient instrument that smoothly brings the power of JinaAI's products —SceneXplain,PromptPerfect,Rationale,BestBanner, andJinaChat— into Python applications. Acting as a sturdy interface for JinaAI's APIs, this SDK lets you effortlessly formulate and fine-tune prompts, thus streamlining application development.InstallingPackage managerUsing pip:$pipinstalljinaaiAPI secretsTo generate an API secret, you need to authenticate on each respective platform's API tab:SceneXplain APIPromptPerfect APIRationale APIJinaChat APIBestBanner APINote:Each secret is product-specific and cannot be interchanged. If you're planning to use multiple products, you'll need to generate a separate secret for each.Example usageImport the SDK and instantiate a new client with your authentication secrets:fromjinaaiimportJinaAIjinaai=JinaAI(secrets={'promptperfect-secret':'XXXXXX','scenex-secret':'XXXXXX','rationale-secret':'XXXXXX','jinachat-secret':'XXXXXX','bestbanner-secret':'XXXXXX',})Describe images:descriptions=jinaai.describe('https://picsum.photos/200')Evaluate situations:decisions=jinaai.decide('Going to Paris this summer',{'analysis':'proscons'})Optimize prompts:prompts=jinaai.optimize('Write an Hello World function in Python')Generate complex answers:output=jinaai.generate('Give me a recipe for a pizza with pineapple')Create images from text:output=jinaai.imagine('A controversial fusion of sweet pineapple and savory pizza.')Use APIs together:situations=[toBase64(img)forimgin['factory-1.png','factory-2.png','factory-3.png','factory-4.png',]]descriptions=jinaai.describe(situations)prompt1=['Do any of those situations present a danger?','Reply with [YES] or [NO] and explain why',*['SITUATION:\n'+desc['output']fori,descinenumerate(descriptions['results'])]]analysis=jinaai.generate('\n'.join(prompt1))prompt2=['What should be done first to make those situations safer?','I only want the most urgent situation',*['SITUATION:\n'+desc['output']fori,descinenumerate(descriptions['results'])]]recommendation=jinaai.generate('\n'.join(propmt2))swot=jinaai.decide(recommendation['output'],{'analysis':'swot'})banners=jinaai.imagine(*[desc['output']fori,descinenumerate(descriptions['results'])])Raw OutputYou can retrieve the raw output of each APIs by passingraw: Truein the options:descriptions=jinaai.describe('https://picsum.photos/200',{'raw':True})print(descriptions['raw'])Custom Base UrlsCustom base Urls can be passed directly in the client's constructor:jinaai=JinaAI(baseUrls={'promptperfect':'https://promptperfect-customurl.jina.ai','scenex':'https://scenex-customurl.jina.ai','rationale':'https://rationale-customurl.jina.ai','jinachat':'https://jinachat-customurl.jina.ai','bestbanner':'https://bestbanner-customurl.jina.ai',})API DocumentationJinaAi.describeoutput=JinaAI.describe(input,options)InputVARIABLETYPEVALUEinputstr / str arrayImage URL or Base64OptionsVARIABLETYPEVALUEoptionsdictoptions['algorithm']None / strAqua / Bolt / Comet / Dune / Ember / Flash / Glide / Hearth / Inception / Jellyoptions['features']None / str arrayhigh_quality, question_answer, tts, opt-out, jsonoptions['languages']None / str arrayen, cn, de, fr, it...options['question']None / strQuestion related to the picture(s)options['style']None / strdefault / concise / promptoptions['output_length']None / numberoptions['json_schema']None / dictoptions['callback_url']None / stringOutputVARIABLETYPEVALUEoutputdictoutput['results']dict arrayresults[0]['output']strThe picture descriptionresults[0]['i18n']dictContains one key for each item in languages...i18n['cn']strThe translated picture description...i18n['cn']dict arrayOnly for Hearth algorithm...i18n['cn'][0]dict...i18n['cn'][0]['message']str...i18n['cn'][0]['isNarrator']boolean...i18n['cn'][0]['name']str...i18n['cn']dict arrayOnly for Inception algorithm...i18n['cn'][0]dict...i18n['cn'][0]['summary']str...i18n['cn'][0]['events']dict array...['events']['description']str...['events']['timestamp']strresults[0]['tts']dictOnly for Hearth algorithm...tts['cn']strContains the url to the tts fileresults[0]['ssml']dictOnly for Hearth algorithm...ssml['cn']strContains the url to the ssml fileJinaAi.optimizeoutput=JinaAI.optimize(input,options)InputVARIABLETYPEVALUEinputstr / str arrayImage URL or Base64 / prompt to optimizeOptionsVARIABLETYPEVALUEoptionsdictoptions['targetModel']None / strchatgpt / gpt-4 / stablelm-tuned-alpha-7b / claude / cogenerate / text-davinci-003 / dalle / sd / midjourney / kandinsky / lexicaoptions['features']None / str arraypreview, no_spam, shorten, bypass_ethics, same_language, always_en, high_quality, redo_original_image, variable_subs, template_runoptions['iterations']None / numberDefault: 1options['previewSettings']None / dictContains the settings for the preview...previewSettings['temperature']numberExample: 0.9...previewSettings['topP']numberExample: 0.9...previewSettings['topK']numberExample: 0...previewSettings['frequencyPenalty']numberExample: 0...previewSettings['presencePenalty']numberExample: 0options['previewVariables']None / dictContains one key for each variables in the prompt...previewVariables['var1']strThe value of the variableoptions['timeout']NumberDefault: 20000options['target_language']None / stren / cn / de / fr / it...OutputVARIABLETYPEVALUEoutputdictoutput['results']dict arrayresults[0]['output']strThe optimized promptJinaAi.decideoutput=JinaAI.decide(input,options)InputVARIABLETYPEVALUEinputstr / str arrayDecision to evaluateOptionsVARIABLETYPEVALUEoptionsdictoptions['analysis']None / strproscons / swot / multichoice / outcomesoptions['style']None / strconcise / professional / humor / sarcastic / childish / genZoptions['profileId']None / strThe id of the Personas you want to useOutputVARIABLETYPEVALUEoutputdictoutput['results']dict arrayresults[0]['proscons']None / dict...proscons['pros']dictContains one key for each pros...proscons['pros']['pros1']strThe explanation of the pros...proscons['cons']dictContains one key for each cons...proscons['cons']['cons1']strThe explanation of the cons...proscons['bestChoice']str...proscons['conclusion']str...proscons['confidenceScore']numberresults[0]['swot']None / dict...swot['strengths']dictContains one key for each strength...swot['strengths']['str1']strThe explanation of the strength...swot['weaknesses']dictContains one key for each weakness...swot['weaknesses']['weak1']strThe explanation of the weakness...swot['opportunities']dictContains one key for each opportunity...swot['opportunities']['opp1']strThe explanation of the opportunity...swot['threats']dictContains one key for each threat...swot['threats']['thre1']strThe explanation of the threat...swot['bestChoice']str...swot['conclusion']str...swot['confidenceScore']numberresults[0]['multichoice']None / dictContains one key for each choice...multichoice['choice1']strThe value of the choiceresults[0]['outcomes']None / dict array...outcomes[0]['children']None / dict arraya recursive array of results['outcomes']...outcomes[0]['label']str...outcomes[0]['sentiment']strJinaAi.generateoutput=JinaAI.generate(input,options)InputVARIABLETYPEVALUEinputstr / str arrayImage URL or Base64 / promptOptionsVARIABLETYPEVALUEoptionsdictoptions['role']None / struser / assistantoptions['name']None / strThe name of the author of this messageoptions['chatId']None / strThe id of the conversation to continueoptions['stream']None / booleanWhether to stream back partial progress, Default: falseoptions['temperature']None / numberDefault: 1options['top_p']None / strDefault: 1options['stop']None / str / str arrayUp to 4 sequences where the API will stop generating further tokensoptions['max_tokens']None / numberDefault: infiniteoptions['presence_penalty']None / numberNumber between -2.0 and 2.0, Default: 0options['frequency_penalty']None / numberNumber between -2.0 and 2.0, Default: 0options['logit_bias']None / dictThe likelihood for a token to appear in the completion...logit_bias['tokenId']numberBias value from -100 to 100options['image']strThe attached image of the message. The image can be either a URL or a base64-encoded stringOutputVARIABLETYPEVALUEoutputdictoutput['output']strThe generated answeroutput['chatId']strThe chatId to continue the conversationJinaAi.imagineoutput=JinaAI.imagine(input,options)InputVARIABLETYPEVALUEinputstr / str arrayPromptOptionsVARIABLETYPEVALUEoptionsdictoptions['style']None / strdefault / photographic / minimalist / flatOutputVARIABLETYPEVALUEoutputdictoutput['results']dict arrayresults[0]['output']arrayarray of 4 image urlsJinaAi.utilsoutout=JinaAI.utils.image_to_base64(input)VARIABLETYPEVALUEinputstrImage path on diskoutputstrBase64 imageoutout=JinaAI.utils.is_url(input)VARIABLETYPEVALUEinputstroutputbooleanoutout=JinaAI.utils.is_base64(input)VARIABLETYPEVALUEinputstroutputboolean