import subprocess
import os
import mysql.connector
from dotenv import load_dotenv
def run_llama_cpp(prompt):
# Specify the absolute path of the executable and current directory
executable_path = 'D:\\Code\\llama_cpp\\w64devkit\\w64devkit.exe'
current_directory = 'D:\\Code\\llama_cpp\\llama.cpp'
model_path = 'D:\\Code\\llama_cpp\\llama.cpp\\models\\llama-2-7b.Q8_0.gguf'
# Debug: Print the current working directory
print("Current Working Directory:", os.getcwd())
# Change directory
os.chdir(current_directory)
print("Changed to Directory:", os.getcwd())
# Define the command
command = [
executable_path, # Use the absolute path of your executable
'./main',
'-ins',
'--color',
'-c', '1024',
'--temp', '0.7',
'--repeat_penalty', '1.1',
'-s', '42',
'-n', '-1',
'-m', model_path,
'-p', "'" , prompt , "'"
]
try:
print("Command: ", ' '.join(command))
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
stdout, stderr = process.communicate()
if stderr:
print("Standard Error Output:", stderr)
if process.returncode != 0:
print("Error running llama_cpp:", stderr)
return None
else:
title_start = stdout.find('[TITLE_START]') + len('[TITLE_START]')
title_end = stdout.find('[TITLE_END]')
description_start = stdout.find('[DESCRIPTION_START]') + len('[DESCRIPTION_START]')
description_end = stdout.find('[DESCRIPTION_END]')
title = stdout[title_start:title_end].strip()
description = stdout[description_start:description_end].strip()
return title, description
except FileNotFoundError as e:
print(f"File not found: {e}")
return None
except Exception as e:
print(f"An error occurred: {e}")
return None
load_dotenv()
db_connection = os.getenv('DB_CONNECTION')
db_host = os.getenv('DB_HOST')
db_port = int(os.getenv('DB_PORT'))
db_database = os.getenv('DB_DATABASE')
db_username = os.getenv('DB_USERNAME')
db_password = os.getenv('DB_PASSWORD')
connection = mysql.connector.connect(host=db_host, user=db_username, password=db_password, database=db_database, port=db_port)
cursor = connection.cursor(dictionary=True)
cursor.execute("SELECT * FROM posts")
prompts = cursor.fetchall()
cursor.close()
connection.close()
for prompt_entity in prompts:
str = prompt_entity['content']
content = "Generate headline for this content: '" + str + "'. Put the headline between [TITLE_START] and [TITLE_END]"
title, description = run_llama_cpp(content)
if title and description:
print("Content:", content)
print("Title:", title)
print("Description:", description)
print("####################################")
Ich versuche, meine Eingabeaufforderung direkt über w64devkit.exe zu übergeben, aber wenn ich den Befehl auf einem normalen Terminal öffne, öffnet w64devkit sein eigenes Terminal.
So übergebe ich meine Eingabeaufforderung direkt an Lama .cpp und erhalten Sie die Antwort?
Ich freue mich über Ihre Antworten!
Ich habe den folgenden Code geschrieben: [code]import subprocess import os import mysql.connector from dotenv import load_dotenv
def run_llama_cpp(prompt): # Specify the absolute path of the executable and current directory executable_path = 'D:\\Code\\llama_cpp\\w64devkit\\w64devkit.exe' current_directory = 'D:\\Code\\llama_cpp\\llama.cpp' model_path = 'D:\\Code\\llama_cpp\\llama.cpp\\models\\llama-2-7b.Q8_0.gguf'
# Debug: Print the current working directory print("Current Working Directory:", os.getcwd())
# Change directory os.chdir(current_directory) print("Changed to Directory:", os.getcwd())
# Define the command command = [ executable_path, # Use the absolute path of your executable './main', '-ins', '--color', '-c', '1024', '--temp', '0.7', '--repeat_penalty', '1.1', '-s', '42', '-n', '-1', '-m', model_path, '-p', "'" , prompt , "'" ]
try: print("Command: ", ' '.join(command))
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) stdout, stderr = process.communicate()
if stderr: print("Standard Error Output:", stderr)
for prompt_entity in prompts: str = prompt_entity['content'] content = "Generate headline for this content: '" + str + "'. Put the headline between [TITLE_START] and [TITLE_END]"
title, description = run_llama_cpp(content) if title and description: print("Content:", content) print("Title:", title) print("Description:", description) print("####################################")
[/code] Ich versuche, meine Eingabeaufforderung direkt über w64devkit.exe zu übergeben, aber wenn ich den Befehl auf einem normalen Terminal öffne, öffnet w64devkit sein eigenes Terminal. [img]https://i.sstatic.net/Nz4h3.png[/img] So übergebe ich meine Eingabeaufforderung direkt an Lama .cpp und erhalten Sie die Antwort? Ich freue mich über Ihre Antworten!
Wenn ich „unsloth“ verwende und versuche, das Modell als gguf zu speichern, erhalte ich die folgende Fehlermeldung:
1053 check = os.system( rm -rf llama.cpp/build )
1054 if check != 0: raise...
Ich arbeite also an einem Projekt, bei dem ich einen von Roboflow heruntergeladenen Datensatz im Yolo-Format verwende und dann versuche, den Trainingsordner an Llama 3.2 zu übergeben, um diesen...
Ich möchte einen Instabot in meinen Code einbeziehen. Code> Da Spyder meinen Benutzer nicht erkannte: C: \ Benutzer \ (mein Name) wird nicht als interner oder externer Befehl oder externer Befehl,...