Skip to content

Instantly share code, notes, and snippets.

View john-adeojo's full-sized avatar

John Adeojo john-adeojo

View GitHub Profile
from haystack.nodes import PreProcessor
from haystack.utils import convert_files_to_docs
from haystack.document_stores import FAISSDocumentStore
from sqlalchemy import create_engine
from haystack.nodes import EmbeddingRetriever
# pre-process docs
def preprocess_docs(doc_dir):
all_docs = convert_files_to_docs(dir_path=doc_dir)
preprocessor = PreProcessor(
from haystack.agents import Agent
from haystack.nodes import PromptNode, PromptTemplate, AnswerParser
from haystack.agents import Tool
def create_agent(document_qa, API_KEY):
react_prompt = PromptTemplate(
prompt="""You are a helpful and knowledgeable agent. To achieve your goal of answering complex questions
correctly, you have access to the following tools:
{tool_names_with_descriptions}
from haystack.nodes import EmbeddingRetriever, FARMReader
from haystack.pipelines import ExtractiveQAPipeline
from haystack.pipelines import Pipeline
def make_document_qa_pipeline(document_store):
retriever = EmbeddingRetriever(
document_store=document_store,
embedding_model="sentence-transformers/all-mpnet-base-v2"
)
document_store.update_embeddings(retriever)
from haystack.nodes import PreProcessor
from haystack.utils import convert_files_to_docs
from haystack.document_stores import FAISSDocumentStore
from sqlalchemy import create_engine
# pre-process docs
def preprocess_docs(doc_dir):
all_docs = convert_files_to_docs(dir_path=doc_dir)
preprocessor = PreProcessor(
clean_empty_lines=True,
import transformers
import evaluate
from sklearn.metrics import f1_score, precision_score, recall_score, accuracy_score
f1_metric = evaluate.load("f1")
recall_metric = evaluate.load("recall")
accuracy_metric = evaluate.load("accuracy")
precision_metric = evaluate.load("precision")
def compute_metrics(eval_pred):
# Setting up the LoRA model
import os
os.environ["CUDA_VISIBLE_DEVICES"]="0"
from transformers import AutoModelForSequenceClassification
from peft import LoraConfig, get_peft_model, TaskType
MODEL ="xlm-roberta-large"
config = LoraConfig(
task_type="SEQ_CLS",
import openai
def return_topic_args(query, API_KEY):
openai.api_key = API_KEY
content = "You parse the arguments defined in the prompt"
prompt = f""" From the {query}, Return the news topic required """
response = openai.ChatCompletion.create(
import openai
def function_calling_multiple_function(API_KEY, query):
# Step 1: send the conversation and available functions to GPT
functions = [
{
"name": "get_current_news",
"description": "Get the latest news headline for a given topic",
"parameters": {
"type": "object",
import openai
def generate_response(topic, API_KEY):
"""
Generates a random news headline for a given ticker
"""
openai.api_key = API_KEY
def function_calling_one_function(API_KEY, query):
# Step 1: send the conversation and available functions to GPT
functions = [
{
"name": "get_temperature",
"description": "Get the temperature at a given location and date",
"parameters": {
"type": "object",
"properties": {
"location": {