Can you access the CLI in a python script? Please add this if not

I would like to fine-tune a model without having to open the CLI and run commands.

I am trying to make a script that allows users to fine tune models automatically. Is there anything I can do?

My code is

import sqlite3
import os
import time

# Create a connection to the database
conn = sqlite3.connect('database.sqlite')

# Create a cursor
c = conn.cursor()

# Access the database
res = c.execute("SELECT name FROM sqlite_master")
res = res.fetchall()
print(res)

# Ask the user for the table to access
name = input("What expert would you like to access?\nTo make a new one, simply type a name not in the list above\n")

# Use the input to access
if name in [r[0] for r in res]:
    print("Expert found.")
else:
    try:
        c.execute("CREATE TABLE {} (Question TEXT, Response TEXT)".format(name))
        print("Expert not found. Created expert instead.")
    except sqlite3.OperationalError as e:
        print("Error:", e)

time.sleep(1)

def runcode():
    os.system('clear')
    action = input("What would you like to do?\n Type 1 to add data\n Type 2 to save data\n Type 3 to terminate process\n Type 4 to train and use expert\n")
    if action == '1':
        addedRequest = input("What would a user ask to request the data?\n")
        idealResponse = input("How should the expert respond?\n")
        # Use parameterized query to prevent SQL injection
        c.execute("INSERT INTO {} (Question, Response) VALUES (?, ?)".format(name), (addedRequest, idealResponse))
        runcode()
    elif action == '2':
        conn.commit()
        runcode()
    elif action == '3':
        print('Goodbye')
    elif action == '4':
        # I need a way to access the OpenAI CLI here, using the database to fine tune a model in the CLI
        print('Not available yet')

runcode()

# Close the connection
conn.close()

Feature requests

you could try to make a bash script that triggers CLI commands
but that’d be risky

Thank you for the suggestion. I apologize, I meant to ask for a way to run the commands in a python script. If that was what you meant, please explain

“automatically”, and “run commands in a script”, are a bit exclusive.

And also, one can jump from “script” to “program” to GUI application, simply in how complex your “.py” is. You could write a program that is a graphical tune editor and validator, parameter adjuster, submitter, queue tracker, database, chatbot evaluator for validation tests, etc.

Or if you just want to simplify things you can type at a python shell prompt, you could make a module with classes or functions to support fine-tuning:

import my_finetuner as ft
ft.pushtune(model_id, tune_file5.txt)

I would be hard-pressed to offer a solution based on your abstract specifications. If this topic is simply “how do I run external programs from within python”, asking ChatGPT (or a programming forum) is more appropriate.

1 Like

Thank you, allow me to write my code

import sqlite3
import os
import time

# Create a connection to the database
conn = sqlite3.connect('database.sqlite')

# Create a cursor
c = conn.cursor()

# Access the database
res = c.execute("SELECT name FROM sqlite_master")
res = res.fetchall()
print(res)

# Ask the user for the table to access
name = input("What expert would you like to access?\nTo make a new one, simply type a name not in the list above\n")

# Use the input to access
if name in [r[0] for r in res]:
    print("Expert found.")
else:
    try:
        c.execute("CREATE TABLE {} (Question TEXT, Response TEXT)".format(name))
        print("Expert not found. Created expert instead.")
    except sqlite3.OperationalError as e:
        print("Error:", e)

time.sleep(1)

def runcode():
    os.system('clear')
    action = input("What would you like to do?\n Type 1 to add data\n Type 2 to save data\n Type 3 to terminate process\n Type 4 to train and use expert\n")
    if action == '1':
        addedRequest = input("What would a user ask to request the data?\n")
        idealResponse = input("How should the expert respond?\n")
        # Use parameterized query to prevent SQL injection
        c.execute("INSERT INTO {} (Question, Response) VALUES (?, ?)".format(name), (addedRequest, idealResponse))
        runcode()
    elif action == '2':
        conn.commit()
        runcode()
    elif action == '3':
        print('Goodbye')
    elif action == '4':
        # I need a way to access the OpenAI CLI here, using the database to fine tune a model in the CLI
        print('Not available yet')

runcode()

# Close the connection
conn.close()

B.U.M.P. (Bring up my post)

Hello,
Like the other guy said this probably isn’t really the right place to ask this question, not to mention a quick Google search will pop up a quick answer with a lot of examples to use. Or just ask ChatGPT and it can probably write the python script for you.

But to give you a quick answer and at least point you in the right direction I believe you are looking for the exec command in python. i.e exec (/user/bin/hello_world.py).
But there are really much better / safer ways to do what I think you are wanting to do. Doing things like this feels very 90’s. :slightly_smiling_face:
Check out this answer from Stackoverflow. Execute a command from Python.

Paul.

I dont know, I never completed fine tuning process. But most likely it is a python script, yes.