https://github.com/kabragaurav/ai-agent
A simple AI agent for getting temperature of a city
https://github.com/kabragaurav/ai-agent
ai-agent cursor-ai cursor-ai-editor cursorai openai openai-api openweathermap openweathermap-api temperature-app weather-app
Last synced: 10 months ago
JSON representation
A simple AI agent for getting temperature of a city
- Host: GitHub
- URL: https://github.com/kabragaurav/ai-agent
- Owner: kabragaurav
- Created: 2025-03-14T13:04:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-24T09:38:40.000Z (about 1 year ago)
- Last Synced: 2025-05-29T13:26:07.171Z (about 1 year ago)
- Topics: ai-agent, cursor-ai, cursor-ai-editor, cursorai, openai, openai-api, openweathermap, openweathermap-api, temperature-app, weather-app
- Language: JavaScript
- Homepage: https://kabragaurav.netlify.app/
- Size: 7.32 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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](https://platform.openai.com/api-keys).
Check your remaining credit quota [here](https://platform.openai.com/settings/organization/billing/overview).
Also get keys for getting weather details from [here](https://api.openweathermap.org/). 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=
WEATHER_API_KEY=
```
## Insights
#### 1.
Code:
```js
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:
```json
{"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:
```js
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

