{"id":26430468,"url":"https://github.com/fus3n/twoai","last_synced_at":"2025-03-18T05:31:52.465Z","repository":{"id":231956251,"uuid":"783120969","full_name":"Fus3n/TwoAI","owner":"Fus3n","description":"A simple experiment on letting two local LLM have a conversation about anything!","archived":false,"fork":false,"pushed_at":"2024-04-18T20:06:39.000Z","size":113,"stargazers_count":66,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-18T21:25:40.221Z","etag":null,"topics":["ai","ai-agent","ai-conversations","local-llm","ollama","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Fus3n.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-04-07T01:59:52.000Z","updated_at":"2024-04-18T21:25:41.467Z","dependencies_parsed_at":"2024-04-10T18:44:41.183Z","dependency_job_id":null,"html_url":"https://github.com/Fus3n/TwoAI","commit_stats":null,"previous_names":["fus3n/twoai"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fus3n%2FTwoAI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fus3n%2FTwoAI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fus3n%2FTwoAI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fus3n%2FTwoAI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Fus3n","download_url":"https://codeload.github.com/Fus3n/TwoAI/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244164988,"owners_count":20409021,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","ai-agent","ai-conversations","local-llm","ollama","python"],"created_at":"2025-03-18T05:31:24.727Z","updated_at":"2025-03-18T05:31:52.454Z","avatar_url":"https://github.com/Fus3n.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TWOAI\nA simple experiment on letting two local LLM have a conversation about anything!\n\nIf you want to discuss more join the discord!\n\n[![Discord](https://img.shields.io/badge/Discord-R7TcKrQv?style=for-the-badge\u0026logo=discord\u0026logoColor=white)](https://discord.gg/R7TcKrQv)\n\n\u003cimg src=\"images/demo-1.png\"/\u003e\n\n**[Another example](#section-1)**\n\n## Installation\n\nFirst you need [Ollama](https://ollama.com/), install the executable as per the instructions.\nAfter that just make sure ollama is running in background, check your system tray.\nthen find the model you like [https://ollama.com/library](https://ollama.com/library)\nand just do:\n```bash\nollama pull \u003cmodel-name\u003e\n```\nThe installation commands are usually in the library page.\n\n### Usage for TwoAI\nExample in `src/example/main.py`\nIf you are using [pdm](https://github.com/pdm-project/pdm) you can install the package as with `pdm install` \n\n- Manual\n```bash\ngit clone https://github.com/Fus3n/TwoAI\ncd TwoAI\npip install -r requirements.txt\npython src/example/main.py llama3\n# with pdm\npdm run example llama3\n```\n\n```py\n# Setup\n\nBASE_MODEL = \"llama3\" # need to be pulled first if you want to use this, `ollama pull llama3`\n\nsys_prompt = \"\"\"\nYou are a very intelligent AI Chatbot and your name is {current_name}, Now\nyou will be having a converstaion with another AI called {other_name}, and its also same as you.\n{current_objective} Keep each message short and concise and repeat \"\u003cDONE!\u003e\" ONLY if you both established and agreed that you came to the end of the discussion. \n\"\"\".strip()\n\nagent_details: AgentDetails = (\n    {\n        \"name\": \"Zerkus\",\n        \"objective\": \"Debate against the other AI on what came first, the chicken or the egg.\"\n        \"and you think the chicken came first.\"\n        \"model\": BASE_MODEL, # this is optional, but here so you can use different models for different agent\n        \"host\": \"http://localhost:11434\" # optional, so you can use multiple host machines for each model\n    }, \n    {\n        \"name\": \"Nina\",\n        \"objective\": \"Debate against the other AI on what came first, the chicken or the egg.\"\n        \"and you think the Egg came first.\"\n    }\n)\n\ntwoai = TWOAI(\n    model=BASE_MODEL, \n    agent_details=agent_details, \n    system_prompt=sys_prompt\n    exit_word=\"\u003cDONE!\u003e\",\n    max_exit_words=2,\n)\n```\nNow to get response there are two ways\n\n```py\ntwoai.next_response(show_output=True)\ntwoai.next_response(show_output=True)\ntwoai.next_response(show_output=True)\n```\nResult will be something like:\n```\nZerkus: The chicken came first.\nNina: The egg came first.\nZerkus: According to scientific evidence, chickens came from eggs, but the question is about which came first in a cycle. Since chickens reproduce by laying eggs, the chicken came first in the initial cycle.\n```\n**Or** you can just start the infinite loop and they will continue until they both say the stop word and agree that the converstaion is over.\n```py\ntwoai.start_conversation()\n```\n\n\u003e The above conversation is from the data they are trained on and not from the internet, they cant do that yet.\n\n\u003e All my tests were on 7B models and i got the best results with `openhermes` 2.5 and `spooknik/kunoichi-dpo-v2-7b:q5_k_s` \n\n\n# \u003ca id=\"section-1\"\u003eProblem solving and more use cases\u003c/a\u003e\n\nI tested with some code snippets with errors and let them figure out where is the issue together\nThis is a simple test i did, obviously my objective and system prompt could be improved to get even better results or just using a better model as this is still 7B models, i also used 2 seperate models for each agent.\n\n#### Preview\n\nhttps://github.com/Fus3n/TwoAI/assets/52007265/58e71471-1c8c-445f-a3dc-b85b8627ff63\n\n#### System Prompt\n```py\nsys_prompt = \"\"\"\nYou are an AI Chatbot, you are an LLM, and your name is {current_name}, Now\nYou will be having a converstaion with Another AI called {other_name}, and it's also same as you.\n\\```py\ndef calculate_average(numbers):\n    total = 0\n    count = 0\n    for num in numbers:\n        total += num\n        count += 1\n    average = total / count\n    return average\n\ndata = [10, 20, 30, 40, 50]\nresult = calculate_average(data)\nprint(\"The average is:\", result)\n\\```\n\n{current_objective} And repeat \"\u003cDONE!\u003e\" ONLY if you both established and agreed that you came to the end of the discussion. \n\"\"\".strip()\n```\n\n#### Agent Details\n```py\n# they both have the same objective in this case so you could omit the {current_objective} and just use sytem prompt, as its used for both.\nagent_details: AgentDetails = (\n    {\n        \"name\": \"Zerkus\",\n        \"objective\": \"Check the above code thoroughly for errors and debate and decide and fix the error if there was any with the other AI by collaborating and suggesting solutions.\"\n        \"Carefully go through and try to find any and all edge cases step-by-step and conclude it.\",\n        \"model\": \"llama3\"\n    }, \n    {\n        \"name\": \"Nina\",\n        \"objective\": \"Check the above code thoroughly for errors and debate and decide and fix the error if there was any with the other AI by collaborating and suggesting solutions.\"\n        \"Carefully go through and try to find any and all edge cases step-by-step and conclude it.\",\n        \"model\": \"gemma2\"\n    }\n)\n```\n#### TwoAI\n```py\ntwoai = TWOAI(\n    model=BASE_MODEL, # not used but required parameter\n    agent_details=agent_details, \n    system_prompt=sys_prompt,\n    max_tokens=6094,\n    num_context=4094*2\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffus3n%2Ftwoai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffus3n%2Ftwoai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffus3n%2Ftwoai/lists"}