Skip to content

Instantly share code, notes, and snippets.

@ranfysvalle02
ranfysvalle02 / ondemand-analytics.py
Created December 11, 2023 02:42
on-demand analytics with actionweaver and mongodb atlas
from typing import List
from actionweaver import RequireNext, action, SelectOne
from actionweaver.llms.azure.chat import ChatCompletion
from actionweaver.llms.openai.tools.chat import OpenAIChatCompletion
from actionweaver.llms.openai.functions.tokens import TokenUsageTracker
from langchain.embeddings import GPT4AllEmbeddings
from langchain.text_splitter import RecursiveCharacterTextSplitter
import json
import os
import pymongo
@ranfysvalle02
ranfysvalle02 / search-web.py
Created December 5, 2023 23:27
Search the web with a headless browser, not a library
# Import the necessary libraries
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from bs4 import BeautifulSoup
# Set up the headless browser
options = Options()
options.headless = True
options.add_argument("--headless")
options.add_argument('--disable-gpu')
@ranfysvalle02
ranfysvalle02 / acl-secure-rag.py
Last active December 3, 2023 21:35
acl-secure-rag.py
import pymongo
from langchain.embeddings import AzureOpenAIEmbeddings
MONGODB_URI = ""
client = pymongo.MongoClient(MONGODB_URI)
db = client["sample_mflix"]
collection = db["embedded_movies"]
azureEmbeddings = AzureOpenAIEmbeddings(
deployment="",
@ranfysvalle02
ranfysvalle02 / interactive-rag.py
Last active November 17, 2023 12:32
EXPERIMENTAL---
import os
from enum import Enum
from typing import List, Optional, Tuple
from actionweaver import RequireNext, SelectOne, action
from actionweaver.llms.azure.chat import ChatCompletion
from actionweaver.llms.openai.tokens import TokenUsageTracker
from langchain.vectorstores import MongoDBAtlasVectorSearch
from langchain.embeddings import GPT4AllEmbeddings
from langchain.document_loaders import PlaywrightURLLoader
from llama_index import Document, ServiceContext
@ranfysvalle02
ranfysvalle02 / summarize-this.py
Created November 12, 2023 06:21
Strategic Summarization of Large Text using OpenAI
import tiktoken
import openai
from bs4 import BeautifulSoup
import requests
class OpenAISummarize(object):
def __init__(self, api_key:str="", model:str="gpt-3.5-turbo",max_words:int=200,max_sections:int=2,deployment_id:str="", api_version:str="", api_base:str="" ) -> None:
self.api_key = api_key
self.deployment_id = deployment_id
self.api_version = api_version
@ranfysvalle02
ranfysvalle02 / openai-summarizer.py
Last active November 11, 2023 18:43
Summary Chain without LangChain
import tiktoken
import openai
from bs4 import BeautifulSoup
import requests
class OpenAISummarize(object):
def __init__(self, api_key:str="", model:str="gpt-3.5-turbo",max_words:int=200,max_sections:int=2,deployment_id:str="", api_version:str="", api_base:str="" ) -> None:
self.api_key = api_key
self.deployment_id = deployment_id
self.api_version = api_version
@ranfysvalle02
ranfysvalle02 / autogen-demo.py
Created November 7, 2023 08:18
Autogen to Visualize CSV information automagically
from autogen.agentchat.contrib.retrieve_assistant_agent import RetrieveAssistantAgent
from autogen.agentchat.contrib.retrieve_user_proxy_agent import RetrieveUserProxyAgent
import autogen
config_list = [
{
'model': 'gpt-3.5-turbo',
'api_key': 'sk-',
},
]
@ranfysvalle02
ranfysvalle02 / openai-v1.py
Last active November 7, 2023 04:54
OpenAI Assistants
from openai import AzureOpenAI
from openai import OpenAI
#v1 beta openai https://github.com/openai/openai-python/discussions/631
#assistants: https://platform.openai.com/docs/assistants/how-it-works
#AZURE
# gets the API Key from environment variable AZURE_OPENAI_API_KEY
client = AzureOpenAI(
api_version="2023-09-01-preview",
azure_endpoint="https://.openai.azure.com",
@ranfysvalle02
ranfysvalle02 / Council-AI-Routing.py
Created October 31, 2023 02:16
Council-AI-Routing.py
from council.agents import Agent
from council.chains import Chain
from council.llm import AzureLLM
from council.skills import LLMSkill
from council.agents import Agent
from council.filters import BasicFilter
from council.controllers import LLMController
from council.evaluators import LLMEvaluator
import os
@ranfysvalle02
ranfysvalle02 / MDBAgent.py
Created October 30, 2023 01:17
ActionWeaver Agent for MongoDB Atlas
import itertools
import openai
from actionweaver.llms.openai.chat import OpenAIChatCompletion
from actionweaver import action, RequireNext,SelectOne
openai.api_key = "sk-" #os.getenv("OPENAI_API_KEY")
from pymongo import MongoClient
import json
connection_string="mongodb+srv://abc123:[email protected]/?retryWrites=true&w=majority"
mongodb_client = MongoClient(connection_string)