Package: aibridge-test
AIBridge 0.0.1AIBridge is the python package with the support of the Multiple LLM's,User can utilised the Formatters ,prompts, varibales to get most of the LLM's Through the AIBridgeRequirementPython 3Install The Test packagepipinstallaibridge-testSet aibridge_config.yamlSetting the the aibridge_config.yaml at your desire choiceIn .env file set the path for file.Exampleinbashweset:exportAIBRIDGE_CONFIG=C:/Users/Admin/aibridge/aibridge_config.yamlvariablenameforenv:AIBRIDGE_CONFIGstarterfile.&id001data:*id001group_name:my_consumer_groupmessage_queue:redisno_of_threads:1open_ai:-key:APIKEYHEREpriority:equalpalm_api:-key:APIKEYHEREpriority:equalstable_diffusion:-key:APIKEYHEREpriority:equalredis_host:localhostredis_port:LoacalHoststream_name:my_streamdatabase:nosqldatabase_name:aibridgedatabase_uri:mongodb://localhost:27017per_page:10ConfigurationWith the help of the AIBridge we can svae the prompts in your sql/nosql data bases by default the :sqllite on the disc spaceTo configure the database you have add the data in config file.fromAIBridgeimpprtSetconfig#call the config methodSetconfig.set_db_confonfig(database=sql,database_name=None,database_uri=None)#parameters:#database-sql/nosql#database_uri: url of the databse of your choice(all sql support for no sql(Mongo))If you want use the sqllite on the disc no need to configure these for db supportCurrently AI bridge support only the OPEN_AI api:fromAIBridgeimportSetConfigSetConfig.set_api_key(ai_service="open_ai",key="YOUR_API_KEY",priority="high")#priority:high/medium/low/equalPrompt savePrompt save mechanism is used the save the reusable and extraordinary prompts that give you the exceptional result from LLMfromAIBridgeimportPromptInsertion# save promptdata=PromptInsertion.save_prompt(prompt="your prompt:{{data}},context:{{context}}",name="first_prompt",prompt_data={"data":"what is purpose of the ozone here"},variables={"context":"environment_context"},)print(data)# parameters: prompt_data: is used to manipulatre the same prompt  with diffrent context at realtime# variables: is used to manipulate the prompt with fixed context as varibales is a specific data#update prompt can see the prompt_data and variables, is used the get diffrent output from same promptdata=PromptInsertion.update_prompt(id="prompt_id",name="updated_prompt",prompt_data={"data":"write abouts the plastic pollution"},variables={"context":"ocean_pollution"},)print(data)#Get prompt from iddata=PromptInsertion.get_prompt(id="prompt_id")print(data)# pagination support for getting the all promptdata=PromptInsertion.get_all_prompt(page=1)print(data)variableswhy variables?-> variables are the specific data used the get the desired and with context from ai LLM's.These is the example of the self consistance prompts Ref:https://www.promptingguide.ai/techniques/consistencyVaribales methods:fromAIBridgeimportVariableInsertion# save varibales# parameters: var_key: key for the varibales# var_value: list of the string for the contextdata=VariableInsertion.save_variables(var_key="ochean_context",var_value=["Ocean pollution is a significant environmental issue that poses a threat to marine life and ecosystems"],)print(data)# update the variablesdata=VariableInsertion.update_variables(id="variable_id",var_key="updated_string",var_value=["updated senetece about topics"],)print(data)# get Variables from iddata=VariableInsertion.get_variable(id="variable_id")# get all Variables paginationdata=VariableInsertion.get_all_variable(page=1)Get ResponseLLm=open_aidefault_model="gpt-3.4-turbo-oo3"Max_toke count - 3500temprature set to 0.5
methodsfromAIBridgeimportOpenAIServiceimportjsonjson_schema=json.dumps({"animal":["list of animals"]})xml_schema="<animals><category>animal name</category></animals>"csv="name,category,species,age,weight,color,habitat"data=OpenAIService.generate(prompts=["name of the animals in the  {{jungle}}"],prompt_ids=None,prompt_data=[{"jungle":"jungle"}],variables=None,output_format=["json"],format_strcture=[json_schema],model="gpt-3.5-turbo",variation_count=1,max_tokens=3500,temperature=0.5,message_queue=False,)print(data)# Prameters# prompts= list of the string that need to executed in session  where output id dependant on each other,# promts_ids= prompt  id's list and  so at a time ids will execute or prompts,# prompt_data=[data of the every prompt id they required],# variables=[ varibale dict of the prompt],# output_format=["xml/json/csv/sql/"],# format_strcture=[out put strcture of the prompt],# model="gpt-3.5-turbo", model for completion api of the gpt# variation_count = 1,  n of the output require# max_tokens = 3500, maximut token per out put# temperature = 0.5, data consistecy# message_queue=False, scalability purposeoutput={"items":{"response":[{"data":['{"animal": ["lion", "tiger", "elephant", "monkey", "snake", "gorilla", "leopard", "crocodile", "jaguar", "giraffe"]}']}],"token_used":85,"created_at":1689323114.9568439,"ai_service":"open_ai",}}Message Queuedefault Queue=redis,Configure redisfromAIBridgeimportSetConfig# set redis configurationSetConfig.redis_config(redis_host="localhost",redis_port="port _for redis",group_name="consumer gorup name",stream_name="redis topic",no_of_threads=1,#concurrent thread ypu want run for your application)To use the Queue service set message_queue = TruefromAIBridgeimportOpenAIServiceimportjsonjson_schema=json.dumps({"animal":["list of animals"]})data=OpenAIService.generate(prompts=["name of the animals in the  {{jungle}}"],prompt_ids=None,prompt_data=[{"jungle":"jungle"}],variables=None,output_format=["json"],format_strcture=[json_schema],message_queue=True# to activate message queue service)# to use the Queue service use the name set the message queue prameter = Trueprint(data)*Response for above function is the id of the response stored in the databse{"response_id":"eaa61944-3216-4ba1-bec5-05842fb86d86"}Message queue is for increasing scalibiltyfor APplication server you have turn on the consumer when application getting started.fromAIBridgeimportMessageQ# to start the consumer in backgroundMessageQ.mq_deque()In the non application environmen:you can run set message queue=TrueRun the below function to procees the Stream data in consumerfromAIBridgeimportMessageQ# these for testingthe redis env in local on single page filedata=MessageQ.local_process()print(data)###Dalle image genration###fromAIBridge.ai_services.openai_imagesimportOpenAIImageimages=OpenAIImage.generate(prompts=["A sunlit indoor lounge area with a pool containing a flamingo"],image_data=["image loacation or image url"],mask_image=["image loacation or image url"],variation_count=1,process_type="edit",)print(images)# prompts: is list string how many diffrent image we have to genearte# image_data: is the lacation of the image in file or the image url# mask_image: is the mask image with transpernet patch in the  image where we want edit the images# variation_count: is the number of image we want to generate# prcess type : create, edit, variation,# create is for genrating new images# edit the image with the mask mask is compulsary to edi the images# variation is for genrating new images of sama typePalm-Text APi IntegrationTo set APi key in aibridge_config.yaml file you can add the it directly in aibridge_config.yaml file in the formatpalm_api:-key:AIz****************************QkkA(your-api_key)priority:equalfromAIBridgeimportSetConfigSetConfig.set_api_key(ai_service="palm_api",key="YOUR_API_KEY",priority="high")#priority:high/medium/low/equal```python
from AIBridge import PalmText

