at least this kind of works
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
isiap/
|
isiap/
|
||||||
|
database/
|
||||||
63
archive/claude_tool_test.py
Normal file
63
archive/claude_tool_test.py
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
# Made with Claude
|
||||||
|
|
||||||
|
import ollama
|
||||||
|
|
||||||
|
# Simulated database
|
||||||
|
database = {
|
||||||
|
"users": ["Alice", "Bob", "Charlie"],
|
||||||
|
"products": ["Chair", "Table", "Lamp"],
|
||||||
|
"orders": ["Order#1: Alice bought Chair", "Order#2: Bob bought Lamp"],
|
||||||
|
}
|
||||||
|
|
||||||
|
def query_database(keyword):
|
||||||
|
keyword = keyword.strip().lower()
|
||||||
|
for key, values in database.items():
|
||||||
|
if keyword == key.lower():
|
||||||
|
return f"Database result for '{keyword}': {values}"
|
||||||
|
return f"No results found for '{keyword}'"
|
||||||
|
|
||||||
|
system_prompt = """You are a helpful assistant with access to a database.
|
||||||
|
If you need to look something up in the database, output EXACTLY:
|
||||||
|
$DATABASE$
|
||||||
|
<keyword>
|
||||||
|
|
||||||
|
Where <keyword> is what you want to search for (e.g. 'users', 'products', 'orders').
|
||||||
|
Do not add anything else on those lines. Wait for the result before responding."""
|
||||||
|
|
||||||
|
def chat(user_input):
|
||||||
|
messages = [
|
||||||
|
{'role': 'system', 'content': system_prompt},
|
||||||
|
{'role': 'user', 'content': user_input},
|
||||||
|
]
|
||||||
|
|
||||||
|
while True:
|
||||||
|
# Get response (non-streaming for easier parsing)
|
||||||
|
response = ollama.chat(model='llama3.2', messages=messages)
|
||||||
|
reply = response['message']['content']
|
||||||
|
|
||||||
|
print(f"[Raw model output]: {reply}\n")
|
||||||
|
|
||||||
|
# Check if the model wants to query the database
|
||||||
|
if '$DATABASE$' in reply:
|
||||||
|
lines = reply.strip().split('\n')
|
||||||
|
db_index = next(i for i, l in enumerate(lines) if '$DATABASE$' in l)
|
||||||
|
|
||||||
|
# Keyword is on the next line
|
||||||
|
if db_index + 1 < len(lines):
|
||||||
|
keyword = lines[db_index + 1].strip()
|
||||||
|
db_result = query_database(keyword)
|
||||||
|
print(f"[Database queried: '{keyword}' → {db_result}]\n")
|
||||||
|
|
||||||
|
# Feed the result back into the conversation
|
||||||
|
messages.append({'role': 'assistant', 'content': reply})
|
||||||
|
messages.append({'role': 'user', 'content': f"Database result: {db_result}\nNow respond to the user."})
|
||||||
|
# Loop again so the model can respond with the result
|
||||||
|
else:
|
||||||
|
print("Model requested DB but didn't provide a keyword.")
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# No database call, just print the final response
|
||||||
|
print(f"Assistant: {reply}")
|
||||||
|
break
|
||||||
|
|
||||||
|
chat("Can you show me the list of users?")
|
||||||
36
archive/tool_test.py
Normal file
36
archive/tool_test.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# TOOL USE TEST
|
||||||
|
|
||||||
|
import ollama
|
||||||
|
|
||||||
|
system_prompt = """You have access to a list. If you want to retrieve the content in the list, output EXACTLY:
|
||||||
|
$DATABASE$
|
||||||
|
|
||||||
|
Do not output anything else. The result will be returned in a string starting with [DATABASE].
|
||||||
|
"""
|
||||||
|
context_prompt = None # if context exists
|
||||||
|
user_input = "Check the list and tell me what is in there"
|
||||||
|
|
||||||
|
combined_system = f"{system_prompt}\n\nContext: {context_prompt}"
|
||||||
|
|
||||||
|
stream = ollama.chat(
|
||||||
|
model='llama3.2',
|
||||||
|
messages=[
|
||||||
|
{'role': 'system', 'content': combined_system},
|
||||||
|
{'role': 'user', 'content': user_input},
|
||||||
|
],
|
||||||
|
stream=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Accumulate chunks into a variable
|
||||||
|
full_response = ""
|
||||||
|
for chunk in stream:
|
||||||
|
content = chunk['message']['content']
|
||||||
|
print(content, end='', flush=True)
|
||||||
|
full_response += content
|
||||||
|
|
||||||
|
if "$DATABASE$" in full_response:
|
||||||
|
# DATABASE LOGIC TODO
|
||||||
|
pass
|
||||||
|
|
||||||
|
print() # newline after streaming
|
||||||
|
print(full_response) # your complete output
|
||||||
0
boss_prompt.txt
Normal file
0
boss_prompt.txt
Normal file
23
test.py
Normal file
23
test.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import ollama
|
||||||
|
|
||||||
|
# 1. Define your variables
|
||||||
|
system_prompt = "You are a helpful assistant with a witty personality."
|
||||||
|
context_prompt = "The current topic of conversation is quantum computing."
|
||||||
|
user_input = "Can you explain it like I'm five?"
|
||||||
|
|
||||||
|
# 2. Combine the prompts
|
||||||
|
# We merge the system and context for the 'system' role
|
||||||
|
combined_system = f"{system_prompt}\n\nContext: {context_prompt}"
|
||||||
|
|
||||||
|
# 3. Stream the response
|
||||||
|
stream = ollama.chat(
|
||||||
|
model='llama3.2', # or your preferred model
|
||||||
|
messages=[
|
||||||
|
{'role': 'system', 'content': combined_system},
|
||||||
|
{'role': 'user', 'content': user_input},
|
||||||
|
],
|
||||||
|
stream=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
for chunk in stream:
|
||||||
|
print(chunk['message']['content'], end='', flush=True)
|
||||||
47
tool_test_func.py
Normal file
47
tool_test_func.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# TOOL USE TEST
|
||||||
|
|
||||||
|
import ollama
|
||||||
|
|
||||||
|
def llm_converse(system_prompt, context_prompt, user_input):
|
||||||
|
combined_system = f"{system_prompt}\n\nContext: {context_prompt}"
|
||||||
|
|
||||||
|
stream = ollama.chat(
|
||||||
|
model='llama3.2',
|
||||||
|
messages=[
|
||||||
|
{'role': 'system', 'content': combined_system},
|
||||||
|
{'role': 'user', 'content': user_input},
|
||||||
|
],
|
||||||
|
stream=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Accumulate chunks into a variable
|
||||||
|
full_response = ""
|
||||||
|
for chunk in stream:
|
||||||
|
content = chunk['message']['content']
|
||||||
|
print(content, end='', flush=True)
|
||||||
|
full_response += content
|
||||||
|
|
||||||
|
return full_response
|
||||||
|
|
||||||
|
def get_file_content(filename):
|
||||||
|
with open(filename, "r") as files:
|
||||||
|
bruh = files.read()
|
||||||
|
return bruh
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
system_prompts = """You have access to a list. If you want to retrieve the content in the list, output EXACTLY:
|
||||||
|
$DATABASE$
|
||||||
|
|
||||||
|
Do not output anything else. The result will be returned in a string starting with [DATABASE].
|
||||||
|
"""
|
||||||
|
context_prompts = None # if context exists
|
||||||
|
user_inputs = "Check the list and tell me what is in there"
|
||||||
|
|
||||||
|
prompt1 = llm_converse(system_prompts, context_prompts, user_inputs)
|
||||||
|
if "$DATABASE$" in prompt1:
|
||||||
|
# DATABASE LOGIC TODO
|
||||||
|
pass
|
||||||
|
|
||||||
|
print() # newline after streaming
|
||||||
|
print(full_response) # your complete output
|
||||||
Reference in New Issue
Block a user