Package: llmnet
llmnetllmnet is a library designed to facilitate collaborative work among LLMs on diverse tasks. Its primary goal is to encourage a diversity of thought across various LLM models.llmnet comprises two main components:LLM network workersConsensus workerThe LLM network workers can independently and concurrently process tasks, while the consensus worker can access the various solutions and generate a final output. It's important to note that the consensus worker is optional and doesn't necessarily need to be employed.ExamplePrerequisitellmnet currently supports LLM models from OpenAI and Google. The user can define the model to be used for the LLM workers, as well as the model to be used for the consensus worker.Please make sure to set env variables calledOPENAI_API_KEY,GOOGLE_API_KEYto your OpenAi and Google keys.How to use llmnet?llm workerYou have currently three llm worker at your disposal:openaillmbotgooglellmbotrandomllmbotrandomopenaillmbotrandomgooglellmbotopenaillmbotInterface with OpenAi models.optional parameters:model         (str) = 'gpt-3.5-turbo'
max_tokens    (int) = 2024
temperature   (float) = 0.1
n             (int) = 1
stop          (Union[str, List[str]]) = NonegooglellmbotInterface with Google models.optional parameters:model               (str) = 'gemini-pro'
max_output_tokens   (int) = 2024
temperature         (float) = 0.1
top_p               (float) = None
top_k               (int) = None
candidate_count     (int) = 1
stop_sequences      (str) = NonerandomllmbotSelect randomly between all available llmworkers and parameter specified.optional parameters:random_configuration  (Dict) = {}example dict:{
    "<worker1>":
    {
        "<parameter1>": [<possible_arguments>],
        "<parameter2>": [<possible_arguments>],
        ...
    },
    "<worker2>":
    {
        "<parameter1>": [<possible_arguments>],
        "<parameter2>": [<possible_arguments>]
        ...
    }
    ...
}randomopenaillmbotSelect randomly between all configurations possible for OpenAi based llms.optional parameters - if not provided, defaults toopenaillmbotdefault values:random_configuration  (Dict) = {}example dict:{
    "<parameter1>": [<possible_arguments>],
    "<parameter2>": [<possible_arguments>],
    ...
}randomgooglellmbotSelect randomly between all configurations possible for Google based llms.optional parameters - if not provided, defaults togooglellmbotdefault values:random_configuration  (Dict) = {}example dict:{
    "<parameter1>": [<possible_arguments],
    "<parameter2>": [<possible_arguments],
    ...
}create_networkcreates llmworker networkexpects:instruct: List[Dict[str, str]]structure:[{"objective": xxx, "context": ooo}..], the context key is is optionalworker: select any worker from the abovemax_concurrent_worker: how many API calls are allowed in parallelkwargs: any configuration for the worker selectedaccess results via getter methods:get_worker_answers: collection of answers combined in one stringget_worker_answers_messages: collection of answers with metadataapply_consensuscreates consensus workerexpects:worker: select any worker from the abovekwargs: any configuration for the worker selectedset_prompt: prompt to build consensusaccess results via getter methods:get_worker_consensus: consensus result as stringget_worker_consensus_messages: consensus result with metadataSimple independent tasks - no consensusfromllmnetimportLlmNetworkinstructions=[]instructions=[{"objective":"how many countries are there?"},{"objective":"what is AGI"},{"objective":"What is the purpose of biological life?"}]net=LlmNetwork()net.create_network(instruct=instructions,worker="randomllmbot",max_concurrent_worker=2,# how many API calls are allowed in parallelrandom_configuration={"googlellmbot":{"model":["gemini-pro"],"temperature":[0.12,0.11]},"openaillmbot":{"model":["gpt-3.5-turbo","gpt-4"],"temperature":[0.11,0.45,1],},},)# collection of answers as a stringnet.get_worker_answers# collection of answers with metadatanet.get_worker_answer_messagesOne task with same objective split between multiple workers - consensusfromllmnetimportLlmNetworkinstructions=[]instructions=[{"objective":"What is empiricism?","context":"Text Part One"},{"objective":"What is empiricism?","context":"Text Part Two"},{"objective":"What is empiricism?","context":"Text Part Three"}]net=LlmNetwork()net.create_network(instruct=instructions,worker="randomllmbot",max_concurrent_worker=2,# how many API calls are allowed in parallelrandom_configuration={"googlellmbot":{"model":["gemini-pro"],"temperature":[0.12,0.11]},"openaillmbot":{"model":["gpt-3.5-turbo"],"temperature":[0.11,0.45,1],},},)# collection of answers as a stringnet.get_worker_answers# collection of answers with metadatanet.get_worker_answer_messages# apply consensusnet.apply_consensus(worker="openaillmbot",model="gpt-3.5-turbo",temperature=0.7,set_prompt=f"Answer this objective: What is empiricism? with the following text in just one sentences:{net.get_worker_answers}",)# get final consensus answer as a stringnet.get_worker_consensus# get answer with metadatanet.get_worker_consensus_messagesOther example use casesindependent objectives, choose best solution via consensusmixed objectives with and without context, with or without consensusetc.AppendixMap reduce by LangChain:LangChain MapReduce Documentation