Use watsonx, Elasticsearch, and LangChain to answer questions (RAG)¶
Disclaimers¶
- Use only Projects and Spaces that are available in watsonx context.
Notebook content¶
This notebook contains the steps and code to demonstrate support of Retrieval Argumented Generation in watsonx.ai. It introduces commands for data retrieval, knowledge base building & querying, and model testing.
Following this, an AI service is created based on the previously constructed application.
Some familiarity with Python is helpful. This notebook uses Python 3.11.
About Retrieval Augmented Generation¶
Retrieval Augmented Generation (RAG) is a versatile pattern that can unlock a number of use cases requiring factual recall of information, such as querying a knowledge base in natural language.
In its simplest form, RAG requires 3 steps:
- Index knowledge base passages (once)
- Retrieve relevant passage(s) from knowledge base (for every user query)
- Generate a response by feeding retrieved passage into a large language model (for every user query)
Contents¶
This notebook contains the following parts:
Set up the environment¶
Before you use the sample code in this notebook, you must perform the following setup tasks:
- Create a Watson Machine Learning (WML) Service instance (a free plan is offered and information about how to create the instance can be found here).
Install and import the datasets
and dependencies¶
!pip install wget | tail -n 1
!pip install pandas | tail -n 1
!pip install humanize | tail -n 1
!pip install -U "langchain>=0.3,<0.4" | tail -n 1
!pip install -U "ibm_watsonx_ai>=1.1.22" | tail -n 1
!pip install -U "langchain_ibm>=0.3,<0.4" | tail -n 1
!pip install -U "langchain-huggingface>=0.1,<0.2" | tail -n 1
!pip install -U "langchain-elasticsearch>=0.3,<0.4" | tail -n 1
import os
import random
import getpass
import pandas as pd
import humanize
Define the WML credentials¶
Use the code cell below to define the WML credentials that are required to work with watsonx Foundation Model inferencing.
Action: Provide the IBM Cloud user API key. For details, see Managing user API keys.
from ibm_watsonx_ai import Credentials
credentials = Credentials(
url="https://us-south.ml.cloud.ibm.com",
api_key=getpass.getpass("Enter your WML API key and hit enter: "),
)
Working with spaces¶
You need to create a space that will be used for your work. If you do not have a space, you can use Deployment Spaces Dashboard to create one.
- Click New Deployment Space
- Create an empty space
- Select Cloud Object Storage
- Select Watson Machine Learning instance and press Create
- Go to Manage tab
- Copy
Space GUID
and paste it below
Tip: You can also use SDK to prepare the space for your work. More information can be found here.
Action: assign space ID below
try:
space_id = os.environ["SPACE_ID"]
except KeyError:
space_id = input("Please enter your project_id (hit enter): ")
Create an instance of APIClient with authentication details.
from ibm_watsonx_ai import APIClient
api_client = APIClient(credentials=credentials, space_id=space_id)
Test data loading¶
Download the test dataset. This dataset is used to calculate the metrics score for selected model, defined prompts and parameters.
import wget
questions_test_filename = 'questions_test.csv'
questions_train_filename = 'questions_train.csv'
questions_test_url = 'https://raw.github.com/IBM/watson-machine-learning-samples/master/cloud/data/RAG/questions_test.csv'
questions_train_url = 'https://raw.github.com/IBM/watson-machine-learning-samples/master/cloud/data/RAG/questions_train.csv'
if not os.path.isfile(questions_test_filename):
wget.download(questions_test_url, out=questions_test_filename)
if not os.path.isfile(questions_train_filename):
wget.download(questions_train_url, out=questions_train_filename)
filename_test = './questions_test.csv'
filename_train = './questions_train.csv'
test_data = pd.read_csv(filename_test)
train_data = pd.read_csv(filename_train)
Inspect data sample
train_data.head()
qid | question | answers | |
---|---|---|---|
0 | 1961 | where does diffusion occur in the excretory sy... | diffusion |
1 | 7528 | when did the us join world war one | April 6 , 1917 |
2 | 8685 | who played wilma in the movie the flintstones | Elizabeth Perkins |
3 | 6716 | when was the office of the vice president created | 1787 |
4 | 2916 | where does carbon fixation occur in c4 plants | in the mesophyll cells |
Build up knowledge base¶
The current state-of-the-art in RAG is to create dense vector representations of the knowledge base in order to calculate the semantic similarity to a given user query.
We can generate dense vector representations using embedding models. In this notebook, we use all-MiniLM-L6-v2
to embed both the knowledge base passages and user queries.
A vector database is optimized for dense vector indexing and retrieval. This notebook uses Elasticsearch, a distributed, RESTful search and analytics engine, capable of performing both vector and lexical search. It is built on top of the Apache Lucene library, which offers good speed and performance with all-MiniLM-L6-v2
embedding model.
Load knowledge base documents¶
Load set of documents used further to build knowledge base.
knowledge_base_dir = "./knowledge_base"
my_path = f"{os.getcwd()}/knowledge_base"
if not os.path.isdir(my_path):
os.makedirs(my_path)
documents_filename = 'knowledge_base/psgs.tsv'
documents_url = 'https://raw.github.com/IBM/watson-machine-learning-samples/master/cloud/data/RAG/psgs.tsv'
if not os.path.isfile(documents_filename):
wget.download(documents_url, out=documents_filename)
documents = pd.read_csv(f"{knowledge_base_dir}/psgs.tsv", sep='\t', header=0, nrows=1000)
documents['indextext'] = documents['title'].astype(str) + "\n" + documents['text']
from langchain_core.documents import Document
lc_documents = [Document(page_content=text, metadata={"id": doc_id})
for text, doc_id in zip(documents['indextext'], documents['id'])]
Create an embedding function¶
Note that you can feed a custom embedding function to be used by Elasticsearch. The performance of Elasticsearch may differ depending on the embedding model used.
from langchain_huggingface import HuggingFaceEmbeddings
emb_func = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
Foundation Models on watsonx¶
Defining model¶
You need to specify model_id
that will be used for inferencing:
text_model_id = api_client.foundation_models.TextModels.FLAN_UL2
Defining the model parameters¶
We need to provide a set of model parameters that will influence the result:
from ibm_watsonx_ai.metanames import GenTextParamsMetaNames as GenParams
from ibm_watsonx_ai.foundation_models.utils.enums import DecodingMethods
parameters = {
GenParams.DECODING_METHOD: DecodingMethods.GREEDY,
GenParams.MIN_NEW_TOKENS: 1,
GenParams.MAX_NEW_TOKENS: 50
}
Initialize the WatsonxLLM
class.¶
WatsonxLLM
is a wrapper around watsonx.ai models that provide chain integration around the models.
Action: For more details about CustomLLM
check the LangChain documentation
from langchain_ibm import WatsonxLLM
watsonx_llm = WatsonxLLM(
model_id=text_model_id,
url=credentials.get("url"),
apikey=credentials.get("apikey"),
space_id=space_id,
params=parameters
)
Set up connectivity information to Elasticsearch¶
This notebook focuses on self-managed cluster using IBM Cloud® Databases for Elasticsearch.
The following cell retrieves the Elasticsearch url, username, password and ssl_certificate (base_64) and prompts you to provide them manually in case of failure.
You can provide a connection asset ID to read all required connection data from it. Before doing so, make sure that a connection asset was created in your space.
elasticsearch_connection_id = input("Provide connection asset ID in your space. Skip this, if you wish to type credentials by hand and hit enter: ") or None
if elasticsearch_connection_id is None:
elasticsearch_url = input("Please enter your Elasticsearch url name and hit enter: ")
username = input("Please enter your Elasticsearch user name and hit enter: ")
password = getpass.getpass("Please enter your Elasticsearch password and hit enter: ")
ssl_certificate = input("Please enter your Elasticsearch ssl certificate (base64) and hit enter: ")
elasticsearch_data_source_type_id = api_client.connections.get_datasource_type_uid_by_name(
"elasticsearch"
)
connections_details = api_client.connections.create(
{
api_client.connections.ConfigurationMetaNames.NAME: "elasticsearch Connection",
api_client.connections.ConfigurationMetaNames.DESCRIPTION: "Connection created by the sample notebook",
api_client.connections.ConfigurationMetaNames.DATASOURCE_TYPE: elasticsearch_data_source_type_id,
api_client.connections.ConfigurationMetaNames.PROPERTIES: {
"url": elasticsearch_url,
"username": username,
"password": password,
"use_anonymous_access": "false",
"ssl_certificate": ssl_certificate,
},
}
)
elasticsearch_connection_id = api_client.connections.get_id(connections_details)
We first create a regular Elasticsearch Python client connection using watsonx's VectorStore comeponent.
from datetime import datetime
index_name = f"elastic_index_{datetime.now().strftime('%Y_%m_%d_%H%M%S')}"
index_name
'elastic_index_2024_11_05_114707'
from ibm_watsonx_ai.foundation_models.extensions.rag.vector_stores.vector_store import VectorStore
knowledge_base = VectorStore(
api_client,
connection_id=elasticsearch_connection_id,
embeddings=emb_func,
index_name=index_name,
)
elasticsearch_client = knowledge_base.get_client().client
Embed and index documents with Elasticsearch¶
Note: Could take several minutes if you don't have pre-built indices
stored_documents = knowledge_base.add_documents(content=lc_documents)
Let's take a look in Elasticsearch what the LangChain wrapper has created. First we display the newly created index ("tables" in Elasticsearch are always called "index"). Note the field vector
of type dense_vector
with dot_product
similarity.
dict(elasticsearch_client.indices.get(index=index_name))
{'elastic_index_2024_11_05_114707': {'aliases': {}, 'mappings': {'properties': {'metadata': {'properties': {'id': {'type': 'long'}}}, 'text': {'type': 'text', 'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}}, 'vector': {'type': 'dense_vector', 'dims': 384}}}, 'settings': {'index': {'routing': {'allocation': {'include': {'_tier_preference': 'data_content'}}}, 'allocation': {'max_retries': '15'}, 'number_of_shards': '1', 'provided_name': 'elastic_index_2024_11_05_114707', 'creation_date': '1730803645647', 'unassigned': {'node_left': {'delayed_timeout': '60m'}}, 'number_of_replicas': '1', 'uuid': 'Ch7PbkhcQu-9T0FbiJl0Qw', 'version': {'created': '8070099'}}}}}
Verify the number of documents loaded into the Elasticsearch index.
doc_count = knowledge_base.count()
doc_count
1000
Let's retrieve a random document as a sample. Note the embedding in the vector field, that was generated with the watsonx embedding model.
elasticsearch_client.search(index=index_name).get("hits").get("hits")[random.randint(0, elasticsearch_client.search(index=index_name).get("took"))]
Display the total size and indexing time of the new index in Elasticsearch.
index_stats = elasticsearch_client.indices.stats(index=index_name).get('_all').get('primaries')
print("Index size: " + humanize.naturalsize(index_stats.get('store').get('size_in_bytes')))
print("Indexing time: " + humanize.precisedelta(index_stats.get('indexing').get('index_time_in_millis')/1000, minimum_unit='minutes'))
Index size: 9.4 MB Indexing time: 0 minutes
Generate a retrieval-augmented response to a question¶
RetrievalQA
is a chain to do question answering.
Select questions¶
The prompts we will use to test the RAG flow
questions_and_answers = {
"names of founding fathers of the united states?":"Thomas Jefferson::James Madison::John Jay::George Washington::John Adams::Benjamin Franklin::Alexander Hamilton",
"who played in the super bowl in 2013?":"Baltimore Ravens::San Francisco 49ers",
"when did bucharest become the capital of romania?":"1862"
}
Retrieve relevant context¶
Fetch paragraphs similar to the question
from langchain.chains.retrieval_qa.base import RetrievalQA
qa = RetrievalQA.from_chain_type(llm=watsonx_llm, chain_type="stuff", retriever=knowledge_base.as_langchain_retriever(), return_source_documents=True)
results_1 = []
for question in questions_and_answers.keys():
result = qa.invoke({"query": question})
results_1.append(result)
Get the set of chunks for one of the questions.
for idx, result in enumerate(results_1):
print("=========")
print("Question = ", result['query'])
print("Answer = ", result['result'])
print("Expected Answer(s) (may not be appear with exact wording in the dataset) = ", questions_and_answers[result['query']])
print("\n")
print("Source documents:")
print(*(x.page_content for x in result['source_documents']), sep='\n')
print("\n")
========= Question = names of founding fathers of the united states? Answer = John Adams , Benjamin Franklin , Alexander Hamilton , John Jay , Thomas Jefferson , James Madison , and George Washington Expected Answer(s) (may not be appear with exact wording in the dataset) = Thomas Jefferson::James Madison::John Jay::George Washington::John Adams::Benjamin Franklin::Alexander Hamilton Source documents: Founding Fathers of the United States ^ Burstein , Andrew . `` Politics and Personalities : Garry Wills takes a new look at a forgotten founder , slavery and the shaping of America '' , Chicago Tribune ( November 09 , 2003 ) : `` Forgotten founders such as Pickering and Morris made as many waves as those whose faces stare out from our currency . '' ^ Jump up to : Rafael , Ray . The Complete Idiot 's Guide to the Founding Fathers : And the Birth of Our Nation ( Penguin , 2011 ) . Jump up ^ `` Founding Fathers : Virginia '' . FindLaw Constitutional Law Center . 2008 . Retrieved 2008 - 11 - 14 . Jump up ^ Schwartz , Laurens R. Jews and the American Revolution : Haym Solomon and Others , Jefferson , North Carolina : McFarland & Co. , 1987 . Jump up ^ Kendall , Joshua . The Forgotten Founding Father : Noah Webster 's Obsession and the Creation of an American Culture ( Penguin 2011 ) . Jump up ^ Wright , R.E. ( 1996 ) . `` Thomas Willing ( 1731 - 1821 ) : Philadelphia Financier and Forgotten Founding Father '' . Pennsylvania History . 63 ( 4 ) : 525 -- 560 . doi : 10.2307 / 27773931 ( inactive 2017 - 01 - 15 ) . JSTOR 27773931 . Jump up ^ `` A Patriot of Early New England '' , New York Times ( December 20 , 1931 ) Founding Fathers of the United States President of Congress Peyton Randolph New Hampshire John Sullivan Nathaniel Folsom Massachusetts Bay Thomas Cushing Samuel Adams John Adams Robert Treat Paine Rhode Island Stephen Hopkins Samuel Ward Connecticut Eliphalet Dyer Roger Sherman Silas Deane New York Isaac Low John Alsop John Jay James Duane Philip Livingston William Floyd Henry Wisner Simon Boerum New Jersey James Kinsey William Livingston Stephen Crane Richard Smith John De Hart Pennsylvania Joseph Galloway John Dickinson Charles Humphreys Thomas Mifflin Edward Biddle John Morton George Ross The Lower Counties Caesar Rodney Thomas McKean George Read Maryland Matthew Tilghman Thomas Johnson , Junr William Paca Samuel Chase Virginia Richard Henry Lee George Washington Patrick Henry , Junr Richard Bland Benjamin Harrison Edmund Pendleton North Carolina William Hooper Joseph Hewes Richard Caswell South Carolina Henry Middleton Thomas Lynch Christopher Gadsden John Rutledge Edward Rutledge See also Virginia Association First Continental Congress Carpenters ' Hall Declaration and Resolves of the First Continental Congress Retrieved from `` https://en.wikipedia.org/w/index.php?title=Founding_Fathers_of_the_United_States&oldid=815247535 '' Categories : Age of Enlightenment American Revolution Articles about multiple people Patriots in the American Revolution Political leaders of the American Revolution National founders Hidden categories : Webarchive template wayback links Pages with DOIs inactive since 2017 Use mdy dates from April 2011 Talk Read Contents About Wikipedia Wikiquote Bân - lâm - gú Башҡортса Bikol Central Български Brezhoneg Català Čeština Cymraeg Deutsch Ελληνικά Español Esperanto فارسی Français 한국어 Հայերեն हिन्दी Ido Bahasa Indonesia Interlingua Íslenska Italiano עברית Latina Lietuvių Magyar Bahasa Melayu Nederlands 日本 語 Norsk Polski Português Română Founding Fathers of the United States Founding Fathers of the United States - wikipedia Founding Fathers of the United States Jump to : navigation , search Declaration of Independence , a painting by John Trumbull depicting the Committee of Five presenting their draft to the Congress on June 28 , 1776 Signature page of Treaty of Paris ( 1783 ) ; the treaty was negotiated by John Adams , Benjamin Franklin and John Jay . The Founding Fathers of the United States were those individuals of the Thirteen Colonies in North America who led the American Revolution against the authority of the British Crown in word and deed and contributed to the establishment of the United States of America . Historian Richard B. Morris in 1973 identified the following seven figures as the key Founding Fathers : John Adams , Benjamin Franklin , Alexander Hamilton , John Jay , Thomas Jefferson , James Madison , and George Washington . Adams , Jefferson , and Franklin were members of the Committee of Five that drafted the Declaration of Independence . Hamilton , Madison , and Jay were authors of The Federalist Papers , advocating ratification of the Constitution . The constitutions drafted by Jay and Adams for their respective states of New York ( 1777 ) and Massachusetts ( 1780 ) were heavily relied upon when creating language for the US Constitution Jay , Adams and Franklin negotiated the Treaty of Paris ( 1783 ) that would end the American Revolutionary War . Washington was Commander - Founding Fathers of the United States Prior to , and during the 19th century , they were referred to as simply the `` Fathers '' . The term has been used to describe the founders and first settlers of the original royal colonies . Contents ( hide ) 1 Background 2 Interesting facts and commonalities 2.1 Education 2.1. 1 Colleges attended 2.1. 2 Advanced degrees and apprenticeships 2.1. 2.1 Doctors of medicine 2.1. 2.2 Theology 2.1. 2.3 Legal apprenticeships 2.1. 3 Self - taught or little formal education 2.2 Demographics 2.3 Political experience 2.4 Occupations and finances 2.5 Religion 2.6 Ownership of slaves and position on slavery 2.7 Attendance at conventions 2.8 Spouses and children 2.9 Charters of freedom and historical documents of the United States 2.10 Post-constitution life 2.11 Youth and longevity 2.12 Founders who were not signatories or delegates 3 Legacy 3.1 Institutions formed by Founders 3.2 Scholarship on the Founders 3.2. 1 Living historians whose focus is the Founding Fathers 3.2. 2 Noted collections of the Founding Fathers 3.3 In stage and film 3.4 Children 's books 4 See also 5 Notes 6 References 7 External links Background ( edit ) The Albany Congress of 1754 was a conference attended by seven colonies , which presaged later efforts at cooperation . The Stamp Act Congress of 1765 included representatives from nine colonies . The First Continental Congress met briefly in Philadelphia , Pennsylvania in 1774 , consisting of fifty - six delegates from twelve of the thirteen colonies ( excluding Georgia ) that ========= Question = who played in the super bowl in 2013? Answer = Baltimore Ravens Expected Answer(s) (may not be appear with exact wording in the dataset) = Baltimore Ravens::San Francisco 49ers Source documents: Super Bowl XLVII responded to the claim on Twitter in jest , tweeting `` There is no conspiracy . I pulled the plug . '' Box score ( edit ) Super Bowl XLVII : Baltimore Ravens 34 , San Francisco 49ers 31 Total Ravens ( AFC ) 7 14 7 6 34 49ers ( NFC ) 17 8 31 at Mercedes - Benz Superdome in New Orleans , Louisiana Date : February 3 , 2013 Game time : 5 : 31 p.m. CST Game weather : Played indoors ( dome stadium ) Game attendance : 71,024 Referee : Jerome Boger TV announcers ( CBS ) : Jim Nantz , Phil Simms , Steve Tasker , Solomon Wilcots Gamebook ( hide ) Scoring summary Quarter Time Drive Team Scoring information Score Plays Yards TOP BAL SF 10 : 36 6 51 2 : 29 BAL Anquan Boldin 13 - yard touchdown reception from Joe Flacco , Justin Tucker kick good 7 0 3 : 58 12 62 6 : 38 SF 36 - yard field goal by David Akers 7 7 : 10 10 75 4 : 43 BAL Dennis Pitta 1 - yard touchdown reception from Flacco , Tucker kick good 14 1 : 45 56 0 : 22 BAL Jacoby Jones 56 - yard touchdown reception from Flacco , Tucker kick good 21 0 : 00 8 71 1 : 45 SF 27 - yard field goal by Akers 21 6 14 : 49 -- -- -- BAL J. Jones 108 - Super Bowl XLVII for the 2012 season . The Ravens defeated the 49ers by the score of 34 -- 31 , handing the 49ers their first Super Bowl loss in franchise history . The game was played on February 3 , 2013 , at Mercedes - Benz Superdome in New Orleans , Louisiana . This was the tenth Super Bowl to be played in New Orleans , equaling Miami 's record of ten in an individual city . For the first time in Super Bowl history , the game featured two brothers coaching against each other -- Jim and John Harbaugh , head coaches of the San Francisco 49ers and Baltimore Ravens , respectively -- earning it the nickname Harbaugh Bowl . In addition , Super Bowl XLVII was the first to feature two teams that had undefeated records in previous Super Bowl games ( Baltimore , 1 -- 0 ; San Francisco , 5 -- 0 ) . The 49ers , who posted a regular - season record of 11 -- 4 -- 1 , entered the game seeking their sixth Super Bowl win in team history ( and first since Super Bowl XXIX at the end of the 1994 season ) , which would have tied the Pittsburgh Steelers for the most by a franchise . The Ravens , who posted a 10 -- 6 regular - season record , made their second Super Bowl appearance in 12 years , having previously won Super Bowl XXXV . Ray Lewis , the Super Bowl XLVII preview : A minute - by - minute breakdown '' . USA Today . Retrieved February 2 , 2013 . Jump up ^ `` Beyonce half time performance '' . NFL.Com . February 4 , 2013 . Retrieved February 5 , 2013 . Jump up ^ `` Beyonce wows at half - time show '' . BBC News . February 4 , 2013 . Retrieved February 5 , 2013 . Jump up ^ `` Beyonce Draws Estimated 104 Million to Super Bowl Halftime '' . ^ Jump up to : `` Play - by - Play '' . ESPN . February 3 , 2013 . Retrieved February 4 , 2013 . Jump up ^ Inman , Cam ( February 3 , 2013 ) . `` Super Bowl 2013 : San Francisco 49ers ' furious comeback falls short in 34 -- 31 loss to Baltimore Ravens -- San Jose Mercury News '' . San Jose Mercury News . Retrieved February 4 , 2013 . ^ Jump up to : `` Jacoby Jones returns kick 108 yards '' . ESPN.com . February 4 , 2013 . Retrieved April 24 , 2016 . Jump up ^ `` Watch Baltimore Ravens vs. Denver Broncos ( 01 / 12 / 2013 ) '' . NFL . Retrieved February 4 , 2013 . ^ Jump up to : Rosenthal , Gregg ( February 3 , 2013 ) . `` Jacoby Jones ' 108 - yard return TD a Super Bowl record '' . NFL . Retrieved Super Bowl XLVII MVP Award '' . Forbes.com . February 4 , 2013 . Retrieved February 6 , 2013 . Jump up ^ Heitner , Darren ( April 18 , 2013 ) . `` Is It Worth Spending $4 Million On A Super Bowl Commercial ? '' . Forbes . Retrieved February 4 , 2013 . Jump up ^ Collins , Scott ( February 5 , 2013 ) . `` Super Bowl ratings dip slightly from last year '' . Los Angeles Times . Retrieved February 5 , 2013 . ^ Jump up to : `` New Orleans to host 10th Super Bowl in 2013 '' . ESPN.com . Associated Press . May 19 , 2009 . Retrieved January 14 , 2011 . Jump up ^ Ally Burguieres Designs Official NFL Beads with Courtyard by Marriott for SuperBowl -- WGNO -- YouTube on YouTube Jump up ^ Wilner , Barry ( January 21 , 2013 ) . `` Ravens dominate Pats , set up ' Harbaugh Bowl ' '' . NBC Sports . Associated Press . Retrieved January 21 , 2013 . Jump up ^ Brinson , Will . `` Sorting the Sunday Pile , Divisional Round : Harbaugh Bowl still lives '' . CBSSports.com . CBS Interactive . Retrieved January 21 , 2013 . Jump up ^ Schwab , Frank . `` HarBowl ! Harbaugh brothers Jim and John to square off in Super Bowl '' . Yahoo ! Sports . Retrieved January 21 , 2003 . Jump up ^ `` The ========= Question = when did bucharest become the capital of romania? Answer = 1862 Expected Answer(s) (may not be appear with exact wording in the dataset) = 1862 Source documents: Bucharest EU ) Density 9,237 / km ( 23,920 / sq mi ) Metro 2,412,530 Demonym ( s ) Bucharester ( en ) bucureștean , bucureșteancă ( ro ) Time zone UTC + 2 ( EET ) Summer ( DST ) UTC + 3 ( EEST ) Postal code 0xxxxx Area code ( s ) + 40 x1 Car plate prefix GDP ( Nominal ) € 47 billion - Per capita PPP € 40,400 -- Per capita € 20,000 Website pmb.ro Romanian law stipulates that Bucharest has a special administrative status which is equal to that of a County ; Bucharest metropolitan area is a proposed project . Bucharest ( / ˈb ( j ) uː kərɛst / ; Romanian : București ( bukuˈreʃtj ) ( listen ) ) is the capital and largest city of Romania , as well as its cultural , industrial , and financial centre . It is located in the southeast of the country , at 44 ° 25 ′ 57 '' N 26 ° 06 ′ 14 '' E / 44.43250 ° N 26.10389 ° E / 44.43250 ; 26.10389 Coordinates : 44 ° 25 ′ 57 '' N 26 ° 06 ′ 14 '' E / 44.43250 ° N 26.10389 ° E / 44.43250 ; 26.10389 , on the banks of the Dâmbovița River , less than 60 km ( 37.3 mi ) north of the Danube River and the Bulgarian border . Bucharest was first mentioned in Bucharest Bucharest - wikipedia Bucharest This article contains too many pictures , charts or diagrams for its overall length . Please help to improve this article by removing or adjusting the sandwiching of text between two images and indiscriminate galleries in accordance with the Manual of Style on use of images . ( Learn how and when to remove this template message ) Capital city in None , Romania Bucharest București Capital city From top , left to right : Central University Library Palace of the Parliament Arcul de Triumf Romanian Athenaeum Modernist skyscrapers CEC Palace Royal Palace of Bucharest Flag Coat of arms Nickname ( s ) : Micul Paris ( The Little Paris ) , Paris of the East Motto ( s ) : Patria și dreptul meu ( The Homeland and my right ) Bucharest Location of Bucharest in Romania Show map of Romania Bucharest Bucharest ( Europe ) Show map of Europe Coordinates : 44 ° 25 ′ 57 '' N 26 ° 6 ′ 14 '' E / 44.43250 ° N 26.10389 ° E / 44.43250 ; 26.10389 Country Romania County None First attested 1459 Government Mayor Gabriela Firea ( PSD ) Prefect Speranţa Cliseru Area Capital city 228 km ( 88 sq mi ) Urban 285 km ( 110 sq mi ) Elevation 55.8 -- 91.5 m ( 183.1 -- 300.2 ft ) Population ( 2011 ) Capital city 1,883,425 Estimate ( 2016 ) 2,106,144 Rank 1st in Romania ( 6th in Bucharest destroying a third of the city . Ottoman massacre of Greek irregulars in Bucharest ( August , 1821 ) In 1862 , after Wallachia and Moldavia were united to form the Principality of Romania , Bucharest became the new nation 's capital city . In 1881 , it became the political centre of the newly proclaimed Kingdom of Romania under King Carol I. During the second half of the 19th century , the city 's population increased dramatically , and a new period of urban development began . During this period , gas lighting , horse - drawn trams , and limited electrification were introduced . The Dâmbovița River was also massively channelled in 1883 , thus putting a stop to previously endemic floods like the 1865 flooding of Bucharest . The Fortifications of Bucharest were built . The extravagant architecture and cosmopolitan high culture of this period won Bucharest the nickname of `` Little Paris '' ( Micul Paris ) of the east , with Calea Victoriei as its Champs - Élysées . I.C. Brătianu Boulevard in the 1930s Between 6 December 1916 and November 1918 , the city was occupied by German forces as a result of the Battle of Bucharest , with the official capital temporarily moved to Iași , in the Moldavia region . After World War I , Bucharest became the capital of Greater Romania . In the interwar years , Bucharest 's urban development continued , with the city gaining an average of 30,000 Bucharest documents in 1459 . It became the capital of Romania in 1862 and is the centre of Romanian media , culture , and art . Its architecture is a mix of historical ( neo-classical ) , interbellum ( Bauhaus and art deco ) , communist - era and modern . In the period between the two World Wars , the city 's elegant architecture and the sophistication of its elite earned Bucharest the nickname of `` Little Paris '' ( Micul Paris ) . Although buildings and districts in the historic city centre were heavily damaged or destroyed by war , earthquakes , and above all Nicolae Ceaușescu 's program of systematization , many survived . In recent years , the city has been experiencing an economic and cultural boom . In 2016 , the historical city centre was listed as `` endangered '' by the World Monuments Watch . According to the 2011 census , 1,883,425 inhabitants live within the city limits , a decrease from the 2002 census . Adding the satellite towns around the urban area , the proposed metropolitan area of Bucharest would have a population of 2.27 million people . According to Eurostat , Bucharest has a functional urban area of 2,412,530 residents ( as of 2015 ) . Bucharest is the sixth - largest city in the European Union by population within city limits , after London , Berlin , Madrid , Rome , and Paris . Economically , Bucharest is the most prosperous
def deployable_ai_service(context, **custom):
from ibm_watsonx_ai.foundation_models.extensions.rag.vector_stores.vector_store import VectorStore
from ibm_watsonx_ai import APIClient, Credentials
from langchain.chains.retrieval_qa.base import RetrievalQA
from langchain_huggingface import HuggingFaceEmbeddings
from langchain_ibm import WatsonxLLM
from ibm_watsonx_ai.metanames import GenTextParamsMetaNames as GenParams
from ibm_watsonx_ai.foundation_models.utils.enums import DecodingMethods
space_id = custom.get("space_id")
url = custom.get("url")
elasticsearch_connection_id = custom.get("elasticsearch_connection_id")
index_name = custom.get("index_name")
text_model_id = custom.get("text_model_id")
api_client = APIClient(
credentials=Credentials(url=url, token=context.generate_token()),
space_id=space_id
)
wx_parameters = {
GenParams.DECODING_METHOD: DecodingMethods.GREEDY,
GenParams.MIN_NEW_TOKENS: 1,
GenParams.MAX_NEW_TOKENS: 50
}
watsonx_llm = WatsonxLLM(
model_id=text_model_id,
watsonx_client=api_client,
params=wx_parameters
)
emb_func = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
knowledge_base = VectorStore(
api_client=api_client,
connection_id=elasticsearch_connection_id,
embeddings=emb_func,
index_name=index_name,
)
qa = RetrievalQA.from_chain_type(llm=watsonx_llm, chain_type="stuff", retriever=knowledge_base.as_langchain_retriever(), return_source_documents=True)
def generate(context) -> dict:
api_client.set_token(context.get_token())
payload = context.get_json()
questions_and_answers = payload["questions_and_answers"]
results = []
for question in questions_and_answers.keys():
result = qa.invoke({"query": question})
results.append(result)
for res in results:
for ind in range(len(res["source_documents"])):
res["source_documents"][ind] = res["source_documents"][ind].to_json()
response_body = {
"query": questions_and_answers,
"result": results,
}
return {"body": response_body}
return generate
There is also possibility to create streaming service
def deployable_ai_service(context, **custom):
...
def generate(context) -> dict:
...
return {"body": ...}
def generate_stream(context) -> Iterator:
...
yield ...
return generate, generate_stream
Testing AI service's function locally¶
You can test AI service function locally. Initialise RuntimeContext
firstly.
from ibm_watsonx_ai.deployments import RuntimeContext
context = RuntimeContext(api_client=api_client)
context.request_payload_json = {"questions_and_answers": questions_and_answers}
kwargs = {
"space_id": api_client.default_space_id,
"url": api_client.credentials.url,
"elasticsearch_connection_id": elasticsearch_connection_id,
"index_name": index_name,
"text_model_id": text_model_id,
}
resp = deployable_ai_service(context=context, **kwargs)(context)
for idx, result in enumerate(resp["body"]["result"]):
print("=========")
print("Question = ", result['query'])
print("Answer = ", result['result'])
print("Expected Answer(s) (may not be appear with exact wording in the dataset) = ", questions_and_answers[result['query']])
print("\n")
print("Source documents:")
print(*(x.get("kwargs").get("page_content") for x in result['source_documents']), sep='\n')
print("\n")
========= Question = names of founding fathers of the united states? Answer = John Adams , Benjamin Franklin , Alexander Hamilton , John Jay , Thomas Jefferson , James Madison , and George Washington Expected Answer(s) (may not be appear with exact wording in the dataset) = Thomas Jefferson::James Madison::John Jay::George Washington::John Adams::Benjamin Franklin::Alexander Hamilton Source documents: Founding Fathers of the United States ^ Burstein , Andrew . `` Politics and Personalities : Garry Wills takes a new look at a forgotten founder , slavery and the shaping of America '' , Chicago Tribune ( November 09 , 2003 ) : `` Forgotten founders such as Pickering and Morris made as many waves as those whose faces stare out from our currency . '' ^ Jump up to : Rafael , Ray . The Complete Idiot 's Guide to the Founding Fathers : And the Birth of Our Nation ( Penguin , 2011 ) . Jump up ^ `` Founding Fathers : Virginia '' . FindLaw Constitutional Law Center . 2008 . Retrieved 2008 - 11 - 14 . Jump up ^ Schwartz , Laurens R. Jews and the American Revolution : Haym Solomon and Others , Jefferson , North Carolina : McFarland & Co. , 1987 . Jump up ^ Kendall , Joshua . The Forgotten Founding Father : Noah Webster 's Obsession and the Creation of an American Culture ( Penguin 2011 ) . Jump up ^ Wright , R.E. ( 1996 ) . `` Thomas Willing ( 1731 - 1821 ) : Philadelphia Financier and Forgotten Founding Father '' . Pennsylvania History . 63 ( 4 ) : 525 -- 560 . doi : 10.2307 / 27773931 ( inactive 2017 - 01 - 15 ) . JSTOR 27773931 . Jump up ^ `` A Patriot of Early New England '' , New York Times ( December 20 , 1931 ) Founding Fathers of the United States President of Congress Peyton Randolph New Hampshire John Sullivan Nathaniel Folsom Massachusetts Bay Thomas Cushing Samuel Adams John Adams Robert Treat Paine Rhode Island Stephen Hopkins Samuel Ward Connecticut Eliphalet Dyer Roger Sherman Silas Deane New York Isaac Low John Alsop John Jay James Duane Philip Livingston William Floyd Henry Wisner Simon Boerum New Jersey James Kinsey William Livingston Stephen Crane Richard Smith John De Hart Pennsylvania Joseph Galloway John Dickinson Charles Humphreys Thomas Mifflin Edward Biddle John Morton George Ross The Lower Counties Caesar Rodney Thomas McKean George Read Maryland Matthew Tilghman Thomas Johnson , Junr William Paca Samuel Chase Virginia Richard Henry Lee George Washington Patrick Henry , Junr Richard Bland Benjamin Harrison Edmund Pendleton North Carolina William Hooper Joseph Hewes Richard Caswell South Carolina Henry Middleton Thomas Lynch Christopher Gadsden John Rutledge Edward Rutledge See also Virginia Association First Continental Congress Carpenters ' Hall Declaration and Resolves of the First Continental Congress Retrieved from `` https://en.wikipedia.org/w/index.php?title=Founding_Fathers_of_the_United_States&oldid=815247535 '' Categories : Age of Enlightenment American Revolution Articles about multiple people Patriots in the American Revolution Political leaders of the American Revolution National founders Hidden categories : Webarchive template wayback links Pages with DOIs inactive since 2017 Use mdy dates from April 2011 Talk Read Contents About Wikipedia Wikiquote Bân - lâm - gú Башҡортса Bikol Central Български Brezhoneg Català Čeština Cymraeg Deutsch Ελληνικά Español Esperanto فارسی Français 한국어 Հայերեն हिन्दी Ido Bahasa Indonesia Interlingua Íslenska Italiano עברית Latina Lietuvių Magyar Bahasa Melayu Nederlands 日本 語 Norsk Polski Português Română Founding Fathers of the United States Founding Fathers of the United States - wikipedia Founding Fathers of the United States Jump to : navigation , search Declaration of Independence , a painting by John Trumbull depicting the Committee of Five presenting their draft to the Congress on June 28 , 1776 Signature page of Treaty of Paris ( 1783 ) ; the treaty was negotiated by John Adams , Benjamin Franklin and John Jay . The Founding Fathers of the United States were those individuals of the Thirteen Colonies in North America who led the American Revolution against the authority of the British Crown in word and deed and contributed to the establishment of the United States of America . Historian Richard B. Morris in 1973 identified the following seven figures as the key Founding Fathers : John Adams , Benjamin Franklin , Alexander Hamilton , John Jay , Thomas Jefferson , James Madison , and George Washington . Adams , Jefferson , and Franklin were members of the Committee of Five that drafted the Declaration of Independence . Hamilton , Madison , and Jay were authors of The Federalist Papers , advocating ratification of the Constitution . The constitutions drafted by Jay and Adams for their respective states of New York ( 1777 ) and Massachusetts ( 1780 ) were heavily relied upon when creating language for the US Constitution Jay , Adams and Franklin negotiated the Treaty of Paris ( 1783 ) that would end the American Revolutionary War . Washington was Commander - Founding Fathers of the United States Prior to , and during the 19th century , they were referred to as simply the `` Fathers '' . The term has been used to describe the founders and first settlers of the original royal colonies . Contents ( hide ) 1 Background 2 Interesting facts and commonalities 2.1 Education 2.1. 1 Colleges attended 2.1. 2 Advanced degrees and apprenticeships 2.1. 2.1 Doctors of medicine 2.1. 2.2 Theology 2.1. 2.3 Legal apprenticeships 2.1. 3 Self - taught or little formal education 2.2 Demographics 2.3 Political experience 2.4 Occupations and finances 2.5 Religion 2.6 Ownership of slaves and position on slavery 2.7 Attendance at conventions 2.8 Spouses and children 2.9 Charters of freedom and historical documents of the United States 2.10 Post-constitution life 2.11 Youth and longevity 2.12 Founders who were not signatories or delegates 3 Legacy 3.1 Institutions formed by Founders 3.2 Scholarship on the Founders 3.2. 1 Living historians whose focus is the Founding Fathers 3.2. 2 Noted collections of the Founding Fathers 3.3 In stage and film 3.4 Children 's books 4 See also 5 Notes 6 References 7 External links Background ( edit ) The Albany Congress of 1754 was a conference attended by seven colonies , which presaged later efforts at cooperation . The Stamp Act Congress of 1765 included representatives from nine colonies . The First Continental Congress met briefly in Philadelphia , Pennsylvania in 1774 , consisting of fifty - six delegates from twelve of the thirteen colonies ( excluding Georgia ) that ========= Question = who played in the super bowl in 2013? Answer = Baltimore Ravens Expected Answer(s) (may not be appear with exact wording in the dataset) = Baltimore Ravens::San Francisco 49ers Source documents: Super Bowl XLVII responded to the claim on Twitter in jest , tweeting `` There is no conspiracy . I pulled the plug . '' Box score ( edit ) Super Bowl XLVII : Baltimore Ravens 34 , San Francisco 49ers 31 Total Ravens ( AFC ) 7 14 7 6 34 49ers ( NFC ) 17 8 31 at Mercedes - Benz Superdome in New Orleans , Louisiana Date : February 3 , 2013 Game time : 5 : 31 p.m. CST Game weather : Played indoors ( dome stadium ) Game attendance : 71,024 Referee : Jerome Boger TV announcers ( CBS ) : Jim Nantz , Phil Simms , Steve Tasker , Solomon Wilcots Gamebook ( hide ) Scoring summary Quarter Time Drive Team Scoring information Score Plays Yards TOP BAL SF 10 : 36 6 51 2 : 29 BAL Anquan Boldin 13 - yard touchdown reception from Joe Flacco , Justin Tucker kick good 7 0 3 : 58 12 62 6 : 38 SF 36 - yard field goal by David Akers 7 7 : 10 10 75 4 : 43 BAL Dennis Pitta 1 - yard touchdown reception from Flacco , Tucker kick good 14 1 : 45 56 0 : 22 BAL Jacoby Jones 56 - yard touchdown reception from Flacco , Tucker kick good 21 0 : 00 8 71 1 : 45 SF 27 - yard field goal by Akers 21 6 14 : 49 -- -- -- BAL J. Jones 108 - Super Bowl XLVII for the 2012 season . The Ravens defeated the 49ers by the score of 34 -- 31 , handing the 49ers their first Super Bowl loss in franchise history . The game was played on February 3 , 2013 , at Mercedes - Benz Superdome in New Orleans , Louisiana . This was the tenth Super Bowl to be played in New Orleans , equaling Miami 's record of ten in an individual city . For the first time in Super Bowl history , the game featured two brothers coaching against each other -- Jim and John Harbaugh , head coaches of the San Francisco 49ers and Baltimore Ravens , respectively -- earning it the nickname Harbaugh Bowl . In addition , Super Bowl XLVII was the first to feature two teams that had undefeated records in previous Super Bowl games ( Baltimore , 1 -- 0 ; San Francisco , 5 -- 0 ) . The 49ers , who posted a regular - season record of 11 -- 4 -- 1 , entered the game seeking their sixth Super Bowl win in team history ( and first since Super Bowl XXIX at the end of the 1994 season ) , which would have tied the Pittsburgh Steelers for the most by a franchise . The Ravens , who posted a 10 -- 6 regular - season record , made their second Super Bowl appearance in 12 years , having previously won Super Bowl XXXV . Ray Lewis , the Super Bowl XLVII preview : A minute - by - minute breakdown '' . USA Today . Retrieved February 2 , 2013 . Jump up ^ `` Beyonce half time performance '' . NFL.Com . February 4 , 2013 . Retrieved February 5 , 2013 . Jump up ^ `` Beyonce wows at half - time show '' . BBC News . February 4 , 2013 . Retrieved February 5 , 2013 . Jump up ^ `` Beyonce Draws Estimated 104 Million to Super Bowl Halftime '' . ^ Jump up to : `` Play - by - Play '' . ESPN . February 3 , 2013 . Retrieved February 4 , 2013 . Jump up ^ Inman , Cam ( February 3 , 2013 ) . `` Super Bowl 2013 : San Francisco 49ers ' furious comeback falls short in 34 -- 31 loss to Baltimore Ravens -- San Jose Mercury News '' . San Jose Mercury News . Retrieved February 4 , 2013 . ^ Jump up to : `` Jacoby Jones returns kick 108 yards '' . ESPN.com . February 4 , 2013 . Retrieved April 24 , 2016 . Jump up ^ `` Watch Baltimore Ravens vs. Denver Broncos ( 01 / 12 / 2013 ) '' . NFL . Retrieved February 4 , 2013 . ^ Jump up to : Rosenthal , Gregg ( February 3 , 2013 ) . `` Jacoby Jones ' 108 - yard return TD a Super Bowl record '' . NFL . Retrieved Super Bowl XLVII MVP Award '' . Forbes.com . February 4 , 2013 . Retrieved February 6 , 2013 . Jump up ^ Heitner , Darren ( April 18 , 2013 ) . `` Is It Worth Spending $4 Million On A Super Bowl Commercial ? '' . Forbes . Retrieved February 4 , 2013 . Jump up ^ Collins , Scott ( February 5 , 2013 ) . `` Super Bowl ratings dip slightly from last year '' . Los Angeles Times . Retrieved February 5 , 2013 . ^ Jump up to : `` New Orleans to host 10th Super Bowl in 2013 '' . ESPN.com . Associated Press . May 19 , 2009 . Retrieved January 14 , 2011 . Jump up ^ Ally Burguieres Designs Official NFL Beads with Courtyard by Marriott for SuperBowl -- WGNO -- YouTube on YouTube Jump up ^ Wilner , Barry ( January 21 , 2013 ) . `` Ravens dominate Pats , set up ' Harbaugh Bowl ' '' . NBC Sports . Associated Press . Retrieved January 21 , 2013 . Jump up ^ Brinson , Will . `` Sorting the Sunday Pile , Divisional Round : Harbaugh Bowl still lives '' . CBSSports.com . CBS Interactive . Retrieved January 21 , 2013 . Jump up ^ Schwab , Frank . `` HarBowl ! Harbaugh brothers Jim and John to square off in Super Bowl '' . Yahoo ! Sports . Retrieved January 21 , 2003 . Jump up ^ `` The ========= Question = when did bucharest become the capital of romania? Answer = 1862 Expected Answer(s) (may not be appear with exact wording in the dataset) = 1862 Source documents: Bucharest EU ) Density 9,237 / km ( 23,920 / sq mi ) Metro 2,412,530 Demonym ( s ) Bucharester ( en ) bucureștean , bucureșteancă ( ro ) Time zone UTC + 2 ( EET ) Summer ( DST ) UTC + 3 ( EEST ) Postal code 0xxxxx Area code ( s ) + 40 x1 Car plate prefix GDP ( Nominal ) € 47 billion - Per capita PPP € 40,400 -- Per capita € 20,000 Website pmb.ro Romanian law stipulates that Bucharest has a special administrative status which is equal to that of a County ; Bucharest metropolitan area is a proposed project . Bucharest ( / ˈb ( j ) uː kərɛst / ; Romanian : București ( bukuˈreʃtj ) ( listen ) ) is the capital and largest city of Romania , as well as its cultural , industrial , and financial centre . It is located in the southeast of the country , at 44 ° 25 ′ 57 '' N 26 ° 06 ′ 14 '' E / 44.43250 ° N 26.10389 ° E / 44.43250 ; 26.10389 Coordinates : 44 ° 25 ′ 57 '' N 26 ° 06 ′ 14 '' E / 44.43250 ° N 26.10389 ° E / 44.43250 ; 26.10389 , on the banks of the Dâmbovița River , less than 60 km ( 37.3 mi ) north of the Danube River and the Bulgarian border . Bucharest was first mentioned in Bucharest Bucharest - wikipedia Bucharest This article contains too many pictures , charts or diagrams for its overall length . Please help to improve this article by removing or adjusting the sandwiching of text between two images and indiscriminate galleries in accordance with the Manual of Style on use of images . ( Learn how and when to remove this template message ) Capital city in None , Romania Bucharest București Capital city From top , left to right : Central University Library Palace of the Parliament Arcul de Triumf Romanian Athenaeum Modernist skyscrapers CEC Palace Royal Palace of Bucharest Flag Coat of arms Nickname ( s ) : Micul Paris ( The Little Paris ) , Paris of the East Motto ( s ) : Patria și dreptul meu ( The Homeland and my right ) Bucharest Location of Bucharest in Romania Show map of Romania Bucharest Bucharest ( Europe ) Show map of Europe Coordinates : 44 ° 25 ′ 57 '' N 26 ° 6 ′ 14 '' E / 44.43250 ° N 26.10389 ° E / 44.43250 ; 26.10389 Country Romania County None First attested 1459 Government Mayor Gabriela Firea ( PSD ) Prefect Speranţa Cliseru Area Capital city 228 km ( 88 sq mi ) Urban 285 km ( 110 sq mi ) Elevation 55.8 -- 91.5 m ( 183.1 -- 300.2 ft ) Population ( 2011 ) Capital city 1,883,425 Estimate ( 2016 ) 2,106,144 Rank 1st in Romania ( 6th in Bucharest destroying a third of the city . Ottoman massacre of Greek irregulars in Bucharest ( August , 1821 ) In 1862 , after Wallachia and Moldavia were united to form the Principality of Romania , Bucharest became the new nation 's capital city . In 1881 , it became the political centre of the newly proclaimed Kingdom of Romania under King Carol I. During the second half of the 19th century , the city 's population increased dramatically , and a new period of urban development began . During this period , gas lighting , horse - drawn trams , and limited electrification were introduced . The Dâmbovița River was also massively channelled in 1883 , thus putting a stop to previously endemic floods like the 1865 flooding of Bucharest . The Fortifications of Bucharest were built . The extravagant architecture and cosmopolitan high culture of this period won Bucharest the nickname of `` Little Paris '' ( Micul Paris ) of the east , with Calea Victoriei as its Champs - Élysées . I.C. Brătianu Boulevard in the 1930s Between 6 December 1916 and November 1918 , the city was occupied by German forces as a result of the Battle of Bucharest , with the official capital temporarily moved to Iași , in the Moldavia region . After World War I , Bucharest became the capital of Greater Romania . In the interwar years , Bucharest 's urban development continued , with the city gaining an average of 30,000 Bucharest documents in 1459 . It became the capital of Romania in 1862 and is the centre of Romanian media , culture , and art . Its architecture is a mix of historical ( neo-classical ) , interbellum ( Bauhaus and art deco ) , communist - era and modern . In the period between the two World Wars , the city 's elegant architecture and the sophistication of its elite earned Bucharest the nickname of `` Little Paris '' ( Micul Paris ) . Although buildings and districts in the historic city centre were heavily damaged or destroyed by war , earthquakes , and above all Nicolae Ceaușescu 's program of systematization , many survived . In recent years , the city has been experiencing an economic and cultural boom . In 2016 , the historical city centre was listed as `` endangered '' by the World Monuments Watch . According to the 2011 census , 1,883,425 inhabitants live within the city limits , a decrease from the 2002 census . Adding the satellite towns around the urban area , the proposed metropolitan area of Bucharest would have a population of 2.27 million people . According to Eurostat , Bucharest has a functional urban area of 2,412,530 residents ( as of 2015 ) . Bucharest is the sixth - largest city in the European Union by population within city limits , after London , Berlin , Madrid , Rome , and Paris . Economically , Bucharest is the most prosperous
config_yml =\
"""
name: python311
channels:
- empty
dependencies:
- pip:
- langchain-huggingface==0.1.2
prefix: /opt/anaconda3/envs/python311
"""
with open("config.yaml", "w", encoding="utf-8") as f:
f.write(config_yml)
base_sw_spec_id = api_client.software_specifications.get_id_by_name("runtime-24.1-py3.11")
meta_prop_pkg_extn = {
api_client.package_extensions.ConfigurationMetaNames.NAME: "langchain watsonx.ai env",
api_client.package_extensions.ConfigurationMetaNames.DESCRIPTION: "Environment with langchain",
api_client.package_extensions.ConfigurationMetaNames.TYPE: "conda_yml"
}
pkg_extn_details = api_client.package_extensions.store(meta_props=meta_prop_pkg_extn, file_path="config.yaml")
pkg_extn_id = api_client.package_extensions.get_id(pkg_extn_details)
pkg_extn_id
Creating package extensions SUCCESS
'3cce971c-4805-4925-9776-ad484f974d06'
meta_prop_sw_spec = {
api_client.software_specifications.ConfigurationMetaNames.NAME: "AI service watsonx.ai custom software specification",
api_client.software_specifications.ConfigurationMetaNames.DESCRIPTION: "Software specification for AI service deployment",
api_client.software_specifications.ConfigurationMetaNames.BASE_SOFTWARE_SPECIFICATION: {"guid": base_sw_spec_id}
}
sw_spec_details = api_client.software_specifications.store(meta_props=meta_prop_sw_spec)
sw_spec_id = api_client.software_specifications.get_id(sw_spec_details)
api_client.software_specifications.add_package_extension(sw_spec_id, pkg_extn_id)
sw_spec_id
SUCCESS
'a5c002e4-8022-4341-91b6-aabcf5b727de'
meta_props = {
api_client.repository.AIServiceMetaNames.NAME: "AI service SDK",
api_client.repository.AIServiceMetaNames.SOFTWARE_SPEC_ID: sw_spec_id
}
stored_ai_service_details = api_client.repository.store_ai_service(deployable_ai_service, meta_props)
ai_service_id = api_client.repository.get_ai_service_id(stored_ai_service_details)
ai_service_id
'094b6d58-8bd4-4dfd-95da-7660636cb33b'
Deploy AI service¶
Create deployment of AI service.
meta_props = {
api_client.deployments.ConfigurationMetaNames.NAME: "AI service elasticsearch",
api_client.deployments.ConfigurationMetaNames.ONLINE: {},
api_client.deployments.ConfigurationMetaNames.CUSTOM: {
"space_id": api_client.default_space_id,
"url": api_client.credentials.url,
"elasticsearch_connection_id": elasticsearch_connection_id,
"index_name": index_name,
"text_model_id": text_model_id,
},
}
deployment_details = api_client.deployments.create(ai_service_id, meta_props)
###################################################################################### Synchronous deployment creation for id: '094b6d58-8bd4-4dfd-95da-7660636cb33b' started ###################################################################################### initializing Note: online_url and serving_urls are deprecated and will be removed in a future release. Use inference instead. ....... ready ----------------------------------------------------------------------------------------------- Successfully finished deployment creation, deployment_id='575e0d2d-02eb-4195-bd38-b5fd94af32ee' -----------------------------------------------------------------------------------------------
deployment_id = api_client.deployments.get_id(deployment_details)
Example of Executing an AI service.¶
deployments_results = api_client.deployments.run_ai_service(
deployment_id, {"questions_and_answers": questions_and_answers}
)
for idx, result in enumerate(deployments_results["result"]):
print("=========")
print("Question = ", result['query'])
print("Answer = ", result['result'])
print("Expected Answer(s) (may not be appear with exact wording in the dataset) = ", questions_and_answers[result['query']])
print("\n")
print("Source documents:")
print(*(x.get("kwargs").get("page_content") for x in result['source_documents']), sep='\n')
print("\n")
========= Question = names of founding fathers of the united states? Answer = John Adams , Benjamin Franklin , Alexander Hamilton , John Jay , Thomas Jefferson , James Madison , and George Washington Expected Answer(s) (may not be appear with exact wording in the dataset) = Thomas Jefferson::James Madison::John Jay::George Washington::John Adams::Benjamin Franklin::Alexander Hamilton Source documents: Founding Fathers of the United States ^ Burstein , Andrew . `` Politics and Personalities : Garry Wills takes a new look at a forgotten founder , slavery and the shaping of America '' , Chicago Tribune ( November 09 , 2003 ) : `` Forgotten founders such as Pickering and Morris made as many waves as those whose faces stare out from our currency . '' ^ Jump up to : Rafael , Ray . The Complete Idiot 's Guide to the Founding Fathers : And the Birth of Our Nation ( Penguin , 2011 ) . Jump up ^ `` Founding Fathers : Virginia '' . FindLaw Constitutional Law Center . 2008 . Retrieved 2008 - 11 - 14 . Jump up ^ Schwartz , Laurens R. Jews and the American Revolution : Haym Solomon and Others , Jefferson , North Carolina : McFarland & Co. , 1987 . Jump up ^ Kendall , Joshua . The Forgotten Founding Father : Noah Webster 's Obsession and the Creation of an American Culture ( Penguin 2011 ) . Jump up ^ Wright , R.E. ( 1996 ) . `` Thomas Willing ( 1731 - 1821 ) : Philadelphia Financier and Forgotten Founding Father '' . Pennsylvania History . 63 ( 4 ) : 525 -- 560 . doi : 10.2307 / 27773931 ( inactive 2017 - 01 - 15 ) . JSTOR 27773931 . Jump up ^ `` A Patriot of Early New England '' , New York Times ( December 20 , 1931 ) Founding Fathers of the United States President of Congress Peyton Randolph New Hampshire John Sullivan Nathaniel Folsom Massachusetts Bay Thomas Cushing Samuel Adams John Adams Robert Treat Paine Rhode Island Stephen Hopkins Samuel Ward Connecticut Eliphalet Dyer Roger Sherman Silas Deane New York Isaac Low John Alsop John Jay James Duane Philip Livingston William Floyd Henry Wisner Simon Boerum New Jersey James Kinsey William Livingston Stephen Crane Richard Smith John De Hart Pennsylvania Joseph Galloway John Dickinson Charles Humphreys Thomas Mifflin Edward Biddle John Morton George Ross The Lower Counties Caesar Rodney Thomas McKean George Read Maryland Matthew Tilghman Thomas Johnson , Junr William Paca Samuel Chase Virginia Richard Henry Lee George Washington Patrick Henry , Junr Richard Bland Benjamin Harrison Edmund Pendleton North Carolina William Hooper Joseph Hewes Richard Caswell South Carolina Henry Middleton Thomas Lynch Christopher Gadsden John Rutledge Edward Rutledge See also Virginia Association First Continental Congress Carpenters ' Hall Declaration and Resolves of the First Continental Congress Retrieved from `` https://en.wikipedia.org/w/index.php?title=Founding_Fathers_of_the_United_States&oldid=815247535 '' Categories : Age of Enlightenment American Revolution Articles about multiple people Patriots in the American Revolution Political leaders of the American Revolution National founders Hidden categories : Webarchive template wayback links Pages with DOIs inactive since 2017 Use mdy dates from April 2011 Talk Read Contents About Wikipedia Wikiquote Bân - lâm - gú Башҡортса Bikol Central Български Brezhoneg Català Čeština Cymraeg Deutsch Ελληνικά Español Esperanto فارسی Français 한국어 Հայերեն हिन्दी Ido Bahasa Indonesia Interlingua Íslenska Italiano עברית Latina Lietuvių Magyar Bahasa Melayu Nederlands 日本 語 Norsk Polski Português Română Founding Fathers of the United States Founding Fathers of the United States - wikipedia Founding Fathers of the United States Jump to : navigation , search Declaration of Independence , a painting by John Trumbull depicting the Committee of Five presenting their draft to the Congress on June 28 , 1776 Signature page of Treaty of Paris ( 1783 ) ; the treaty was negotiated by John Adams , Benjamin Franklin and John Jay . The Founding Fathers of the United States were those individuals of the Thirteen Colonies in North America who led the American Revolution against the authority of the British Crown in word and deed and contributed to the establishment of the United States of America . Historian Richard B. Morris in 1973 identified the following seven figures as the key Founding Fathers : John Adams , Benjamin Franklin , Alexander Hamilton , John Jay , Thomas Jefferson , James Madison , and George Washington . Adams , Jefferson , and Franklin were members of the Committee of Five that drafted the Declaration of Independence . Hamilton , Madison , and Jay were authors of The Federalist Papers , advocating ratification of the Constitution . The constitutions drafted by Jay and Adams for their respective states of New York ( 1777 ) and Massachusetts ( 1780 ) were heavily relied upon when creating language for the US Constitution Jay , Adams and Franklin negotiated the Treaty of Paris ( 1783 ) that would end the American Revolutionary War . Washington was Commander - Founding Fathers of the United States Prior to , and during the 19th century , they were referred to as simply the `` Fathers '' . The term has been used to describe the founders and first settlers of the original royal colonies . Contents ( hide ) 1 Background 2 Interesting facts and commonalities 2.1 Education 2.1. 1 Colleges attended 2.1. 2 Advanced degrees and apprenticeships 2.1. 2.1 Doctors of medicine 2.1. 2.2 Theology 2.1. 2.3 Legal apprenticeships 2.1. 3 Self - taught or little formal education 2.2 Demographics 2.3 Political experience 2.4 Occupations and finances 2.5 Religion 2.6 Ownership of slaves and position on slavery 2.7 Attendance at conventions 2.8 Spouses and children 2.9 Charters of freedom and historical documents of the United States 2.10 Post-constitution life 2.11 Youth and longevity 2.12 Founders who were not signatories or delegates 3 Legacy 3.1 Institutions formed by Founders 3.2 Scholarship on the Founders 3.2. 1 Living historians whose focus is the Founding Fathers 3.2. 2 Noted collections of the Founding Fathers 3.3 In stage and film 3.4 Children 's books 4 See also 5 Notes 6 References 7 External links Background ( edit ) The Albany Congress of 1754 was a conference attended by seven colonies , which presaged later efforts at cooperation . The Stamp Act Congress of 1765 included representatives from nine colonies . The First Continental Congress met briefly in Philadelphia , Pennsylvania in 1774 , consisting of fifty - six delegates from twelve of the thirteen colonies ( excluding Georgia ) that ========= Question = who played in the super bowl in 2013? Answer = Baltimore Ravens Expected Answer(s) (may not be appear with exact wording in the dataset) = Baltimore Ravens::San Francisco 49ers Source documents: Super Bowl XLVII responded to the claim on Twitter in jest , tweeting `` There is no conspiracy . I pulled the plug . '' Box score ( edit ) Super Bowl XLVII : Baltimore Ravens 34 , San Francisco 49ers 31 Total Ravens ( AFC ) 7 14 7 6 34 49ers ( NFC ) 17 8 31 at Mercedes - Benz Superdome in New Orleans , Louisiana Date : February 3 , 2013 Game time : 5 : 31 p.m. CST Game weather : Played indoors ( dome stadium ) Game attendance : 71,024 Referee : Jerome Boger TV announcers ( CBS ) : Jim Nantz , Phil Simms , Steve Tasker , Solomon Wilcots Gamebook ( hide ) Scoring summary Quarter Time Drive Team Scoring information Score Plays Yards TOP BAL SF 10 : 36 6 51 2 : 29 BAL Anquan Boldin 13 - yard touchdown reception from Joe Flacco , Justin Tucker kick good 7 0 3 : 58 12 62 6 : 38 SF 36 - yard field goal by David Akers 7 7 : 10 10 75 4 : 43 BAL Dennis Pitta 1 - yard touchdown reception from Flacco , Tucker kick good 14 1 : 45 56 0 : 22 BAL Jacoby Jones 56 - yard touchdown reception from Flacco , Tucker kick good 21 0 : 00 8 71 1 : 45 SF 27 - yard field goal by Akers 21 6 14 : 49 -- -- -- BAL J. Jones 108 - Super Bowl XLVII for the 2012 season . The Ravens defeated the 49ers by the score of 34 -- 31 , handing the 49ers their first Super Bowl loss in franchise history . The game was played on February 3 , 2013 , at Mercedes - Benz Superdome in New Orleans , Louisiana . This was the tenth Super Bowl to be played in New Orleans , equaling Miami 's record of ten in an individual city . For the first time in Super Bowl history , the game featured two brothers coaching against each other -- Jim and John Harbaugh , head coaches of the San Francisco 49ers and Baltimore Ravens , respectively -- earning it the nickname Harbaugh Bowl . In addition , Super Bowl XLVII was the first to feature two teams that had undefeated records in previous Super Bowl games ( Baltimore , 1 -- 0 ; San Francisco , 5 -- 0 ) . The 49ers , who posted a regular - season record of 11 -- 4 -- 1 , entered the game seeking their sixth Super Bowl win in team history ( and first since Super Bowl XXIX at the end of the 1994 season ) , which would have tied the Pittsburgh Steelers for the most by a franchise . The Ravens , who posted a 10 -- 6 regular - season record , made their second Super Bowl appearance in 12 years , having previously won Super Bowl XXXV . Ray Lewis , the Super Bowl XLVII preview : A minute - by - minute breakdown '' . USA Today . Retrieved February 2 , 2013 . Jump up ^ `` Beyonce half time performance '' . NFL.Com . February 4 , 2013 . Retrieved February 5 , 2013 . Jump up ^ `` Beyonce wows at half - time show '' . BBC News . February 4 , 2013 . Retrieved February 5 , 2013 . Jump up ^ `` Beyonce Draws Estimated 104 Million to Super Bowl Halftime '' . ^ Jump up to : `` Play - by - Play '' . ESPN . February 3 , 2013 . Retrieved February 4 , 2013 . Jump up ^ Inman , Cam ( February 3 , 2013 ) . `` Super Bowl 2013 : San Francisco 49ers ' furious comeback falls short in 34 -- 31 loss to Baltimore Ravens -- San Jose Mercury News '' . San Jose Mercury News . Retrieved February 4 , 2013 . ^ Jump up to : `` Jacoby Jones returns kick 108 yards '' . ESPN.com . February 4 , 2013 . Retrieved April 24 , 2016 . Jump up ^ `` Watch Baltimore Ravens vs. Denver Broncos ( 01 / 12 / 2013 ) '' . NFL . Retrieved February 4 , 2013 . ^ Jump up to : Rosenthal , Gregg ( February 3 , 2013 ) . `` Jacoby Jones ' 108 - yard return TD a Super Bowl record '' . NFL . Retrieved Super Bowl XLVII MVP Award '' . Forbes.com . February 4 , 2013 . Retrieved February 6 , 2013 . Jump up ^ Heitner , Darren ( April 18 , 2013 ) . `` Is It Worth Spending $4 Million On A Super Bowl Commercial ? '' . Forbes . Retrieved February 4 , 2013 . Jump up ^ Collins , Scott ( February 5 , 2013 ) . `` Super Bowl ratings dip slightly from last year '' . Los Angeles Times . Retrieved February 5 , 2013 . ^ Jump up to : `` New Orleans to host 10th Super Bowl in 2013 '' . ESPN.com . Associated Press . May 19 , 2009 . Retrieved January 14 , 2011 . Jump up ^ Ally Burguieres Designs Official NFL Beads with Courtyard by Marriott for SuperBowl -- WGNO -- YouTube on YouTube Jump up ^ Wilner , Barry ( January 21 , 2013 ) . `` Ravens dominate Pats , set up ' Harbaugh Bowl ' '' . NBC Sports . Associated Press . Retrieved January 21 , 2013 . Jump up ^ Brinson , Will . `` Sorting the Sunday Pile , Divisional Round : Harbaugh Bowl still lives '' . CBSSports.com . CBS Interactive . Retrieved January 21 , 2013 . Jump up ^ Schwab , Frank . `` HarBowl ! Harbaugh brothers Jim and John to square off in Super Bowl '' . Yahoo ! Sports . Retrieved January 21 , 2003 . Jump up ^ `` The ========= Question = when did bucharest become the capital of romania? Answer = 1862 Expected Answer(s) (may not be appear with exact wording in the dataset) = 1862 Source documents: Bucharest EU ) Density 9,237 / km ( 23,920 / sq mi ) Metro 2,412,530 Demonym ( s ) Bucharester ( en ) bucureștean , bucureșteancă ( ro ) Time zone UTC + 2 ( EET ) Summer ( DST ) UTC + 3 ( EEST ) Postal code 0xxxxx Area code ( s ) + 40 x1 Car plate prefix GDP ( Nominal ) € 47 billion - Per capita PPP € 40,400 -- Per capita € 20,000 Website pmb.ro Romanian law stipulates that Bucharest has a special administrative status which is equal to that of a County ; Bucharest metropolitan area is a proposed project . Bucharest ( / ˈb ( j ) uː kərɛst / ; Romanian : București ( bukuˈreʃtj ) ( listen ) ) is the capital and largest city of Romania , as well as its cultural , industrial , and financial centre . It is located in the southeast of the country , at 44 ° 25 ′ 57 '' N 26 ° 06 ′ 14 '' E / 44.43250 ° N 26.10389 ° E / 44.43250 ; 26.10389 Coordinates : 44 ° 25 ′ 57 '' N 26 ° 06 ′ 14 '' E / 44.43250 ° N 26.10389 ° E / 44.43250 ; 26.10389 , on the banks of the Dâmbovița River , less than 60 km ( 37.3 mi ) north of the Danube River and the Bulgarian border . Bucharest was first mentioned in Bucharest Bucharest - wikipedia Bucharest This article contains too many pictures , charts or diagrams for its overall length . Please help to improve this article by removing or adjusting the sandwiching of text between two images and indiscriminate galleries in accordance with the Manual of Style on use of images . ( Learn how and when to remove this template message ) Capital city in None , Romania Bucharest București Capital city From top , left to right : Central University Library Palace of the Parliament Arcul de Triumf Romanian Athenaeum Modernist skyscrapers CEC Palace Royal Palace of Bucharest Flag Coat of arms Nickname ( s ) : Micul Paris ( The Little Paris ) , Paris of the East Motto ( s ) : Patria și dreptul meu ( The Homeland and my right ) Bucharest Location of Bucharest in Romania Show map of Romania Bucharest Bucharest ( Europe ) Show map of Europe Coordinates : 44 ° 25 ′ 57 '' N 26 ° 6 ′ 14 '' E / 44.43250 ° N 26.10389 ° E / 44.43250 ; 26.10389 Country Romania County None First attested 1459 Government Mayor Gabriela Firea ( PSD ) Prefect Speranţa Cliseru Area Capital city 228 km ( 88 sq mi ) Urban 285 km ( 110 sq mi ) Elevation 55.8 -- 91.5 m ( 183.1 -- 300.2 ft ) Population ( 2011 ) Capital city 1,883,425 Estimate ( 2016 ) 2,106,144 Rank 1st in Romania ( 6th in Bucharest destroying a third of the city . Ottoman massacre of Greek irregulars in Bucharest ( August , 1821 ) In 1862 , after Wallachia and Moldavia were united to form the Principality of Romania , Bucharest became the new nation 's capital city . In 1881 , it became the political centre of the newly proclaimed Kingdom of Romania under King Carol I. During the second half of the 19th century , the city 's population increased dramatically , and a new period of urban development began . During this period , gas lighting , horse - drawn trams , and limited electrification were introduced . The Dâmbovița River was also massively channelled in 1883 , thus putting a stop to previously endemic floods like the 1865 flooding of Bucharest . The Fortifications of Bucharest were built . The extravagant architecture and cosmopolitan high culture of this period won Bucharest the nickname of `` Little Paris '' ( Micul Paris ) of the east , with Calea Victoriei as its Champs - Élysées . I.C. Brătianu Boulevard in the 1930s Between 6 December 1916 and November 1918 , the city was occupied by German forces as a result of the Battle of Bucharest , with the official capital temporarily moved to Iași , in the Moldavia region . After World War I , Bucharest became the capital of Greater Romania . In the interwar years , Bucharest 's urban development continued , with the city gaining an average of 30,000 Bucharest documents in 1459 . It became the capital of Romania in 1862 and is the centre of Romanian media , culture , and art . Its architecture is a mix of historical ( neo-classical ) , interbellum ( Bauhaus and art deco ) , communist - era and modern . In the period between the two World Wars , the city 's elegant architecture and the sophistication of its elite earned Bucharest the nickname of `` Little Paris '' ( Micul Paris ) . Although buildings and districts in the historic city centre were heavily damaged or destroyed by war , earthquakes , and above all Nicolae Ceaușescu 's program of systematization , many survived . In recent years , the city has been experiencing an economic and cultural boom . In 2016 , the historical city centre was listed as `` endangered '' by the World Monuments Watch . According to the 2011 census , 1,883,425 inhabitants live within the city limits , a decrease from the 2002 census . Adding the satellite towns around the urban area , the proposed metropolitan area of Bucharest would have a population of 2.27 million people . According to Eurostat , Bucharest has a functional urban area of 2,412,530 residents ( as of 2015 ) . Bucharest is the sixth - largest city in the European Union by population within city limits , after London , Berlin , Madrid , Rome , and Paris . Economically , Bucharest is the most prosperous
Summary and next steps¶
You successfully completed this notebook!
Check out our Online Documentation for more samples, tutorials, documentation, how-tos, and blog posts.
Author¶
Mateusz Szewczyk, Software Engineer at Watson Machine Learning.
Copyright © 2024 IBM. This notebook and its source code are released under the terms of the MIT License.