prompt = """
write paragraph about the {{prompting}}in ai and let user know what is the{{prompting}} and how the {{prompting}} works in genrative AI
"""
json_format = """{"text": "paragraph here"}"""
data = PalmText.generate(
    prompts=[prompt],
    prompt_data=[{"prompting": "model training"}],
    output_format=["json"],
    format_strcture=[json_format],
    message_queue=True,
)
print(data)
# Prameters
# prompts= list of the string that need to executed in session  where output id dependant on each other,
# promts_ids= prompt  id's list and  so at a time ids will execute or prompts,
# prompt_data=[data of the every prompt id they required],
# variables=[ varibale dict of the prompt],
# output_format=["xml/json/csv/sql/"],
# format_strcture=[out put strcture of the prompt],
# model="models/text-bison-001", model for generate api of the palm
# variation_count = 1-8,  n of the output require
# max_tokens = default 10000, maximut token per out put, no limit for token"
# temperature = default-0.5, data consistecy
# message_queue=False, scalability purposePalm CHAT- APIfromAIBridgeimportPalmChat# An array of "ideal" interactions between the user and the modelexamples=[("What's up?","What isn't up?? The sun rose another day, the world is bright, anything is possible!",),("I'm kind of bored","How can you be bored when there are so many fun, exciting, beautiful experiences to be had in the world?",),]data=PalmChat.generate(messages="give the protype for the stack on c++",context="carreer or growth advides",variation_count=3,message_queue=True,)print(data)# mesages: text provided to chat# context: on the what basis do you want start the chat# examples: demo for the LLm to undersat the tone and what do you reaaly want(few shot prompt type)# variation_count: how many variations of the context should be used# message_queue: if true, the chat will return the messages in a queue# temperature = default-0.5, data consistecyStableDiffusion Imagestable_diffusion:-key:API Key herepriority:equalstable diffusion we have 3 action "img2img,text2image, inpaint"default parameter required for the api are:ParameterDescriptionkeyYour API Key used for request authorization.negative_promptItems you don't want in the image.widthMax Height: Width: 1024x1024. Should be divisible by 8.heightMax Height: Width: 1024x1024. Should be divisible by 8.samplesNumber of images to be returned in response. The maximum value is 4.num_inference_stepsNumber of denoising steps. Available values: 21, 31, 41, 51.safety_checkerA checker for NSFW images. If such an image is detected, it will be replaced by a blank image.enhance_promptEnhance prompts for better results; default: yes, options: yes/no.seedSeed is used to reproduce results, same seed will give you the same image in return again. Pass null for a random number.guidance_scaleScale for classifier-free guidance (minimum: 1; maximum: 20).multi_lingualAllow multilingual prompt to generate images. Use "no" for the default English.panoramaSet this parameter to "yes" to generate a panorama image.self_attentionIf you want a high-quality image, set this parameter to "yes". In this case, the image generation will take more time.upscaleSet this parameter to "yes" if you want to upscale the given image resolution two times (2x). If the requested resolution is 512 x 512 px, the generated image will be 1024 x 1024 px.embeddings_modelThis is used to pass an embeddings model (embeddings_model_id).webhookSet a URL to get a POST API call once the image generation is complete.track_idThis ID is returned in the response to the webhook API call. This will be used to identify the webhook request.text2imagfromAIBridgeimportStableDiffusiondata=StableDiffusion.generate(prompts=["cat sitting on bench"],# prompts is the list for how many images you have to genrate per requestaction="text2img",)print(data)Response{'0': {'status': 'success', 'generationTime': 0.7476449012756348, 'id': 40967676, 'output': ['https://cdn2.stablediffusionapi.com/generations/a77b1e09-e7ee-480b-80ad-abbdcdb66877-0.png'], 'meta': {'H': 512, 'W': 512, 'enable_attention_slicing': 'true', 'file_prefix': 'a77b1e09-e7ee-480b-80ad-abbdcdb66877', 'guidance_scale': 7.5, 'model': 'runwayml/stable-diffusion-v1-5', 'n_samples': 1, 'negative_prompt': 'low quality', 'outdir': 'out', 'prompt': 'cat sitting on bench', 'revision': 'fp16', 'safetychecker': 'yes', 'seed': 2873893487, 'steps': 20, 'vae': 'stabilityai/sd-vae-ft-mse'}}}img2imgfromAIBridgeimportStableDiffusioninit_image="https://raw.githubusercontent.com/CompVis/stable-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"data=StableDiffusion.generate(prompts=["cat sitting on bench"],image_data=[init_image],#image data is the list followed by the prompts for each prompt there should be one image dataaction="img2img",)print(data)Response{"0":{"status":"success","generationTime":0.7667558193206787,"id":40968310,"output":["https://cdn2.stablediffusionapi.com/generations/2f1a2b63-8569-4b94-9b86-41d142f72774-0.png"],"meta":{"H":512,"W":512,"file_prefix":"2f1a2b63-8569-4b94-9b86-41d142f72774","guidance_scale":7.5,"init_image":"https://raw.githubusercontent.com/CompVis/stable-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png","n_samples":1,"negative_prompt":"","outdir":"out","prompt":"cat sitting on bench","safetychecker":"yes","seed":1762284371,"steps":20,"strength":0.7}}}inpaintfromAIBridgeimportStableDiffusionmask_image="https://raw.githubusercontent.com/CompVis/stable-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"init_image="https://raw.githubusercontent.com/CompVis/stable-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"data=StableDiffusion.generate(prompts=["cat sitting on bench"],image_data=[init_image],mask_image=[mask_image],action="inpaint",)print(data)Response{"0":{"status":"success","generationTime":0.8590030670166016,"id":40967907,"output":["https://cdn2.stablediffusionapi.com/generations/59f14b2a-9ef5-4e41-83fc-fb1e5ff9b791-0.png"],"meta":{"H":512,"W":512,"file_prefix":"59f14b2a-9ef5-4e41-83fc-fb1e5ff9b791","guidance_scale":7.5,"init_image":"https://raw.githubusercontent.com/CompVis/stable-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png","mask_image":"https://raw.githubusercontent.com/CompVis/stable-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png","n_samples":1,"negative_prompt":"","outdir":"out","prompt":"cat sitting on bench","safetychecker":"yes","seed":242418520,"steps":20,"strength":0.7}}}NoteAt the image genration time thorugh api in stable diffusion complexex image some time take time so they are keep in the que and to fetch the image after completion we have to provide the response idfromAIBridgeimportStableDiffusiondata=StableDiffusion.fetch_image(id="image_id here")print(Data){
    "status": "success",
    "id": 12202888,
    "output": [
        "https://pub-8b49af329fae499aa563997f5d4068a4.r2.dev/generations/e5cd86d3-7305-47fc-82c1-7d1a3b130fa4-0.png"
    ]
}for Getting the information about all Queuing parametersfrom AIBridge import StableDiffusion
data=StableDiffusion.system_load(id="image_id here")
print(Data){"queue_num":0,"queue_time":0,"status":"ok"}Cohere APi'scohere_api:-key:API Key herepriority:equalfromAIBridgeimportSetConfigSetConfig.set_api_key(ai_service="cohere_api",key="YOUR_API_KEY",priority="high")#priority:high/medium/low/equalfromAIBridgeimportCohereApijson_str="""{"text": "text here"}"""csv_string="name,animal_type,prey,predators"xml_string="""<data><animal>animal information here</animal></data>"""data=CohereApi.generate(prompts=["give the me the more information about the {{animals}}"],prompt_data=[{"animals":"animals"}],format_strcture=[xml_string],output_format=["xml"],)print(data)# Prameters# prompts= list of the string that need to executed in session  where output id dependant on each other,# promts_ids= prompt  id's list and  so at a time ids will execute or prompts,# prompt_data=[data of the every prompt id they required],# variables=[ varibale dict of the prompt],# output_format=["xml/json/csv/sql/"],# format_strcture=[out put strcture of the prompt],# model="models/text-bison-001", model for generate api of the palm# variation_count =  the output require# max_tokens = default 10000, maximut token per out put, no limit for token"# temperature = default-0.5, data consistecy# message_queue=False, scalability purposeAI21 Api'sai21_api:-key:API Key herepriority:equalfromAIBridgeimportSetConfigSetConfig.set_api_key(ai_service="ai21_api",key="YOUR_API_KEY",priority="high")#priority:high/medium/low/equalfromAIBridgeimportJurasicTextjson_str="""{"text": "text here"}"""csv_string="name,animal_type,prey,predators"xml_string="""<?xml version="1.0" encoding="UTF-8" ?><data><animal>animal information here</animal></data>"""data=JurasicText.generate(prompts=["give the me the more information about the {{animals}}"],prompt_data=[{"animals":"tigers"}],format_strcture=[csv_string],output_format=["csv"],)print(data)# Prameters# prompts= list of the string that need to executed in session  where output id dependant on each other,# promts_ids= prompt  id's list and  so at a time ids will execute or prompts,# prompt_data=[data of the every prompt id they required],# variables=[ varibale dict of the prompt],# output_format=["xml/json/csv/sql/"],# format_strcture=[out put strcture of the prompt],# model="models/text-bison-001", model for generate api of the palm# variation_count =  the output require# max_tokens = default 10000, maximut token per out put, no limit for token"# temperature = default-0.5, data consistecy# message_queue=False, scalability purpose