google-gemini / generative-ai-js

The official Node.js / Typescript library for the Google Gemini API
https://www.npmjs.com/package/@google/generative-ai
Apache License 2.0
627 stars 126 forks source link

Can we ensure the ai to not use any other data not in the context? #30

Open Ranork opened 8 months ago

Ranork commented 8 months ago

We are trying to make a sql query generator with chat complation.

prompt: Show me the customers

history:

[
  {"role": "user", "parts": "### SYSTEM CONTEXT ### \nYou are an *MSSQL* command generator. Use table schema for generating sql commands. ### EXAMPLE RESONSE ### \`\`\`sql ... \`\`\`  \n ### DATABASE SCHEME ### ......."},
  {"role": "model", "parts": "OK" }
]
const gemini = gai.getGenerativeModel({ model });
const chat = gemini.startChat({history, generationConfig: { temperature: 0.2 }});

const result = await chat.sendMessage(prompt);
const response = await result.response;

It gives me cool sql commands but some table names are not logical names (like crnt_tbl for current table). AI tries to access tables that do not exist in the schema, causing the query to not work.

I want it to only use existing table names in the schema. How can I set this up?

marb2000 commented 8 months ago

Prompt engineering for large language models is challenging. It involves providing clear context, specifying desired outcomes, and filtering unwanted outputs. Finding the perfect formula takes experimentation – playing with keywords, sentence structures, and prompt lengths.

I hope someone in the community can share their prompts that successfully tackled similar scenarios. In the meantime, this document helped me understand some best practices for prompt engineering

Ranork commented 8 months ago

We have done these experiments on other artificial intelligence models, but it would be great if anyone who has solved similar situations could share their prompt formats :) Thanks for fast answer!