Compare commits
No commits in common. "90798c6a38655023a316bb798f249b6f4a140e14" and "43353c8c792e6afd43e42bb42b496f109fb5e70b" have entirely different histories.
90798c6a38
...
43353c8c79
@ -35,7 +35,7 @@ llm:
|
|||||||
- name : "z-ai/glm-5"
|
- name : "z-ai/glm-5"
|
||||||
|
|
||||||
ragroleplay:
|
ragroleplay:
|
||||||
db_path : "~/.config/hendrik/ragroleplay"
|
db_path : "./.ragroleplay"
|
||||||
vector_size : 768 # used on table create only
|
vector_size : 768 # used on table create only
|
||||||
model_url : "http://localhost:11434/api/embed"
|
model_url : "http://localhost:11434/api/embed"
|
||||||
model_name : "nomic-embed-text" # Need to download model from local ollama
|
model_name : "nomic-embed-text" # Need to download model from local ollama
|
||||||
@ -64,4 +64,4 @@ delay: # Humanize Delay (anti-bot detection)
|
|||||||
typing_max : 10.0 # max typing delay limit per second
|
typing_max : 10.0 # max typing delay limit per second
|
||||||
|
|
||||||
user:
|
user:
|
||||||
id: # Fill your user UUID here
|
id: "YOUR_USER_ID_HERE"
|
||||||
|
|||||||
@ -130,30 +130,6 @@ def _agent_loop(app):
|
|||||||
if response.warning:
|
if response.warning:
|
||||||
log(app, "system", f" {response.warning}")
|
log(app, "system", f" {response.warning}")
|
||||||
|
|
||||||
# Cek apakah response adalah error dari LLM client
|
|
||||||
content = response.content
|
|
||||||
is_error = isinstance(content, str) and (content.startswith("Error:") or content.startswith("HTTP Error:"))
|
|
||||||
|
|
||||||
if is_error:
|
|
||||||
# Hapus "Thinking..." log dan placeholder
|
|
||||||
for i in range(len(app.log) - 1, -1, -1):
|
|
||||||
if app.log[i].get('role') == 'system' and 'Thinking' in app.log[i].get('text', ''):
|
|
||||||
app.log.pop(i)
|
|
||||||
break
|
|
||||||
if placeholder_marker is not None:
|
|
||||||
for i in range(len(app.log) - 1, -1, -1):
|
|
||||||
if app.log[i].get('role') == 'ai':
|
|
||||||
text = app.log[i].get('text', '')
|
|
||||||
if placeholder_marker in text or text == "" or text == "...":
|
|
||||||
app.log.pop(i)
|
|
||||||
break
|
|
||||||
log(app, "error", content)
|
|
||||||
_add_msg(app, "assistant", content)
|
|
||||||
log(app, "sep", "")
|
|
||||||
ntro.end(stamp)
|
|
||||||
app.agent_done.set()
|
|
||||||
return
|
|
||||||
|
|
||||||
# Cek apakah ada tool_calls
|
# Cek apakah ada tool_calls
|
||||||
has_tool_calls = bool(response.tool_calls)
|
has_tool_calls = bool(response.tool_calls)
|
||||||
|
|
||||||
|
|||||||
@ -1,84 +0,0 @@
|
|||||||
import requests, gc, lancedb, pyarrow, uuid
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
def _schema_domainlogic(vector_size):
|
|
||||||
return pyarrow.schema([
|
|
||||||
pyarrow.field('timestamp', pyarrow.timestamp('ms'), metadata={'description': 'When record created'}),
|
|
||||||
pyarrow.field('content', pyarrow.string(), metadata={'description': 'Content'}),
|
|
||||||
pyarrow.field('category', pyarrow.string(), metadata={'description': 'Category. Comma separated.'}),
|
|
||||||
pyarrow.field('vector_context', pyarrow.list_(pyarrow.float32(), vector_size), metadata={'description': 'Vector data of combined data'}),
|
|
||||||
])
|
|
||||||
|
|
||||||
_TABLE_SCHEMAS = {
|
|
||||||
'knowledge_domainlogic': _schema_domainlogic,
|
|
||||||
}
|
|
||||||
|
|
||||||
def db_init(db_path, vector_size):
|
|
||||||
db = lancedb.connect(db_path)
|
|
||||||
existing = db.table_names()
|
|
||||||
for name, schema_fn in _TABLE_SCHEMAS.items():
|
|
||||||
if name not in existing:
|
|
||||||
db.create_table(name, schema=schema_fn(vector_size))
|
|
||||||
print(f"[ragroleplay] Created table: {name}", flush=True)
|
|
||||||
del db
|
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
def table_ensure(db_path, table_name, vector_size):
|
|
||||||
db = lancedb.connect(db_path)
|
|
||||||
existing = db.table_names()
|
|
||||||
if table_name not in existing:
|
|
||||||
schema_fn = _TABLE_SCHEMAS.get(table_name)
|
|
||||||
if schema_fn:
|
|
||||||
db.create_table(table_name, schema=schema_fn(vector_size))
|
|
||||||
del db
|
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
def _uuid(val):
|
|
||||||
return uuid.UUID(val) if isinstance(val, str) else val
|
|
||||||
|
|
||||||
def embed_text(url, model, text):
|
|
||||||
response = requests.post(url=url, json={"model": model, "input": text} )
|
|
||||||
data = response.json()
|
|
||||||
return data["embeddings"][0]
|
|
||||||
|
|
||||||
def domainlogic_store(db_path, model_url, model_name, payload):
|
|
||||||
try:
|
|
||||||
db = lancedb.connect(db_path)
|
|
||||||
table = db.open_table("knowledge_domainlogic")
|
|
||||||
|
|
||||||
vector = embed_text(model_url, model_name, f'Category: {payload["category"]}. \n{payload["content"]}')
|
|
||||||
|
|
||||||
record = {
|
|
||||||
"timestamp" : datetime.now(),
|
|
||||||
"content" : payload["content" ],
|
|
||||||
"category" : payload["category" ],
|
|
||||||
"vector_context" : vector
|
|
||||||
}
|
|
||||||
|
|
||||||
table.add([record])
|
|
||||||
del table
|
|
||||||
del db
|
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
return "success"
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
return e
|
|
||||||
|
|
||||||
def domainlogic_load(db_path, payload):
|
|
||||||
try:
|
|
||||||
db = lancedb.connect(db_path)
|
|
||||||
table = db.open_table("knowledge_domainlogic")
|
|
||||||
|
|
||||||
results = table.search().to_list()
|
|
||||||
|
|
||||||
del table
|
|
||||||
del db
|
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
return results
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"error: {e}")
|
|
||||||
return []
|
|
||||||
|
|
||||||
@ -115,8 +115,11 @@ def ensure_table(db_path, table_name, vector_size): # table_ensure seharusnya
|
|||||||
del db
|
del db
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
|
|
||||||
def _uuid(val):
|
def _uuid(val):
|
||||||
return uuid.UUID(val) if isinstance(val, str) else val
|
if isinstance(val, str):
|
||||||
|
return uuid.UUID(val)
|
||||||
|
return val
|
||||||
|
|
||||||
def embed_text(url, model, text):
|
def embed_text(url, model, text):
|
||||||
response = requests.post(url=url, json={"model": model, "input": text} )
|
response = requests.post(url=url, json={"model": model, "input": text} )
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user