Skip to content

Instantly share code, notes, and snippets.

View fsndzomga's full-sized avatar

Franck Stéphane Ndzomga fsndzomga

View GitHub Profile
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
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
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',
docs = WebBaseLoader(url).load()
text_splitter = RecursiveCharacterTextSplitter()
documents = text_splitter.split_documents(docs)
url = "https://www.ibm.com/topics/artificial-intelligence"
model = ChatOpenAI(model="gpt-4", api_key=os.getenv("OPENAI_API_KEY"))
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
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
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)
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")
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