mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-08-25 18:39:39 +00:00
Compare commits
17 Commits
3f2c36d48b
...
feature/te
Author | SHA1 | Date | |
---|---|---|---|
77cf893121 | |||
61348aa351 | |||
b281ad766d | |||
dea942f11e | |||
bed2c526dd | |||
d62e620828 | |||
3ebca8d98f | |||
f0556813ac | |||
eac72dd2a4 | |||
6d2252a403 | |||
2b1f5190ef | |||
8d265c9105 | |||
ffa38de046 | |||
a4095c837b | |||
65d4a56135 | |||
fffa27b6ee | |||
12579fcd6e |
61
.github/workflows/pr-description.yml
vendored
Normal file
61
.github/workflows/pr-description.yml
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
name: 🤖 AI PR Description with HuggingFace Falcon
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, edited]
|
||||
|
||||
jobs:
|
||||
generate-description:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install GitHub CLI and jq
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install gh jq -y
|
||||
|
||||
- name: Fetch PR Commits
|
||||
id: fetch_commits
|
||||
run: |
|
||||
COMMITS=$(gh pr view ${{ github.event.pull_request.number }} --json commits --jq '.commits[].message' | sed 's/^/- /')
|
||||
echo "commits<<EOF" >> $GITHUB_ENV
|
||||
echo "$COMMITS" >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PERSONAL_TOKEN }}
|
||||
|
||||
- name: Generate PR Description with HuggingFace Falcon
|
||||
run: |
|
||||
REQUEST_BODY=$(jq -n \
|
||||
--arg inputs "Given the following commit messages:\n\n${commits}\n\nGenerate a clear and professional pull request description." \
|
||||
'{ inputs: $inputs }'
|
||||
)
|
||||
|
||||
RESPONSE=$(curl -s https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct \
|
||||
-H "Authorization: Bearer $HUGGINGFACE_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$REQUEST_BODY")
|
||||
|
||||
echo "---------- HuggingFace Raw Response ----------"
|
||||
echo "$RESPONSE"
|
||||
|
||||
DESCRIPTION=$(echo "$RESPONSE" | jq -r 'if type=="array" then .[0].generated_text else .error else "Error: Unexpected response" end')
|
||||
|
||||
echo "---------- Extracted Description ----------"
|
||||
echo "$DESCRIPTION"
|
||||
|
||||
echo "description<<EOF" >> $GITHUB_ENV
|
||||
echo "$DESCRIPTION" >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
env:
|
||||
HUGGINGFACE_API_KEY: ${{ secrets.HUGGINGFACE_API_KEY }}
|
||||
commits: ${{ env.commits }}
|
||||
|
||||
- name: Post AI Generated Description as Comment
|
||||
run: |
|
||||
gh pr comment ${{ github.event.pull_request.number }} --body "${{ env.description }}"
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PERSONAL_TOKEN }}
|
@ -1,7 +1,7 @@
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import axios from 'axios';
|
||||
import nodemailer from 'nodemailer';
|
||||
import * as nodemailer from 'nodemailer';
|
||||
import Mail from 'nodemailer/lib/mailer';
|
||||
import { BatchEmailData } from './batch-email.interface';
|
||||
import { SingleEmailData } from './single-email.interface';
|
||||
|
@ -1 +0,0 @@
|
||||
export * from './weather.controller';
|
@ -1,28 +0,0 @@
|
||||
import { Controller, Get, Query } from '@nestjs/common';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
import { ControllerRoute } from '@app/common/constants/controller-route'; // Assuming this is where the routes are defined
|
||||
import { WeatherService } from '../services';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { GetWeatherDetailsDto } from '../dto/get.weather.dto';
|
||||
|
||||
@ApiTags('Weather Module')
|
||||
@Controller({
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: ControllerRoute.WEATHER.ROUTE, // use the static route constant
|
||||
})
|
||||
export class WeatherController {
|
||||
constructor(private readonly weatherService: WeatherService) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.WEATHER.ACTIONS.FETCH_WEATHER_DETAILS_SUMMARY,
|
||||
description:
|
||||
ControllerRoute.WEATHER.ACTIONS.FETCH_WEATHER_DETAILS_DESCRIPTION,
|
||||
})
|
||||
async fetchWeatherDetails(
|
||||
@Query() query: GetWeatherDetailsDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
return await this.weatherService.fetchWeatherDetails(query);
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsNumber } from 'class-validator';
|
||||
|
||||
export class GetWeatherDetailsDto {
|
||||
@ApiProperty({
|
||||
description: 'Latitude coordinate',
|
||||
example: 35.6895,
|
||||
})
|
||||
@IsNumber()
|
||||
@Type(() => Number)
|
||||
lat: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Longitude coordinate',
|
||||
example: 139.6917,
|
||||
})
|
||||
@IsNumber()
|
||||
@Type(() => Number)
|
||||
lon: number;
|
||||
}
|
@ -1 +0,0 @@
|
||||
export * from './weather.service';
|
@ -1,51 +0,0 @@
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { HttpService } from '@nestjs/axios';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { GetWeatherDetailsDto } from '../dto/get.weather.dto';
|
||||
import { calculateAQI } from '@app/common/util/calculate.aqi';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||
|
||||
@Injectable()
|
||||
export class WeatherService {
|
||||
private readonly weatherApiUrl: string;
|
||||
constructor(
|
||||
private readonly configService: ConfigService,
|
||||
private readonly httpService: HttpService,
|
||||
) {
|
||||
this.weatherApiUrl = this.configService.get<string>('WEATHER_API_URL');
|
||||
}
|
||||
|
||||
async fetchWeatherDetails(
|
||||
query: GetWeatherDetailsDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
try {
|
||||
const { lat, lon } = query;
|
||||
const weatherApiKey = this.configService.get<string>(
|
||||
'OPEN_WEATHER_MAP_API_KEY',
|
||||
);
|
||||
const url = `${this.weatherApiUrl}/current.json?key=${weatherApiKey}&q=${lat},${lon}&aqi=yes`;
|
||||
|
||||
const response = await firstValueFrom(this.httpService.get(url));
|
||||
const pm2_5 = response.data.current.air_quality.pm2_5; // Raw PM2.5 (µg/m³)
|
||||
|
||||
return new SuccessResponseDto({
|
||||
message: `Weather details fetched successfully`,
|
||||
data: {
|
||||
aqi: calculateAQI(pm2_5), // Converted AQI (0-500)
|
||||
temperature: response.data.current.temp_c,
|
||||
humidity: response.data.current.humidity,
|
||||
},
|
||||
statusCode: HttpStatus.OK,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(`Error fetching weather data: ${error}`);
|
||||
|
||||
throw new HttpException(
|
||||
`Api can't handle these lat and lon values`,
|
||||
error.response?.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { HttpModule } from '@nestjs/axios'; // <-- Import this!
|
||||
import { WeatherController } from './controllers';
|
||||
import { WeatherService } from './services';
|
||||
|
||||
@Module({
|
||||
imports: [ConfigModule, HttpModule],
|
||||
controllers: [WeatherController],
|
||||
providers: [WeatherService],
|
||||
})
|
||||
export class WeatherModule {}
|
Reference in New Issue
Block a user