-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
58 additions
and
67,626 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,41 @@ | ||
from langchain.chains.api.base import APIChain | ||
from langchain_openai import ChatOpenAI | ||
from langchain_openai import OpenAIEmbeddings,ChatOpenAI | ||
from langchain_community.document_loaders import TextLoader | ||
from langchain.text_splitter import CharacterTextSplitter | ||
from langchain.prompts import ChatPromptTemplate | ||
from langchain.schema.runnable import RunnablePassthrough | ||
from langchain.schema.output_parser import StrOutputParser | ||
import weaviate | ||
from langchain_weaviate.vectorstores import WeaviateVectorStore | ||
llm=ChatOpenAI(model="gpt-4o") | ||
loader=TextLoader(r"C:\Users\welcome\OneDrive\Documents\GitHub\LLMtutorial\tutorial78\test.txt") | ||
docs=loader.load() | ||
text_splitter=CharacterTextSplitter(chunk_size=500,chunk_overlap=0) | ||
document=text_splitter.split_documents(docs) | ||
|
||
llm = ChatOpenAI(model="gpt-4o") | ||
|
||
api_docs = """ | ||
BASE_URL: http://localhost:8000/ | ||
API Documentation: | ||
The API endpoint /get/zip_code/{city} Used to find informatin about the zip code for the given us city. All URL parameters are listed below: | ||
- city: Name of city - Ex: Camuy, Maricao | ||
The API endpoint /get/state_name/{id}} Uesd to find information about the state name for the given state code. All URL parameters are listed below: | ||
- id: 2 letter usa state code. Example: PR,VI | ||
URL = "https://test-2lt4id2i.weaviate.network" | ||
APIKEY = "DnmmkH4txFMUr6UnAg0SCBbOSeuzaLANxhqF" | ||
|
||
# Connect to a WCS instance | ||
client = weaviate.connect_to_wcs( | ||
cluster_url=URL, | ||
auth_credentials=weaviate.auth.AuthApiKey(APIKEY)) | ||
# vs=WeaviateVectorStore.from_documents(document,embedding=OpenAIEmbeddings(),client=client) | ||
vs=WeaviateVectorStore(client=client,index_name="LangChain_65700351ec2b4baf889198b62eeb6e13",embedding=OpenAIEmbeddings(),text_key="text") | ||
retriever=vs.as_retriever() | ||
template= """You are an assistant for question-answering tasks. | ||
Use the following pieces of retrieved context to answer the question. | ||
If you don't know the answer, just say that you don't know. | ||
Use five sentences minimum and keep the answer concise. | ||
Question: {question} | ||
Context: {context} | ||
Answer: | ||
""" | ||
|
||
chain = APIChain.from_llm_and_api_docs(llm, api_docs=api_docs, verbose=True,limit_to_domains=None) | ||
|
||
response=chain.run('Can you tell me zip code for about Frederiksted?') | ||
print() | ||
prompt=ChatPromptTemplate.from_template(template) | ||
rag_chain=( | ||
{"context":retriever,"question":RunnablePassthrough()} | ||
|prompt | ||
|llm | ||
|StrOutputParser() | ||
) | ||
response=rag_chain.invoke("write is the moral of this story") | ||
print(response) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
**The Tale of Prince John** | ||
|
||
Once upon a time, in the heart of the ancient kingdom of Aldoria, there lived a noble and kind-hearted prince named John. Aldoria was a land of lush forests, towering mountains, and sparkling rivers, where peace and prosperity reigned under the wise rule of King Edmund and Queen Isabella, John's beloved parents. | ||
|
||
Prince John was admired by all for his courage, intelligence, and compassion. From a young age, he was taught the arts of diplomacy, combat, and governance, preparing him for the day he would ascend to the throne. Despite his royal duties, John had a deep love for the natural world and often spent his free time exploring the kingdom’s enchanting landscapes, helping the villagers, and learning their stories. | ||
|
||
One fateful day, news arrived that a dark sorcerer named Malakar had risen in the distant mountains, threatening to cast a shadow over Aldoria. Malakar, with his formidable magic and army of enchanted creatures, sought to conquer the kingdom and enslave its people. The threat was imminent, and the once-peaceful realm now faced the dire prospect of war. | ||
|
||
Determined to protect his homeland, Prince John embarked on a perilous journey to confront Malakar. Armed with his trusted sword, Valor, and accompanied by his loyal companions – Sir Gareth, a brave knight, and Elara, a skilled archer with magical abilities – John ventured into the treacherous mountains. | ||
|
||
The journey was fraught with danger. The trio faced numerous challenges: crossing raging rivers, battling fierce beasts, and navigating through dark, enchanted forests. Along the way, they encountered allies who joined their cause – a wise old wizard named Merlin, a fierce warrior named Kael, and a group of rebels who had been oppressed by Malakar's tyranny. | ||
|
||
As they approached Malakar’s fortress, the final battle loomed. Prince John and his companions stormed the sorcerer’s stronghold, fighting valiantly against Malakar’s minions. The climactic showdown between John and Malakar was a fierce clash of might and magic. With the help of his friends and the strength of his convictions, John was able to overcome the dark sorcerer, breaking his spell over the land. | ||
|
||
With Malakar defeated, peace was restored to Aldoria. The people hailed Prince John as a hero, celebrating his bravery and leadership. Upon returning to the capital, he was greeted with great joy and gratitude by his parents and the kingdom’s citizens. | ||
|
||
Years later, as King John, he ruled Aldoria with wisdom and compassion, just as his parents had taught him. His reign was marked by justice, prosperity, and the continued protection of the natural beauty of the kingdom. The tale of Prince John’s courage and the defeat of Malakar became a cherished legend, inspiring future generations to uphold the values of bravery, kindness, and the enduring fight against darkness. | ||
|
||
And so, the kingdom of Aldoria thrived, a beacon of hope and harmony, all thanks to the noble heart of Prince John. |
Binary file not shown.
Oops, something went wrong.