diff --git a/.gitignore b/.gitignore index 7f166ed..542b6f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -isiap/ \ No newline at end of file +isiap/ +database/ \ No newline at end of file diff --git a/archive/claude_tool_test.py b/archive/claude_tool_test.py new file mode 100644 index 0000000..41af02f --- /dev/null +++ b/archive/claude_tool_test.py @@ -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$ + + +Where 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?") \ No newline at end of file diff --git a/archive/tool_test.py b/archive/tool_test.py new file mode 100644 index 0000000..dbb3dbd --- /dev/null +++ b/archive/tool_test.py @@ -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 \ No newline at end of file diff --git a/boss_prompt.txt b/boss_prompt.txt new file mode 100644 index 0000000..e69de29 diff --git a/test.py b/test.py new file mode 100644 index 0000000..768c813 --- /dev/null +++ b/test.py @@ -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) \ No newline at end of file diff --git a/tool_test_func.py b/tool_test_func.py new file mode 100644 index 0000000..c6f6e05 --- /dev/null +++ b/tool_test_func.py @@ -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 \ No newline at end of file