1

I am unable to obtain the desired response from the model I have trained.

i have this datasets for example

{'prompt':'what are you','completions':'I am a ABC Company Support AI'}
{'prompt':'who are you','completions':'I am a ABC Company Support AI'}

and train a model "davinci"

then i use this PHP Code for my testing

// Load the OpenAI API key from a file
$api_key = 'sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

// Set the model ID and fine-tuned model ID
$model_id = 'davinci';
$ft_model_id = 'davinci:ft-abc-company:dtr-ft1-2023-03-01-00-28-38';

// Define the prompt to send to the model
$prompt = 'what are you';

 
// Define the maximum number of tokens to generate
$max_tokens =200;

// Define the temperature of the response
$temperature = 0.5;

// Define the number of completions to generate
$n = 1;

// Define the stop sequence to use
$stop_sequence = null;

// Define the API endpoint
$endpoint = 'https://api.openai.com/v1/engines/'.$ft_model_id.'/completions';

// Define the API request headers
$headers = [
    'Content-Type: application/json',
    'Authorization: Bearer ' . $api_key
];

// Define the API request body
$body = [
    'prompt' => $prompt,
    'max_tokens' => $max_tokens,
    'temperature' => $temperature,
    'n' => $n,
    'stop' => $stop_sequence
];

// Convert the body to JSON
$body_json = json_encode($body);

// Send the API request
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body_json);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);

// Check for errors
if (curl_errno($ch)) {
    echo 'Error: ' . curl_error($ch);
    exit();
}

// Decode the API response
$response_data = json_decode($response, true);

 
// Get the first completion
$completion = @$response_data['choices'][0]['text'];
 
 print_r(@$response_data); echo '
 ';
 
//Check if the response is in the training data
$is_in_training_data = false;
if(@$response_data['choices'][0]['answers']){
    foreach (@$response_data['choices'][0]['answers'] as $answer) {
        if (strpos($completion, $answer['text']) !== false) {
            $is_in_training_data = true;
            break;
        }
    }
}

// Print the completion or 'I do not know your question.'
if ($is_in_training_data) {
    echo $completion;
} else {
    echo 'I do not know your question.';
}

// Close the cURL handle
curl_close($ch);

However, the answers are not being returned in the response array, only in the text array, and the answers are not related to the questions.

Or Assayag
  • 5,662
  • 13
  • 57
  • 93
  • 1
    Also, see this: [OpenAI API error: "Cannot specify both model and engine"](https://stackoverflow.com/questions/75176667/openai-api-error-cannot-specify-both-model-and-engine/75182746#75182746). All Engines endpoints are deprecated! Use `https://api.openai.com/v1/completions` instead. – Rok Benko Mar 01 '23 at 21:18
  • Thank you for your time. I have a question: Is it advisable to develop a chatbot instead of using OpenAI as a business support? I am impressed with ChatGPT, which is why I started learning OpenAI. However, I find it more complex than I initially thought. –  Mar 03 '23 at 07:25
  • How do you define a "chatbot"? Chatbot that is not using AI? – Rok Benko Mar 03 '23 at 08:27
  • The process would involve matching keywords from the query sent by my client with the information stored in the knowledge base of my website. –  Mar 03 '23 at 08:37
  • My goal was to create a chatbot that could respond to user queries using the information from my website's knowledge base. I aimed for it to function similarly to ChatGPT, with the exception that if the chatbot didn't have the answer in its knowledge base, it would simply reply with 'I don't know the answer to that question'. –  Mar 03 '23 at 08:41
  • So you would not need OpenAI API at all? – Rok Benko Mar 03 '23 at 08:56
  • I'm researching this exact same thing. I've discovered that if it has your data from the internet or a book from before 2021, it can use that as a reference. If you are giving it information, you're using your tokens and the whole API call is limited to 4000 tokens. Some people have had success using embeddings (which is in the documentation) but I haven't read anyone using that with this 3.5 model. So, for example, if you say use Chat Responses for Dummies by Dummies. plus this 3000 token 'string' of business docs, you can get pretty close. – Unnamed Mistress Mar 04 '23 at 20:26

0 Answers0