Skip to content

kabragaurav/ai-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Agents

by Gaurav Kabra

What is an AI agent?

A system capable of autonomously performing taskson behalf of user/another system.

E.g. Salesforce Agentforce

How is it different from LLM?

LLM (like ChatGPT4o) have knowledge base on trained data but cannot perform tasks like CRUD on company DB. Moreover, the data on which LLM was trained, is stale (not real time).

In a very layman terms,

Agent = LLM + tools (defined functions like how to do CRUD)

Setup

Obtain OpenAPI keys from here.

Check your remaining credit quota here.

Also get keys for getting weather details from here. Once you generate key, key will take ~10 mins to become activated.

Then put this in a new .env file, which you need to create in root folder of the project. E.g.

OPENAI_API_KEY=<value here without quotes>
WEATHER_API_KEY=<value here without quotes>

Insights

1.

Code:

async function chat() {
    let result = await client.chat.completions.create({
        model: "gpt-4o-mini",
        messages: [
            {role: "system", content: SYS_PROMPT},
            {role: "user", content: "what is the weather of Jaipur?"}
        ]
    });

    console.log(result.choices[0].message.content);
}

Output:

{"type": "user", "user": "What is the weather of Jaipur?"}
{"type": "plan", "plan": "I will call getTemperatureDetails function for Jaipur"}
{"type": "execution", "function": "getTemperatureDetails", "input": "Jaipur"}

2.

Code:

const chat = await client.chat.completions.create({
            model: "gpt-4o-mini",
            messages: history,
            response_format: { "type": "json_object" }
        });
    
        const response = chat.choices[0].message.content;
        console.log('---------- Starts Agent Response ----------');
        console.log(response);

Output:

3.

It is able to apply AI over output (e.g. °C to °F conversions)

4. Integrating live weather API using Cursor AI editing