This file contains hidden or 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
const puppeteer = require('puppeteer'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const OpenAI = require('openai'); | |
const dotenv = require('dotenv'); | |
dotenv.config(); | |
// Initialize OpenAI Client | |
const client = new OpenAI({ |
This file contains hidden or 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
import numpy as np | |
import math | |
# Function to generate polynomial features | |
def generate_polynomial_features(x, degree): | |
features = np.zeros((len(x), degree)) | |
for i in range(degree): | |
features[:, i] = np.power(x, i + 1) | |
return features |
This file contains hidden or 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
import dspy | |
from dspy.functional import TypedPredictor | |
import os | |
from dotenv import load_dotenv | |
from transitions import Machine | |
# Load the OpenAI API key from the .env file | |
load_dotenv() | |
# Create a language model using the OpenAI API |
This file contains hidden or 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
import dspy | |
from dspy.functional import TypedPredictor | |
import os | |
from dotenv import load_dotenv | |
from transitions import Machine | |
load_dotenv() | |
llm = dspy.OpenAI( | |
model='gpt-3.5-turbo', |
This file contains hidden or 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
docs = WebBaseLoader(url).load() | |
text_splitter = RecursiveCharacterTextSplitter() | |
documents = text_splitter.split_documents(docs) |
This file contains hidden or 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
url = "https://www.ibm.com/topics/artificial-intelligence" | |
model = ChatOpenAI(model="gpt-4", api_key=os.getenv("OPENAI_API_KEY")) |
This file contains hidden or 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
from langchain_openai import ChatOpenAI | |
from dotenv import load_dotenv | |
import os | |
from langchain_community.document_loaders import WebBaseLoader | |
from langchain_openai import OpenAIEmbeddings | |
from langchain_community.vectorstores.faiss import FAISS | |
from langchain_text_splitters import RecursiveCharacterTextSplitter | |
from langchain.tools.retriever import create_retriever_tool | |
from langchain_community.tools.tavily_search import TavilySearchResults | |
from langchain import hub |
This file contains hidden or 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
import dspy | |
import os | |
from dotenv import load_dotenv | |
load_dotenv() | |
llm = dspy.OpenAI( | |
model='gpt-4', | |
api_key=os.environ['OPENAI_API_KEY'], | |
max_tokens=100 |
This file contains hidden or 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
class logical_reasoner(dspy.Module): | |
def __init__(self): | |
super().__init__() | |
self.logical_reasoner = dspy.Predict("text -> premises, conclusions") | |
self.checker = dspy.ChainOfThought(check_logic) | |
def forward(self,text): | |
prediction = self.logical_reasoner(text=text) | |
result = self.checker(premises=prediction.premises, conclusions=prediction.conclusions) |
This file contains hidden or 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
class check_logic(dspy.Signature): | |
"""Given the premises and the conclusions of an argument, check if the conclusions are logical.""" | |
premises = dspy.InputField(desc="Premises of the argument") | |
conclusions = dspy.InputField(desc="Conclusion of the argument") | |
logical = dspy.OutputField(desc="Given the premises, the conclusion is logical or not") |
NewerOlder