Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions end-to-end-use-cases/Contextual-Chunking-RAG/config.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
LLAMAPARSE_API_KEY=""
DEEPINFRA_API_KEY=""
import os

LLAMAPARSE_API_KEY = os.environ.get("LLAMAPARSE_API_KEY", "")
DEEPINFRA_API_KEY = os.environ.get("DEEPINFRA_API_KEY", "")
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@


from pathlib import Path
import os
from qdrant_client import QdrantClient, models
from sentence_transformers import SentenceTransformer
import uuid
import re

# Configuration - in case you want to create an online collection
QDRANT_URL = "replace with your Qdrant URL"
QDRANT_API_KEY = "replace with your qdrant API key"
QDRANT_URL = os.environ.get("QDRANT_URL", "")
QDRANT_API_KEY = os.environ.get("QDRANT_API_KEY", "")
EMBEDDING_MODEL = 'all-MiniLM-L6-v2'

# New files to process
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 3 Community License Agreement.
# This software may be used and distributed according to the terms of the Llama Community License Agreement.

import langchain
from langchain.llms import Replicate
Expand All @@ -10,7 +10,7 @@
import requests
import json

os.environ["REPLICATE_API_TOKEN"] = "<your replicate api token>"
os.environ.setdefault("REPLICATE_API_TOKEN", os.environ.get("REPLICATE_API_TOKEN", ""))
llama3_8b_chat = "meta/meta-llama-3-8b-instruct"

llm = Replicate(
Expand All @@ -35,7 +35,7 @@ def msgrcvd_pager():
'recipient': '{"id": ' + sender + '}',
'message': json.dumps({'text': answer}),
'messaging_type': 'RESPONSE',
'access_token': "<your page access token>"
'access_token': os.environ.get("PAGE_ACCESS_TOKEN", "")
}
headers = {
'Content-Type': 'application/json'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 3 Community License Agreement.
# This software may be used and distributed according to the terms of the Llama Community License Agreement.

import langchain
from langchain.llms import Replicate
Expand All @@ -13,8 +13,8 @@
class WhatsAppClient:

API_URL = "https://graph.facebook.com/v17.0/"
WHATSAPP_API_TOKEN = "<Temporary access token from your WhatsApp API Setup>"
WHATSAPP_CLOUD_NUMBER_ID = "<Phone number ID from your WhatsApp API Setup>"
WHATSAPP_API_TOKEN = os.environ.get("WHATSAPP_API_TOKEN", "")
WHATSAPP_CLOUD_NUMBER_ID = os.environ.get("WHATSAPP_CLOUD_NUMBER_ID", "")

def __init__(self):
self.headers = {
Expand All @@ -38,7 +38,7 @@ def send_text_message(self,message, phone_number):
assert response.status_code == 200, "Error sending message"
return response.status_code

os.environ["REPLICATE_API_TOKEN"] = "<your replicate api token>"
os.environ.setdefault("REPLICATE_API_TOKEN", os.environ.get("REPLICATE_API_TOKEN", ""))
llama3_8b_chat = "meta/meta-llama-3-8b-instruct"

llm = Replicate(
Expand All @@ -58,6 +58,6 @@ def msgrcvd():
answer = llm(message)
print(message)
print(answer)
client.send_text_message(llm(message), "<your phone number>")
client.send_text_message(llm(message), os.environ.get("RECIPIENT_PHONE", ""))
return message + "<p/>" + answer

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io
import re
import gradio as gr
import PyPDF2
import pypdf
from together import Together


Expand Down Expand Up @@ -38,7 +38,7 @@ def extract_arxiv_pdf_url(arxiv_url):

def extract_text_from_pdf(pdf_content):
pdf_file = io.BytesIO(pdf_content)
reader = PyPDF2.PdfReader(pdf_file)
reader = pypdf.PdfReader(pdf_file)
text = ""
for page in reader.pages:
text += page.extract_text() + "\n"
Expand All @@ -53,7 +53,7 @@ def extract_references_with_llm(pdf_content):
if len(text) > max_length:
text = text[:max_length] + "..."

client = Together(api_key="Your API key here")
client = Together(api_key=os.environ.get("TOGETHER_API_KEY"))

citations = client.chat.completions.create(
model="meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8",
Expand Down Expand Up @@ -219,7 +219,7 @@ def respond(message, history):
history.append([user_message, ""])


client = Together(api_key="Your API key here")
client = Together(api_key=os.environ.get("TOGETHER_API_KEY"))

# Prepare the system prompt and user message

Expand Down