Compare commits

..
3 Commits
Author SHA1 Message Date
stupdi c768aaca6b Add large file via LFS 2025-06-27 16:33:13 -05:00
stupdi 0424d27d00 Added some utility skeletons 2025-06-27 16:21:42 -05:00
stupdi 5e932c84ae test 2025-06-27 16:08:45 -05:00
5 changed files with 141 additions and 171 deletions
+1
View File
@@ -0,0 +1 @@
*.gguf filter=lfs diff=lfs merge=lfs -text
-169
View File
@@ -1,170 +1 @@
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
-2
View File
@@ -1,2 +0,0 @@
# MUDProject
+119
View File
@@ -0,0 +1,119 @@
from llama_cpp import Llama
from langchain_core.language_models import LLM
from langchain.prompts import PromptTemplate
from langchain.agents import AgentExecutor, create_react_agent
from langchain.tools import Tool
from typing import Optional, List
from googlesearch import search
from bs4 import BeautifulSoup
import requests
# --- LLaMA-CPP model setup ---
llm_model = Llama(
model_path="ReAction-1.5B.Q5_K_M.gguf",
n_ctx=2**21,
n_threads=8,
use_mlock=True,
verbose=False
)
# --- LangChain wrapper ---
class LlamaCppLLM(LLM):
@property
def _llm_type(self) -> str:
return "llama-cpp"
def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
result = llm_model(
prompt,
stop=stop,
max_tokens=1024,
echo=False,
)
output = result["choices"][0]["text"].strip()
return output
custom_llm = LlamaCppLLM()
# --- Tool definition ---
def extract_text(html):
soup = BeautifulSoup(html, "html.parser")
# Remove scripts and styles
for tag in soup(["script", "style"]):
tag.decompose()
text = soup.get_text(separator=" ", strip=True)
return text
def weather(city: str) -> str:
return f"The weather in {city} is Sunny."
def search_google(query:str):
print(f"serach tool called {query}")
return [url for url in search(query,stop=5)]
def get_webhtml(url):
print(url)
url = url.replace("'","")
if url:
r = requests.get(url)
else:
return None
return extract_text(r.text) if r.status_code == 200 else None
weather_tool = Tool(
name="weather",
func=weather,
description="Use this tool to get the weather of a given city. Input should be the city name."
)
search_tool = Tool(
name = "search_tool",
func=search_google,
description="Returns the first 5 results from google with a specific query"
)
html_tool = Tool(
name="get_webhtml",
func=get_webhtml,
description="Given a url, it provides the HTML for it. If it returns None, the website isn't available."
)
# --- Custom ReAct prompt ---
prompt_template = PromptTemplate.from_template("""
You are a helpful assistant that can use tools to answer questions.
TOOLS:
{tools}
FORMAT:
Question: the input question
Thought: think about what to do
Action: pick one of [{tool_names}]
Action Input: "<the input to the action>"
Observation: result of the action
... (you can repeat Thought/Action/Observation until you reach a Final Answer) ...
... (Also, only use Action Input AFTER you use Action, so before you use Action input again, you have to call a tool again. Reach a final Answer before 3 iterations) ...
Thought: I now know the final answer
Final Answer: <the final answer>
NEW QUESTION:
Question: {input}
{agent_scratchpad}
""")
# --- Create ReAct agent ---
react_agent = create_react_agent(
llm=custom_llm,
tools=[search_tool,html_tool],
prompt=prompt_template
)
agent = AgentExecutor(
agent=react_agent,
tools=[search_tool,html_tool],
verbose=True,
handle_parsing_errors=True,
max_iterations=5
)
# --- Run it ---
response = agent.invoke({"input": "What is the weather in San Francisco"})
print("\nFinal Output:\n", response)
+21
View File
@@ -0,0 +1,21 @@
class Item():
def __init__(self,material_name,item_owner=None,**kwargs):
self.material_name = material_name
self.item_owner = item_owner if item_owner else "Wild"
self.__dict__.update(kwargs)
class Entity():
def __init__(self,name:str,health:int,isInvincible,statusEffects,**kwargs):
pass
class Player(Entity):
pass
class StatusEffects():
pass
class EntityAttributes():
pass
class Skill():
pass
class Inventory():
def __init__(self,max_space,items=None):
pass