Sorry for the confusion, no I am recreating the same setup as the tutorial, here is my code:
export async function recreateIndex() {
console.log("--- Recreating index ---");
const client = getClient();
try {
const response1 = await client.indices.delete({
index,
});
console.log("response1 :>>", JSON.stringify(response1.body, null, 2));
} catch (error) {
// Ignore if index does not exist
}
const response2 = await client.http.post({
path: "/_plugins/_ml/connectors/_create",
body: {
name: "OpenAI Chat Connector",
description: "The connector to public OpenAI model service for GPT 3.5",
version: 2,
protocol: "http",
parameters: {
endpoint: "api.openai.com",
model: "gpt-3.5-turbo",
temperature: 0,
},
credential: {
openAI_key: "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",
},
actions: [
{
action_type: "predict",
method: "POST",
url: "https://${parameters.endpoint}/v1/chat/completions",
headers: {
Authorization: "Bearer ${credential.openAI_key}",
},
request_body:
'"{ "model": "${parameters.model}", "messages": ${parameters.messages}, "temperature": ${parameters.temperature} }"',
},
],
},
});
const { connector_id } = response2.body;
console.log("connector_id :>> ", connector_id);
const response3 = await client.http.post({
path: "/_plugins/_ml/models/_register",
body: {
name: "openAI-gpt-3.5-turbo",
function_name: "remote",
description: "test model",
connector_id,
},
});
const { model_id } = response3.body;
console.log("model_id :>> ", model_id);
const response4 = await client.http.post({
path: `/_plugins/_ml/models/${model_id}/_deploy`,
});
console.log("response4 :>> ", response4.body);
const response5 = await client.http.put({
path: "/_search/pipeline/rag_pipeline",
body: {
response_processors: [
{
retrieval_augmented_generation: {
tag: "openai_pipeline_demo",
description: "Demo pipeline Using OpenAI Connector",
model_id,
context_field_list: ["textContent"],
system_prompt: "You are a helpful assistant",
user_instructions:
"Generate a concise and informative answer in less than 100 words for the given question",
},
},
],
},
});
console.log("response5 :>>", JSON.stringify(response5.body, null, 2));
const response6 = await client.http.put({
path: `/${index}`,
body: {
settings: {
"index.search.default_pipeline": "rag_pipeline",
},
mappings: {
properties: {
textContent: {
type: "text",
},
},
},
},
});
console.log("response6 :>>", JSON.stringify(response6.body, null, 2));
}