Skip to content

Commit

Permalink
🎨 Remove unnecessary imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
redadmiral committed Sep 5, 2024
1 parent 091e8be commit f6d9681
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions src/factchecker.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@

import asyncio
# import logging
# import re
# from uuid import uuid4

# import uvicorn
# from fastapi.responses import StreamingResponse, RedirectResponse, JSONResponse
from openai import OpenAI, AsyncOpenAI

from src.config import app, LOGGING_CONFIG
from src.datastructures import GenerationRequest, CheckResponse, CheckRequest, CheckResponseItem
from src.datastructures import OpenAiModel
from src.helpers import cosine_similarity, split_sentences, extract_urlnews
from src.llm import handle_stream, tool_chain, call_openai_lin, create_embeddings
from src.prompts import system_prompt_honest, system_prompt_malicious, check_prompt, check_summary_prompt
from src.helpers import cosine_similarity, split_sentences
from src.llm import create_embeddings


class FactChecker:
Expand All @@ -23,7 +12,7 @@ def __init__(self,
client=OpenAI(),
async_client=AsyncOpenAI(),
model=OpenAiModel.gpt4mini,
semantic_similarity_threshold = .57
semantic_similarity_threshold=.57
):
self.source = source
self.input = input
Expand All @@ -32,14 +21,14 @@ def __init__(self,
self.model = model
self.semantic_similarity_threshold = semantic_similarity_threshold
self.paragraphs = self.sentences = []

self._split_text()
self._embed_sentences()
self._compare_sentence_embeddings()

self.similar_sentences = [sentence for sentence in self.sentences[:-1] if sentence['sim'] > self.semantic_similarity_threshold]
self.similar_para_id = list(set([sentence['para_id'] for sentence in self.similar_sentences]))

self.similar_sentences = [sentence for sentence in self.sentences[:-1] if
sentence['sim'] > self.semantic_similarity_threshold]
self.similar_para_id = list(set([sentence['para_id'] for sentence in self.similar_sentences]))

def _split_text(self):
# split self.source into paras and sents
Expand All @@ -52,7 +41,8 @@ def _split_text(self):

for para_id, p in enumerate(self.paragraphs):
sentence_array = split_sentences(p)
self.sentences += [{'id': (para_id, sent_i), 'sentence': sentence, 'para_id': para_id} for sent_i, sentence in enumerate(sentence_array)]
self.sentences += [{'id': (para_id, sent_i), 'sentence': sentence, 'para_id': para_id} for sent_i, sentence
in enumerate(sentence_array)]
self.sentences.append({'id': int(-1), 'sentence': self.input, 'para_id': int(-1)})

def _embed_sentences(self):
Expand All @@ -64,7 +54,7 @@ def _embed_sentences(self):

# for sentence, embedding in zip(self.sentences, embeddings):
# sentence['embedding'] = embedding

def _compare_sentence_embeddings(self):
''' Compares each sentence in list with last sentence in list
=> Input sentence must be last sentence in list!'''
Expand Down

0 comments on commit f6d9681

Please sign in to comment.