trying to get tooling working

This commit is contained in:
0x01FE committed 2025-10-02 13:12:46 -05:00
1 parent 4d71275f12
commit 16d4998d70
4 files changed
+46 -17

No files matched your search

+25 -9
View File
@@ -1,10 +1,11 @@
# Import the Llama class from the llama_cpp library
import llama_cpp
import json
import random
from . import tool_funcs
tools: list[dict] = json.loads(open('tools.json', 'r').read())['tools']
tools: list[dict] = json.loads(open('./textgen/tools.json', 'r').read())['tools']
class TextGen:
@@ -19,12 +20,12 @@ class TextGen:
# Provide the path to your downloaded .gguf file
# n_ctx is the maximum context size (number of tokens) the model can handle.
# n_gpu_layers specifies how many layers to offload to the GPU. -1 means offload all possible layers.
llm = llama_cpp.Llama(
model_path="./models/mistral-7b-instruct-v0.2.Q4_K_M.gguf", # Path to your GGUF model
n_ctx=n_ctx, # Context window size
n_gpu_layers=n_gpu_layers, # Offload all layers to GPU. Set to 0 if no GPU.
verbose=False, # Suppress verbose output
chat_format='chatml'
self.llm = llama_cpp.Llama(
model_path=model_path, # Path to your GGUF model
n_ctx=n_ctx, # Context window size
n_gpu_layers=n_gpu_layers, # Offload all layers to GPU. Set to 0 if no GPU.
verbose=False, # Suppress verbose output
chat_format='chatml'
)
def generate(self, prompt: str) -> str:
@@ -52,14 +53,18 @@ class TextGen:
"content": user_message
})
print(tools)
response = self.llm.create_chat_completion(
messages=self.messages,
tools=tools,
tool_choice='auto'
tool_choice='auto',
seed=random.randint(0, 20000000000)
)
tool_call = response['choices'][0]['message'].get('tool_calls')
if not tool_call:
# print(response['choices'][0]['message']['content'])
return response['choices'][0]['message']['content']
call_info = tool_call[0]['function']
@@ -68,5 +73,16 @@ class TextGen:
print(f'Assistant decided to call {function_name}')
tool_output = tool_funcs.get_high_low()
self.messages.append(response['choices'][0]['message'])
self.messages.append(
{
"role" : "tool",
"content": tool_output
}
)
final_response = self.llm.create_chat_completion(messages=self.messages)
return final_response['choices'][0]['message']['content']
+5 -5
View File
@@ -36,10 +36,10 @@ class OpenMeteo:
# Process first location. Add a for-loop for multiple locations or weather models
response = responses[0]
print(f"Coordinates: {response.Latitude()}°N {response.Longitude()}°E")
print(f"Elevation: {response.Elevation()} m asl")
print(f"Timezone: {response.Timezone()}{response.TimezoneAbbreviation()}")
print(f"Timezone difference to GMT+0: {response.UtcOffsetSeconds()}s")
# print(f"Coordinates: {response.Latitude()}°N {response.Longitude()}°E")
# print(f"Elevation: {response.Elevation()} m asl")
# print(f"Timezone: {response.Timezone()}{response.TimezoneAbbreviation()}")
# print(f"Timezone difference to GMT+0: {response.UtcOffsetSeconds()}s")
# Process hourly data. The order of variables needs to be the same as requested.
hourly = response.Hourly()
@@ -57,7 +57,7 @@ class OpenMeteo:
hourly_data['rain'] = hourly_rain
hourly_dataframe = pd.DataFrame(data = hourly_data)
print("\nHourly data\n", hourly_dataframe)
# print("\nHourly data\n", hourly_dataframe)
return hourly_dataframe