import datetime
import openai
import os
import sys
from dotenv import load_dotenv
from langchain.document_loaders import WebBaseLoader
load_dotenv("azure.env")
# Azure Open AI
openai.api_type: str = "azure"
openai.api_key = os.getenv("OPENAI_API_KEY")
openai.api_base = os.getenv("OPENAI_API_BASE")
openai.api_version = os.getenv("OPENAI_API_VERSION")
print("Open AI version:", openai.__version__)
Open AI version: 0.28.1
print("Today is:", datetime.datetime.today().strftime("%d-%b-%Y %H:%M:%S"))
Today is: 12-Oct-2023 14:42:47
sys.version
'3.10.10 (main, Mar 21 2023, 18:45:11) [GCC 11.2.0]'
model = "gpt-4-32k"
def askgpt4(question, usetext=True):
"""
Ask Azure Open AI GPT4 model
"""
if usetext:
prompt = question + "\n" + text
else:
prompt = question
response = openai.ChatCompletion.create(
engine=model,
messages=[
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": prompt},
],
)
return response["choices"][0]["message"]["content"]
askgpt4("Who are you?", usetext=False)
'I am an artificial intelligence assistant designed to help answer your questions, provide information, and assist with various tasks.'
url = "https://medium.com/microsoftazure/introducing-langchain-agents-e58674b1a657"
loader = WebBaseLoader(url)
docs = loader.load()
text = " ".join(doc.page_content for doc in docs)
answer = askgpt4("Can you summarize this article?")
print(answer)
The article introduces LangChain Agents, which are systems powered by Large Language Models (LLMs) integrated with a set of tools like search engines, databases, websites, etc. These agents plan and execute actions based on user input to fulfill the request. This concept is critical because current LLMs, like GPT-3.5-turbo and GPT-4, are limited to knowledge they've been trained on and cannot obtain information from other sources. Two main types of LangChain Agents include Action Agents, which decide an action and execute it step-by-step, and Plan and Execute Agents, which use more sophisticated approach for complex tasks. The article further details how to go about implementing these agents with Azure OpenAI and Python using LangChain, a lightweight SDK that makes it easier to manage and integrate LLMs into applications.
answer = askgpt4("Who is the author of this article?")
print(answer)
The author of the article "Introducing LangChain Agents. An implementation with Azure OpenAI and…" is Valentina Alto.
answer = askgpt4("Can you write a Tweeter post with some emojis?")
print(answer)
"Exploring the power of AI with LangChain and Azure OpenAI. Generative models will revolutionize the way we interact with data. Join the journey! 🚀 #AI #OpenAI #DataScience #Innovation #LangChain"
answer = askgpt4("How many words in this article? Just display the result.")
print(answer)
The text provided contains 1938 words.
answer = askgpt4("Generate some keywords to classify this article?")
print(answer)
Azure OpenAI, LangChain Agents, ChatGPT, GPT-3.5-turbo, GPT-4, LangChain SDK, Language Models, Machine Learning, AI, Python, Data Science.
answer = askgpt4(
"Could you classify this article between GENERATIVE AI, ORACLE, GIS, TYPESCRIPT?"
)
print(answer)
The article belongs to the category of GENERATIVE AI as it discusses the concept of Large Language Models (LLMs) like GPT-3.5-turbo and GPT-4, their limitations, and introduces the concept of Agents which can be seen as applications powered by LLMs and integrated with a set of tools for enhanced functionality.
answer = askgpt4("What is the programming language used?")
print(answer)
The programming language used for OpenAI GPT-3 is Python.