Virtual_Agent_Chatbot_using_Open_Artificial_Intelligence_Final_
Virtual_Agent_Chatbot_using_Open_Artificial_Intelligence_Final_
net/publication/379507857
CITATION READS
1 1,232
3 authors, including:
All content following this page was uploaded by Muthana Alsaadi on 02 April 2024.
Abstract
With the era of open AI (Artificial Intelligence) and its contribution to the massive technological boom.
One of its results is the great development in building virtual agents, or chatbots, which are essentially
applications of machine learning algorithms and large language models. Recently, the use of chatbots has
begun to dominate some websites of commercial, educational, and health institutions, as their presence
has contributed to the development of these institutions due to the characteristics that chatbots have, such
as being available 24/7 and user friendly, thus reducing costs for these institutions instead of providing
human customer service.
Our project faced many obstacles and difficulties. One of the major barriers we faced was that we tried to
use one of the major cloud services Microsoft Azure.Unfortunately, a regional limitation to their services
and our country Iraq was not on the list of the countries that can access their newly launched AI services.
There are numerous ways to reach and achieve our goal and vision for the final project but as engineers,
we must choose the best way which must be cost effective , open source software and easy to implement
for other programmers for educational purposes.
This project presents a chatbot “Esaalni”, a general-use chatbot same as the likes of ChatGPT and
Google’s Gemini based on the power of open AI (Google’s Gemini Pro) and the Python library
LangChain, which is an open source framework used to create AI-powered agents (chatbots) with a
variety of large language models (LLM) integrations and tools supported by vector databases. Google’s
Gemini Pro LLM model, in addition to Open AI LLM model, were chosen as it was the easiest to
implement in our use case. The Python library for hosting data science web applications, Streamlit, was
used to make and host the user interface of this application in the cloud. They had amazing and
easy-to-use APIs (Application programming interfaces) for LLM (Large Language Models) chatbot
cases.
© 2024 Electronic and Communications Department, Faculty of Engineering, University of Kufa, Iraq. All rights reserved.
2
Magazine of Student Research (MOSR)
1. Introduction
1.1 Introduction and definition of Generative AI
Generative AI refers to algorithms that can generate novel content, as opposed to analyzing or acting on
existing data like more traditional, predictive machine learning or AI systems [1]. Defining emerging
technologies is no easy feat. Technology will inevitably evolve. This can mean that the definition
becomes less descriptive over time. This could easily be the case with generative AI. The pace of
innovation is stunningly fast. It seems that every day there is a new breakthrough and standout service.
Then what is a good definition of generative AI? How can we best describe this technology? Let’s take a
look at some examples:
● McKinsey & Co.: “Products like ChatGPT and GitHub Copilot, as well as the underlying AI
models that power such systems (Stable Diffusion, DALL·E 2, GPT-3, to name a few), are taking
technology into realms once thought to be reserved for humans. With generative AI, computers
can now arguably exhibit creativity.” [2]
● Sequoia Capital: “This new category is called ‘Generative AI,’ meaning the machine is
generating something new rather than analyzing something that already exists. Generative AI is
well on the way to becoming not just faster and cheaper, but better in some cases than what
humans create by hand.” [3]
● IBM: “Generative AI is a class of machine learning technology that learns to generate new data
from training data.” [4]
● Meta: “Generative AI research is pushing creative expression forward by giving people tools to
quickly and easily create new content.” [5]
Recently, LLMs have found applications for tasks like essay generation, code development, translation,
and understanding genetic sequences. More broadly, applications of language models involve multiple
areas, such as:
● Question answering
● Automatic summarization
● Sentiment analysis
● Topic modeling
● Semantic search
● Machine translation
The size of the training corpus for LLMs has been increasing drastically. GPT-1, introduced by OpenAI
in 2018, was trained on BookCorpus with 985 million words. BERT, released in the same year, was
trained on a combined corpus of BookCorpus and English Wikipedia, totaling 3.3 billion words. Now,
training corpora for LLMs reach up to trillions of tokens. This graph illustrates how LLMs have been
growing:
© 2024 Electronics and Communication Department, Faculty of Engineering, University of Kufa, Iraq. All rights reserved.
3
Magazine of Student Research (MOSR)
Figure 1. LLMs from BERT to GPT-4 – size, training budget, and organizations. For the proprietary
models, parameter sizes are often estimated. [1]
Historians have theorized that general-purpose technologies are critical for long term economic growth.
This has led to greater wealth and innovation. According to a post in the Economist, generative AI may
also be a general-purpose technology. The authors point out: “Think printing presses, steam engines and
electric motors. The new models’ achievements have made AI look a lot more like a [general-purpose
technology] than it used to.” [6]
Predicting the size of the generative AI market is more art than science. It seems more like it would have
been – in 1995 – to get a sense of the impact of the Internet. Many of the predictions during this period
proved to be laughable – at least over the long term. But there are various research firms that have put
together estimates for generative AI. There is a report from SkyQuest Technology Consulting which
predicts that the technology will contribute a whopping $15.7 trillion to the global economy by 2028. [9]
About $6.6 trillion will be from improved productivity and $9.1 trillion from consumer surplus.
© 2024 Electronics and Communication Department, Faculty of Engineering, University of Kufa, Iraq. All rights reserved.
4
Magazine of Student Research (MOSR)
On the fourth quarter earnings call in 2022, Meta CEO Mark Zuckerberg said: “AI is the foundation of
our discovery engine and our ads business, and we also think it’s going to enable many new products and
additional transformations within our apps. Generative AI is an extremely exciting new area…and one of
my goals for Meta is to build on our research to become a leader in generative AI in addition to our
leading work in recommendation AI.” [10]
Of course, VCs are also making predictions. Perhaps the most notable is from Sequoia Capital. In a
report, the firm states: “The fields that generative AI addresses—knowledge work and creative
work—comprise billions of workers. Generative AI can make these workers at least 10% more efficient
and/or creative: they become not only faster and more efficient, but more capable than before. Therefore,
generative AI has the potential to generate trillions of dollars of economic value.” [11] The following are
some of its predictions for generative AI for 2030:
● Text: Final drafts will be better than professional writers.
● Code: Test-to-product will be better than full-time developers.
● Images: Final drafts will be better than professional artists and designers.
● Video/3D gaming: Video games will be essentially “personalized dreams.”
Lonne Jaffe, a venture capitalist at Insight Partners, is another bull on generative AI. He has noted:
“There is definitely an element to this that feels like the early launch of the internet.” [12] Then there are
the technology research firms that are gauging the market opportunity. Just look at Gartner. The research
firm included generative AI in its report on seven technology disruptions that will impact sales through
2027. The report has these predictions: [13]
● 2025: Generative AI will produce about 10% of all data.
● 2025: Roughly half of drug discovery and development will use generative AI.
● 2030: Close to a third of manufacturers will use generative AI for product development.
Jensen Huang, the CEO and cofounder of Nvidia, has said that generative AI is a key part of his
company’s chip development. He says that the technology will “revolutionize communications.” [14]
Building impactful LLM apps involves challenges like prompt engineering, bias mitigation,
productionizing, and integrating external data. LangChain reduces this learning curve through its
abstractions and composable structure. Beyond basic LLM API usage, LangChain facilitates advanced
interactions like conversational context and persistence through agents and memory. This allows for
chatbots, gathering external data, and more.
In particular, LangChain’s support for chains, agents, tools, and memory allows developers to
build applications that can interact with their environment in a more sophisticated way and store
and reuse information over time. Its modular design makes it easy to build complex applications
© 2024 Electronics and Communication Department, Faculty of Engineering, University of Kufa, Iraq. All rights reserved.
5
Magazine of Student Research (MOSR)
that can be adapted to a variety of domains. Support for action plans and strategies improves
the performance and robustness of applications. The support for memory and access to external
information reduces hallucinations, thus enhancing reliability.
LangChain comes with many extensions and a larger ecosystem that is developing around it. As
mentioned, it has an immense number of integrations already, with many new ones being added every
week. This screenshot highlights a few of the integrations. [15]
2. Objective
The goal of this project is to build a virtual assistant chatbot based on the power of artificial intelligence
to realize the new era of semantic web applications. Chatbots will play a major role in the development
process of existing websites for many purposes such as business, healthcare, education, etc. to make
them available 24/7 thus reducing the burden on human employees and increasing the revenue for these
organizations. Our main objective is making the web application simple and approachable to new
learners that want to get their hands into LLMs. We would also like to implement modularity and ease of
addition of additional future features into the web application by harnessing the powers of the Python
library, LangChain.
© 2024 Electronics and Communication Department, Faculty of Engineering, University of Kufa, Iraq. All rights reserved.
6
Magazine of Student Research (MOSR)
3. Methods
3.1 Theory
The idea is quite simple to understand. There are two main forces acting to make this project work well;
a well documented and light weight front-end Python library which is Streamlit and a powerful back-end
capable of using multiple LLM and implementing them easily into our Python code. Below is a diagram
of the theory of the chatbot.
© 2024 Electronics and Communication Department, Faculty of Engineering, University of Kufa, Iraq. All rights reserved.
7
Magazine of Student Research (MOSR)
Below is the final full pseudo-code that we have gone with before starting our project:
procedure Initialize_Chatbot
import streamlit
import ChatGoogleGenerativeAI from langchain_google_genai
Initialize_Chatbot()
© 2024 Electronics and Communication Department, Faculty of Engineering, University of Kufa, Iraq. All rights reserved.
8
Magazine of Student Research (MOSR)
Why did we choose Gemini as our preferred LLM model to use as the backbone in our project? Below
are some of the main reasons that would convince most people into using Gemini as their preferred LLM
model [16]:
● Multimodality: Unlike most LLMs confined to text, Gemini seamlessly handles diverse
information types like images, audio, and code. This enables applications ranging from image
captioning and video summarization to code generation and music composition.
● Scalability: Gemini exists in various sizes, from the compact Nano model to the powerful Pro
and Ultra versions. This caters to diverse needs, from personal assistant-like functions to
resource-intensive scientific research.
● Reasoning and Planning: Gemini incorporates techniques from AlphaGo’s game-playing
prowess, allowing it to reason, plan, and make logical decisions within a given context. This
opens doors for tasks like strategic game playing and complex problem-solving.
● Safety and Control: Recognizing the potential dangers of powerful AI, Gemini prioritizes safety.
Built-in safeguards prevent responses deemed harmful or inappropriate, while safety ratings give
users transparency into the model’s decision-making process.
The architecture used to make Gemini also catches the eyes of most LLM users of how uniquely it is
built. At the heart of Gemini lies a complex architecture built on several key components [16]:
● Transformer Encoder-Decoder: This backbone of the model processes information and generates
outputs. Encoders analyze input data, extracting meaning and structure, while decoders translate
that understanding into coherent responses.
● Multimodal Embeddings: These embeddings translate diverse data (text, image, audio) into a
common language that the model can comprehend. This allows seamless integration of various
information types.
● Reinforcement Learning and Tree Search: Inspired by AlphaGo’s success, Gemini utilizes
reinforcement learning to explore potential solutions and choose the most optimal one. Tree
search further refines this process, leading to well-reasoned and effective responses.
● Knowledge Graph Integration: Gemini taps into a vast knowledge graph, constantly updated with
real-world information. This allows the model to draw on factual data and enhance its responses
with contextual relevance.
© 2024 Electronics and Communication Department, Faculty of Engineering, University of Kufa, Iraq. All rights reserved.
9
Magazine of Student Research (MOSR)
With that covered, we now tackle the question of why did we choose LangChain as our back-end used to
make our project? LangChain is a development framework specifically designed to streamline the
creation of applications powered by large language models (LLMs). Unlike traditional programming,
these applications can comprehend context and even reason about information they're given. LangChain
achieves this by providing a collection of tools that break down the development process into
manageable steps [17]:
● LangChain Libraries: These function as the building blocks, offering Python and Javascript
interfaces for various components. They also include a basic runtime environment for assembling
these components and pre-built examples to get you started quickly.
● LangChain Templates: If you're facing a common task, chances are there's a LangChain
Template already designed for it. These templates provide reference architectures that you can
easily deploy and adapt to your specific needs.
● LangServe: Once you've developed your application, LangServe allows you to seamlessly deploy
it as a REST API. This makes it easy to integrate your LLM-powered application into other
systems.
● LangSmith: This acts as your development companion, offering debugging, testing, and
monitoring functionalities. LangSmith even integrates with non-LangChain applications, making
it a versatile tool for the entire LLM development lifecycle.
By combining these tools, LangChain simplifies the entire process of building and deploying applications
that leverage the power of LLMs. You can focus on the unique functionalities of your application, while
LangChain handles the complexities of integrating and working with large language models.
© 2024 Electronics and Communication Department, Faculty of Engineering, University of Kufa, Iraq. All rights reserved.
10
Magazine of Student Research (MOSR)
4. Results
The result of our hard work has been made into a public URL that anyone can use. Although the hosting
option is free and is offered by the Python library Streamlit by a waiting list which we were lucky to
have. The page reload times are not the best in the world but the site health according to Screpy which is
an AI-based web analysis tool is 93%.
© 2024 Electronics and Communication Department, Faculty of Engineering, University of Kufa, Iraq. All rights reserved.
11
Magazine of Student Research (MOSR)
5. Challenges
Initially we started this project using the Bot framework Composer from Microsoft Azure. It was
powerful, had complete documentation and was easy to use. But the main problem we faced was that its
integration with OpenAI was regionally restricted and required time to obtain a license, which was
unfortunately not supported in Iraq. We resorted to using a Python library for coding a virtual agent client
which was called Steamship. We subscribed to it for a month before finally settling on using the best
open source Python framework for creating chatbots which is LangChain. LangChain offered a lot of
features and integrations and it was totally free and open source eliminating the need for a subscription.
6. Future Work
There are multiple improvement approaches that we might implement for our project. The main
powerful and distinctive thing about what we worked on is the ability to develop and improve the
program from more than one aspect, for example in terms of receiving and responding. Currently, the
program works by receiving data from the user through written communication, and it also sends the
response by writing. In the future, we will work on developing it to deal with the fact that the user can
listen and analyze the audio instead of writing, which will help save time and effort on the part of the
user. Also in terms of dealing with data, it currently relies on the data provided by (Gemini), and in the
future we can customize it to make it rely on special data in the event of contracting with a specific
company or entity. From the aspect of security and privacy, we will work to implement our project as a
decentralized application and try to make its backend based on blockchain technology.
7. Conclusion
In the era of speed and information, the increasing need for security, and for some tools that increase the
level of well-being, ease and speed of control and communication, the need for a virtual partner can help
humanity in various sectors, whether security, health, service or other sectors, as the virtual partner can
deal with various information, whether Whether it was personal or general information, that is, it could
be a personal assistant to a person or a general assistant to a group of people, whether they are within a
sector that serves the public or a private sector such as companies and civil centers.
The work to develop virtual assistants by harnessing the power of artificial intelligence represents a
milestone of progress for the human future. The virtual assistant offers unparalleled benefits, including
improved customer experience, reduced costs associated with using human agents, 24/7 availability,
personal interactions, and the ability to understand and understand the human user of the virtual assistant.
And by taking advantage of Open AI technology.
Companies can place virtual assistants that understand human language, provide accurate responses, and
continually improve responses through machine learning. As we look to the future, the integration of
virtual assistants is set to revolutionize industries across the board, paving the way for something more
efficient and engaging in the digital age. Embracing this transformative technology of our time will not
only drive business growth but also raise the bar of service delivery and well-being in a rapidly evolving
market.
In the end, the purpose of the virtual assistant is flexibility and facilitation of various human tasks and
moving him towards an easier life and higher well-being in all aspects of life, such as the health, security,
educational and commercial sectors.
© 2024 Electronics and Communication Department, Faculty of Engineering, University of Kufa, Iraq. All rights reserved.
12
Magazine of Student Research (MOSR)
Appendix
Below is the full code used to make the project. We’ll go by every block in detail.
import streamlit as st
import random
from langchain_google_genai import ChatGoogleGenerativeAI
© 2024 Electronics and Communication Department, Faculty of Engineering, University of Kufa, Iraq. All rights reserved.
13
Magazine of Student Research (MOSR)
Below is also the GitHub page where the full details on how someone can use this project to their own
personal interests:
© 2024 Electronics and Communication Department, Faculty of Engineering, University of Kufa, Iraq. All rights reserved.
14
Magazine of Student Research (MOSR)
Acknowledgements
This work was supported by the Electronic and Communications Department, Faculty of Engineering,
University of Kufa, Iraq. We would also like to acknowledge the support of Dr. Rabbie Hanna for giving
us permission into Al-Warith Hospital to meet the medical staff and discuss the future works that could
be done to this project.
References
[1] Auffarth, B. (2023) Generative AI with Langchain: Build large language model (LLM) apps with
python, chatgpt, and other llms. Birmingham, UK: Packt Publishing.
[2] Chui, M., Roberts, R. and Yee, L. (2022) Generative AI is here: How tools like CHATGPT could
change your business, McKinsey & Company. Available at:
http://www.mckinsey.com/capabilities/quantumblack/our-insights/generative-ai-is-here-how-tools-
like-chatgpt-could-change-your-business. (Accessed: 31 March 2024)
[3] Sonya Huang, P.G. and G.-3 (2023) Generative AI: A creative new world, Sequoia Capital.
Available at:
https://www.sequoiacap.com/article/generative-ai-a-creative-new-world/#:~:text=This%20new%2
0category%20is%20called,what%20humans%20create%20by%20hand. (Accessed: 31 March
2024)
[4] Houde, S. et al. (2020) Business (mis)use cases of generative AI for hai-gen+user2agent 2020:
IBM Research, IBM Research Publications. Available at:
https://research.ibm.com/publications/business-misuse-cases-of-generative-ai. (Accessed: 31
March 2024)
[5] Introducing make-A-video: An AI system that generates videos from text AI at Meta. Available at:
https://ai.facebook.com/blog/generative-ai-text-to-video/. (Accessed: 31 March 2024)
[6] Huge ‘Foundation Models’ are Turbo-charging Ai Progress The Economist. Available at:
http://www.economist.com/interactive/briefing/2022/06/11/huge-foundation-models-are-turbo-cha
rging-ai-progress. (Accessed: 31 March 2024)
[7] VCs try to parse through the ‘noise’ of generative AI | Pitchbook. Available at:
https://pitchbook.com/news/articles/generative-ai-venture-capital-investment. (Accessed: 31
March 2024)
[8] Sraders, A. (2023) A.I. tools like chatgpt are exploding on the internet-and one VC believes
companies could be using it in every department someday, Fortune. Available at:
https://fortune.com/2022/12/12/a-i-tools-like-chatgpt-are-exploding-on-the-internet-and-one-vc-be
lieves-companies-could-be-using-it-in-every-department-someday/. (Accessed: 31 March 2024)
[9] SkyQuest Technology Consulting Pvt. Ltd. (2022) Generative AI market to worth $63.05 billion
by 2028: Generative AI to leave biggest impact on drug discovery, Material Science, and Financial
Services, GlobeNewswire News Room. Available at:
http://www.globenewswire.com/news-release/2022/12/09/2571196/0/en/Generative-AI-Market-to-
Worth-63-05-Billion-by-2028-Generative-AI-to-Leave-Biggest-Impact-on-Drug-Discovery-Materi
al-Science-and-Financial-Services.html. (Accessed: 31 March 2024)
[10] Chatgpt has sparked an AI craze. how to build a long-term ai ... Available at:
https://www.barrons.com/articles/chatgpt-ai-invest-8aff5248. (Accessed: 31 March 2024)
[11] Sonya Huang, P.G. and G.-3 (2023a) Generative AI: A creative new world, Sequoia Capital.
Available at: http://www.sequoiacap.com/article/generative-ai-a-creative-new-world/. (Accessed:
31 March 2024)
[12] Metz, E.G. and C. (2023) A new area of A.I. booms, even amid the Tech Gloom (published 2023),
The New York Times. Available at:
http://www.nytimes.com/2023/01/07/technology/generative-ai-chatgpt-investments.html.
(Accessed: 31 March 2024)
[13] AltexSoft (2022) Generative AI models explained, AltexSoft. Available at:
http://www.altexsoft.com/blog/generative-ai/. (Accessed: 31 March 2024)
[14] Kifleswing (2022) Why Silicon Valley is so excited about awkward drawings done by artificial
intelligence, CNBC. Available at:
http://www.cnbc.com/2022/10/08/generative-ai-silicon-valleys-next-trillion-dollar-companies.html
. (Accessed: 31 March 2024)
© 2024 Electronics and Communication Department, Faculty of Engineering, University of Kufa, Iraq. All rights reserved.
View publication stats
15
🦜️🔗
Magazine of Student Research (MOSR)
[15] Providers (no date) Langchain. Available at:
https://python.langchain.com/docs/integrations/platforms/ (Accessed: 31 March 2024).
[16] Incubity, A. (2024). Gemini LLM: Deep Dive with Hands-on Implementations. [online] Incubity
by Ambiio. Available at:
https://incubity.ambilio.com/gemini-llm-deep-dive-with-hands-on-implementations/ (Accessed:
31 March 2024).
© 2024 Electronics and Communication Department, Faculty of Engineering, University of Kufa, Iraq. All rights reserved.