Created
September 11, 2025 02:43
-
-
Save dmateos/1d30abbd09f3e0f9021c7b672a42a295 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from openai import OpenAI | |
| from typing import Any, List | |
| import sys | |
| class Agent: | |
| def __init__(self) -> None: | |
| self.client: OpenAI = OpenAI( | |
| base_url="http://dmacstudio.lan.mateos.cc:11434/v1", | |
| api_key="ollama", | |
| ) | |
| def list_models(self) -> None: | |
| models = self.client.models.list() | |
| for model in models.data: | |
| print(model.id) | |
| print("") | |
| def prompt(self, data: str) -> Any: | |
| messages = [ | |
| {"role": "system", "content": "You are a helpful assistant."}, | |
| {"role": "user", "content": data}, | |
| ] | |
| return messages | |
| def ask(self, data: str) -> str | None: | |
| response = self.client.chat.completions.create( | |
| model="gpt-oss:20b", | |
| messages=self.prompt(data), | |
| ) | |
| return response.choices[0].message.content | |
| class Router(Agent): | |
| def models_availbile(self) -> List[str]: | |
| return ["Scientist", "Coder", "Mathguy"] | |
| def prompt(self, data: str) -> Any: | |
| messages = [ | |
| {"role": "system", "content": f"You are a router who will route requests to the correct expert. Choices are #{self.models_availbile}, respond with just experts name"}, | |
| {"role": "user", "content": data}, | |
| ] | |
| return messages | |
| agent = Router() | |
| #agent.list_models() | |
| response = agent.ask(sys.argv[1]) | |
| print(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment