Skip to content

Instantly share code, notes, and snippets.

@leolivier
Created December 2, 2023 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leolivier/20ba5a92cee3625fb79588824ad84d7d to your computer and use it in GitHub Desktop.
Save leolivier/20ba5a92cee3625fb79588824ad84d7d to your computer and use it in GitHub Desktop.
ollama + litellm + autogen simplified
  1. install ollama

run ollama server

  1. ollama serve
  2. open new terminal

install models you want

  1. ollama pull mistral
  2. ollama pull codellama

install python modules

  1. conda create -n autogen python=3.11
  2. conda activate autogen
  3. which python
  4. python -m pip install pyautogen
  5. conda activate autogen
  6. python -m pip install litellm

run litellm

  1. litellm
  2. open new terminal

  3. create new ollama-autogen.py file with code found below

finally, run demo

  1. python ollama-autogen.py

Code used:

import autogen

config_list_mistral = [ { 'base_url': "http://0.0.0.0:8000", 'api_key': "NULL", 'model': "mistral" } ]

config_list_codellama = [ { 'base_url': "http://0.0.0.0:8000", 'api_key': "NULL", 'model': 'ollama/codellama" } ]

llm_config_mistral={ "config_list": config_list_mistral, }

llm_config_codellama={ "config_list": config_list_codellama, }

coder = autogen.AssistantAgent( name="Coder", llm_config=llm_config_codellama )

user_proxy = autogen.UserProxyAgent( name="user_proxy", human_input_mode="NEVER", max_consecutive_auto_reply=10, is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"), code_execution_config={"work_dir": "web"}, llm_config=llm_config_mistral, system_message="""Reply TERMINATE if the task has been solved at full satisfaction. Otherwise, reply CONTINUE, or the reason why the task is not solved yet.""" )

task=""" Write a python script to output numbers 1 to 100 and then the user_proxy agent should run the script """

user_proxy.initiate_chat(coder, message=task)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment