-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1136 from AletheiaFact/create-fact-check-agents
Automated Fact-checking Report MVP
- Loading branch information
Showing
30 changed files
with
614 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
|
||
# misc | ||
.DS_Store | ||
/**/*/._.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx lint-staged | ||
yarn lint-staged |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
server/automated-fact-checking/automated-fact-checking.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Body, Controller, Post, Header } from "@nestjs/common"; | ||
import { ApiTags } from "@nestjs/swagger"; | ||
import { AutomatedFactCheckingService } from "./automated-fact-checking.service"; | ||
import { CreateAutomatedFactCheckingDTO } from "./dto/create-automated-fact-checking.dto"; | ||
|
||
@Controller() | ||
export class AutomatedFactCheckingController { | ||
constructor( | ||
private automatedFactCheckingService: AutomatedFactCheckingService | ||
) {} | ||
|
||
@ApiTags("automated-fact-checking") | ||
@Post("api/ai-fact-checking") | ||
@Header("Cache-Control", "no-cache") | ||
async create(@Body() { sentence }: CreateAutomatedFactCheckingDTO) { | ||
return this.automatedFactCheckingService.getResponseFromAgents( | ||
sentence | ||
); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
server/automated-fact-checking/automated-fact-checking.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { ClaimReviewTaskModule } from "../claim-review-task/claim-review-task.module"; | ||
import { AutomatedFactCheckingService } from "./automated-fact-checking.service"; | ||
import { AutomatedFactCheckingController } from "./automated-fact-checking.controller"; | ||
import { ConfigModule } from "@nestjs/config"; | ||
|
||
@Module({ | ||
imports: [ClaimReviewTaskModule, ConfigModule], | ||
providers: [AutomatedFactCheckingService], | ||
exports: [AutomatedFactCheckingService], | ||
controllers: [AutomatedFactCheckingController], | ||
}) | ||
export class AutomatedFactCheckingModule {} |
72 changes: 72 additions & 0 deletions
72
server/automated-fact-checking/automated-fact-checking.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Injectable, Scope } from "@nestjs/common"; | ||
import { ConfigService } from "@nestjs/config"; | ||
|
||
@Injectable({ scope: Scope.REQUEST }) | ||
export class AutomatedFactCheckingService { | ||
constructor(private configService: ConfigService) {} | ||
|
||
async getResponseFromAgents(sentence: string = ""): Promise<object> { | ||
try { | ||
const url = `${this.configService.get<string>("agentsUrl")}/stream`; | ||
const params = { | ||
input: { | ||
messages: [ | ||
{ | ||
content: sentence, | ||
type: "human", | ||
role: "human", | ||
}, | ||
], | ||
sender: "Supervisor", | ||
}, | ||
}; | ||
|
||
const response = await fetch(url, { | ||
method: "POST", | ||
body: JSON.stringify(params), | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
|
||
let reader = response.body.getReader(); | ||
|
||
let streamResponse = ""; | ||
let done, value; | ||
|
||
while (!done) { | ||
({ done, value } = await reader.read()); | ||
streamResponse += new TextDecoder().decode(value, { | ||
stream: true, | ||
}); | ||
} | ||
|
||
const jsonEvents = streamResponse | ||
.split("\n") | ||
.filter((line) => line.startsWith("data:")) | ||
.map((line) => JSON.parse(line.substring(5))) | ||
.reduce((acc, data) => ({ ...acc, ...data }), {}); | ||
|
||
jsonEvents.__end__.messages = this.convertMessageContentsToJSON( | ||
jsonEvents.__end__.messages | ||
); | ||
return jsonEvents.__end__; | ||
} catch (error) { | ||
return { | ||
error: "Error in data fetching process", | ||
}; | ||
} | ||
} | ||
|
||
convertMessageContentsToJSON(messages) { | ||
return messages | ||
.map(({ content }) => { | ||
try { | ||
return JSON.parse(content); | ||
} catch (error) { | ||
return undefined; | ||
} | ||
}) | ||
.filter((message) => message !== undefined); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
server/automated-fact-checking/dto/create-automated-fact-checking.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { IsString } from "class-validator"; | ||
|
||
export class CreateAutomatedFactCheckingDTO { | ||
@IsString() | ||
sentence: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import axios from "axios"; | ||
|
||
const request = axios.create({ | ||
withCredentials: true, | ||
baseURL: `/api/ai-fact-checking`, | ||
}); | ||
|
||
const createClaimReviewTaskUsingAIAgents = (params) => { | ||
return request | ||
.post("/", { ...params }) | ||
.then((response) => { | ||
return response.data; | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
}); | ||
}; | ||
|
||
const AutomatedFactCheckingApi = { | ||
createClaimReviewTaskUsingAIAgents, | ||
}; | ||
|
||
export default AutomatedFactCheckingApi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from "react"; | ||
import Step from "@mui/material/Step"; | ||
import StepLabel from "@mui/material/StepLabel"; | ||
|
||
const AgentReviewStep = ({ | ||
label, | ||
stepIconComponent = null, | ||
...props | ||
}: { | ||
label: string; | ||
stepIconComponent?: any; | ||
key: string; | ||
color?: string; | ||
last?: boolean; | ||
completed?: boolean; | ||
}) => { | ||
return ( | ||
<Step {...props}> | ||
<StepLabel StepIconComponent={stepIconComponent}>{label}</StepLabel> | ||
</Step> | ||
); | ||
}; | ||
|
||
export default AgentReviewStep; |
Oops, something went wrong.