Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon

How-To Tutorials

7019 Articles
article-image-openchatkit-could-be-your-open-source-alternative-to-chatgpt
Julian Melanson
20 Jun 2023
5 min read
Save for later

OpenChatKit Could be Your Open-Source Alternative to ChatGPT

Julian Melanson
20 Jun 2023
5 min read
It’s no surprise that LLMs like ChatGPT and Bard possess impressive capabilities. However, it’s important to note that they are proprietary software, subject to restrictions in terms of access and usage due to licensing constraints. Consequently, this limitation has generated significant interest within the open-source community, leading to the development of alternative solutions that emphasize freedom, transparency, and community-driven collaboration.In recent months, the open-source community Together has introduced OpenChatKit, an alternative to ChatGPT, aimed at providing developers with a versatile chatbot solution. OpenChatKit utilizes the GPT-NeoX language model developed by EleutherAI, which consists of an impressive 20 billion parameters. Additionally, the model has been fine-tuned specifically for chat use with 43 million instructions. OpenChatKit's performance surpasses the base model in the industry-standard HELM benchmark, making it a promising tool for various applications.OpenChatKit Components and CapabilitiesOpenChatKit is accompanied by a comprehensive toolkit available on GitHub under the Apache 2.0 license. The toolkit includes several key components designed to enhance customization and performance:Customization recipes: These recipes allow developers to fine-tune the language model for their specific tasks, resulting in higher accuracy and improved performance.Extensible retrieval system: OpenChatKit enables developers to augment bot responses by integrating information from external sources such as document repositories, APIs, or live-updating data during inference time. This capability enhances the bot's ability to provide contextually relevant and accurate responses.Moderation model: The toolkit incorporates a moderation model derived from GPT-JT-6B, fine-tuned to filter and determine which questions the bot should respond to. This feature helps ensure appropriate and safe interactions.Feedback mechanisms: OpenChatKit provides built-in tools for users to provide feedback on the chatbot's responses and contribute new datasets. This iterative feedback loop allows for continuous improvement and refinement of the chatbot's performance.OpenChatKit's Strengths and LimitationsDevelopers highlight OpenChatKit's strengths in specific tasks such as summarization, contextual question answering, information extraction, and text classification. It excels in these areas, offering accurate and relevant responses.However, OpenChatKit's performance is comparatively weaker in tasks that require handling questions without context, coding, and creative writing—areas where ChatGPT has gained popularity. OpenChatKit may occasionally generate erroneous or misleading responses (hallucinations), a challenge that is also encountered in ChatGPT. Furthermore, OpenChatKit sometimes struggles with smoothly transitioning between conversation topics and may occasionally repeat answers.Fine-Tuning and Specialized Use CasesOpenChatKit's performance can be significantly improved by fine-tuning it for specific use cases. Together, the developers are actively working on their own chatbots designed for learning, financial advice, and support requests. By tailoring OpenChatKit to these specific domains, they aim to enhance its capabilities and deliver more accurate and contextually appropriate responses.Comparing OpenChatKit with ChatGPTIn a brief evaluation, OpenChatKit did not demonstrate the same level of eloquence as ChatGPT. This discrepancy can partly be attributed to OpenChatKit's response limit of 256 tokens, which is less than the approximately 500 tokens in ChatGPT. As a result, OpenChatKit generates shorter responses. However, OpenChatKit outperforms ChatGPT in terms of response speed, generating replies at a faster rate. The language transition between different languages does not appear to pose any challenges for OpenChatKit, and it supports formatting options like lists and tables.The Role of User Feedback in ImprovementTogether recognizes the importance of user feedback in enhancing OpenChatKit's performance and plan to leverage it for further improvement. Actively involving users in providing feedback and suggestions ensures that OpenChatKit evolves to meet user expectations and becomes increasingly useful across a wide range of applications.The Future of Decentralized Training for AI ModelsThe decentralized training approach employed in OpenChatKit, as previously seen with GPT-JT, represents a potential future for large-scale open-source projects. By distributing the computational load required for training across numerous machines instead of relying solely on a central data center, developers can leverage the combined power of multiple systems. This decentralized approach not only accelerates training but also promotes collaboration and accessibility within the open-source community.Anticipating Future DevelopmentsOpenChatKit is the pioneer among open-source alternatives to ChatGPT. However, it is likely that other similar projects will emerge. Notably, Meta's LLaMa models, which were leaked, boast parameters three times greater than GPT-NeoX-20B. With these advancements, it is only a matter of time before chatbots based on these models enter the scene.Getting Started with OpenChatKitGetting started with the program is simple:Head to https://openchatkit.net/#demo in your browserRead through the guidelines and agree to the Terms & ConditionsType your prompt into the chatboxNow you can test-drive the program and see how you like it compared to other LLMS. SummaryIn summation, OpenChatKit presents an exciting alternative to ChatGPT. Leveraging the powerful GPT-NeoX language model and extensive fine-tuning for chat-based interactions, OpenChatKit demonstrates promising capabilities in tasks such as summarization, contextual question answering, information extraction, and text classification. While some limitations exist, such as occasional hallucinations and difficulty transitioning between topics, fine-tuning OpenChatKit for specific use cases significantly improves its performance. With the provided toolkit, developers can customize the chatbot to suit their needs, and user feedback plays a crucial role in the continuous refinement of OpenChatKit. As decentralized training becomes an increasingly prominent approach in open-source projects, OpenChatKit sets the stage for further innovations in the field, while also foreshadowing the emergence of more advanced chatbot models in the future.Author BioJulian Melanson is one of the founders of Leap Year Learning. Leap Year Learning is a cutting-edge online school that specializes in teaching creative disciplines and integrating AI tools. We believe that creativity and AI are the keys to a successful future and our courses help equip students with the skills they need to succeed in a continuously evolving world. Our seasoned instructors bring real-world experience to the virtual classroom and our interactive lessons help students reinforce their learning with hands-on activities.No matter your background, from beginners to experts, hobbyists to professionals, Leap Year Learning is here to bring in the future of creativity, productivity, and learning! 
Read more
  • 0
  • 0
  • 243

article-image-build-a-project-that-automates-your-code-review
Luis Sobrecueva
19 Jun 2023
15 min read
Save for later

Build a Project that Automates your Code Review

Luis Sobrecueva
19 Jun 2023
15 min read
Developers understand the importance of a solid code review process but find it time-consuming. Language Models (LLMs) offer a solution by providing insights into code flows and enforcing best practices. A project aims to automate code reviews using LLMs, revolutionizing developers' approach. An intelligent assistant will swiftly analyze code differences, generating feedback in seconds. Imagine having an AI-powered reviewer guiding you to write cleaner, more efficient code. The focus is to streamline the code review workflow, empowering developers to produce high-quality code while saving time. The system will offer comprehensive insights through automated analysis, highlighting areas that need attention and suggesting improvements. By embracing LLMs' potential and automation, this project aims to make code reviews seamless and rewarding. Join the journey to explore LLMs' impact on code review and enhance the development experience.Project OverviewIn this article, we are developing a Python program that will harness the power of OpenAI's ChatGPT for code review. This program will read diff changes from the standard input and generate comprehensive code review comments. The generated comments will be compiled into an HTML file, which will include AI-generated feedback for each diff file section, presented alongside the diff sections themselves as code blocks with syntax highlighting. To simplify the review process, the program will automatically open the HTML file in the user's default web browser.Image 1: Project PageBuild your ProjectLet's walk through the steps to build this code review program from scratch. By following these steps, you'll be able to create your own implementation tailored to your specific needs. Let's get started:1. Set Up Your Development Environment Ensure you have Python installed on your machine. You can download and install the latest version of Python from the official Python website.2. Install Required Libraries To interact with OpenAI's ChatGPT and handle diff changes, you'll need to install the necessary Python libraries. Use pip, the package installer for Python, to install the required dependencies. You can install packages by running the following command in your terminal:pip install openai numpy3. To implement the next steps, create a new Python file named `chatgpt_code_reviewer.py`.4. Import the necessary modules:import argparse import os import random import string import sys import webbrowser import openai from tqdm import tqdm5. Set up the OpenAI API key (you'll need to get a key at https://openai.com if you don't have one yet):openai.api_key = os.environ["OPENAI_KEY"]6. Define a function to format code snippets within the code review comments, ensuring they are easily distinguishable and readable within the generated HTML report.def add_code_tags(text):    # Find all the occurrences of text surrounded by backticks    import re    matches = re.finditer(r"`(.+?)`", text)    # Create a list to store the updated text chunks    updated_chunks = []    last_end = 0    for match in matches:     # Add the text before the current match     updated_chunks.append(text[last_end : match.start()])     # Add the matched text surrounded by <code> tags     updated_chunks.append("<b>`{}`</b>".format(match.group(1)))     # Update the last_end variable to the end of the current match     last_end = match.end()    # Add the remaining text after the last match    updated_chunks.append(text[last_end:])    # Join the updated chunks and return the resulting HTML string    return "".join(updated_chunks) 7. Define a function to generate a comment using ChatGPT:def generate_comment(diff, chatbot_context):    # Use the OpenAI ChatGPT to generate a comment on the file changes    chatbot_context.append(     {           "role": "user",           "content": f"Make a code review of the changes made in this diff: {diff}",     }    )    # Retry up to three times    retries = 3    for attempt in range(retries):     try:           response = openai.ChatCompletion.create(                 model="gpt-3.5-turbo",                 messages=chatbot_context,                 n=1,                 stop=None,                 temperature=0.3,           )     except Exception as e:           if attempt == retries - 1:                 print(f"attempt: {attempt}, retries: {retries}")                 raise e  # Raise the error if reached maximum retries           else:                 print("OpenAI error occurred. Retrying...")                 continue    comment = response.choices[0].message.content    # Update the chatbot context with the latest response    chatbot_context = [     {           "role": "user",                 "content": f"Make a code review of the changes made in this diff: {diff}",     },     {           "role": "assistant",           "content": comment,     }    ]    return comment, chatbot_context  The `generate_comment` function defined above uses the OpenAI ChatGPT to generate a code review comment based on the provided `diff` and the existing `chatbot_context`. It appends the user's request to review the changes in the `chatbot_context`. The function retries the API call up to three times to handle any potential errors. It makes use of the `openai.ChatCompletion.create()` method and provides the appropriate model, messages, and other parameters to generate a response. The generated comment is extracted from the response, and the chatbot context is updated to include the latest user request and assistant response. Finally, the function returns the comment and the updated chatbot context.This function will be a crucial part of the code review program, as it uses ChatGPT to generate insightful comments on the provided code diffs.8. Define a function to create the HTML output:def create_html_output(title, description, changes, prompt): random_string = "".join(random.choices(string.ascii_letters, k=5))    output_file_name = random_string + "-output.html"    title_text = f"\nTitle: {title}" if title else ""    description_text = f"\nDescription: {description}" if description else ""    chatbot_context = [     {           "role": "user",           "content": f"{prompt}{title_text}{description_text}",     }    ]    # Generate the HTML output    html_output = "<html>\n<head>\n<style>\n"    html_output += "body {\n    font-family: Roboto, Ubuntu, Cantarell, Helvetica Neue, sans-serif;\n    margin: 0;\n    padding: 0;\n}\n"    html_output += "pre {\n    white-space: pre-wrap;\n    background-color: #f6f8fa;\n    border-radius: 3px;\n  font-size: 85%;\n    line-height: 1.45;\n    overflow: auto;\n    padding: 16px;\n}\n"    html_output += "</style>\n"    html_output += '<link rel="stylesheet"\n href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css">\n <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>\n'    html_output += "<script>hljs.highlightAll();</script>\n"    html_output += "</head>\n<body>\n"    html_output += "<div style='background-color: #333; color: #fff; padding: 20px;'>"    html_output += "<h1 style='margin: 0;'>AI code review</h1>"    html_output += f"<h3>Diff to review: {title}</h3>" if title else ""    html_output += "</div>"    # Generate comments for each diff with a progress bar    with tqdm(total=len(changes), desc="Making code review", unit="diff") as pbar:     for i, change in enumerate(changes):           diff = change["diff"]           comment, chatbot_context = generate_comment(diff, chatbot_context)           pbar.update(1)           # Write the diff and comment to the HTML           html_output += f"<h3>Diff</h3>\n<pre><code>{diff}</code></pre>\n"           html_output += f"<h3>Comment</h3>\n<pre>{add_code_tags(comment)}</pre>\n"    html_output += "</body>\n</html>"    # Write the HTML output to a file    with open(output_file_name, "w") as f:     f.write(html_output)    return output_file_name The `create_html_output` function defined above takes the `title`, `description`, `changes`, and `prompt` as inputs. It creates an HTML output file that contains the code review comments for each diff, along with the corresponding diff sections as code blocks with syntax highlighting. Let's explain it in more detail:First, the function initializes a random string to be used in the output file name. It creates the appropriate title and description text based on the provided inputs and sets up the initial `chatbot_context`. Next, the function generates the HTML structure and styling, including the necessary CSS and JavaScript libraries for syntax highlighting. It also includes a header section for the AI code review. Using a progress bar, the function iterates over each change in the changes list. For each change, it retrieves the `diff` and generates a comment using the `generate_comment` function. The progress bar is updated accordingly. The function then writes the `diff` and the corresponding comment to the HTML output. The `diff` is displayed within a `<pre><code>` block for better formatting, and the comment is wrapped in `<pre>` tags. The `add_code_tags` function is used to add code tags to the comment, highlighting any code snippets. After processing all the changes, the function completes the HTML structure by closing the `<body>` and `<html>` tags.Finally, the HTML output is written to a file with a randomly generated name. The file name is returned by the function as the output. This `create_html_output` function makes the final HTML output that presents the code review comments alongside the corresponding diff sections.9. Define a function to get diff changes from the pipeline:def get_diff_changes_from_pipeline():    # Get the piped input    piped_input = sys.stdin.read()    # Split the input into a list of diff sections    diffs = piped_input.split("diff --git")    # Create a list of dictionaries, where each dictionary contains a single diff section    diff_list = [{"diff": diff} for diff in diffs if diff]    return diff_list The `get_diff_changes_from_pipeline` function defined above retrieves the input from the pipeline, which is typically the output of a command like `git diff`. It reads the piped input using the`sys.stdin.read()`. The input is then split based on the "diff --git" string, which is commonly used to separate individual diff sections. This splits the input into a list of diff sections. By dividing the diff into separate sections, this function enables code reviews of very large projects. It overcomes the context limitation that LLMs have by processing each diff section independently. This approach allows for efficient and scalable code reviews, ensuring that the review process can handle projects of any size. The function returns the list of diff sections as the output, which can be further processed and utilized in the code review pipeline10. Define the main function:def main():    title, description, prompt = None, None, None    changes = get_diff_changes_from_pipeline()    # Parse command line arguments    parser = argparse.ArgumentParser(description="AI code review script")    parser.add_argument("--title", type=str, help="Title of the diff")    parser.add_argument("--description", type=str, help="Description of the diff")    parser.add_argument("--prompt", type=str, help="Custom prompt for the AI")    args = parser.parse_args()    title = args.title if args.title else title    description = args.description if args.description else description    prompt = args.prompt if args.prompt else PROMPT_TEMPLATE    output_file = create_html_output(title, description, changes, prompt)    try:     webbrowser.open(output_file)    except Exception:     print(f"Error running the web browser, you can try to open the outputfile: {output_file} manually") if __name__ == "__main__":    main() The `main` function serves as the entry point of the code review script. It begins by initializing the `title`, `description`, and `prompt` variables as `None`. Next, it calls the `get_diff_changes_from_pipeline` function to retrieve the diff changes from the pipeline. These changes will be used for the code review process. The script then parses the command line arguments using the `argparse` module. It allows specifying optional arguments such as `--title`, `--description`, and `--prompt` to customize the code review process. The values provided through the command line are assigned to the corresponding variables, overriding the default `None` values. After parsing the arguments, the `create_html_output` function is called to generate the HTML output file. The `title`, `description`, `changes`, and `prompt` is passed as arguments to the function. The output file name is returned and stored in the `output_file` variable. Finally, the script attempts to open the generated HTML file in the default web browser using the `webbrowser` module. If an error occurs during the process, a message is printed, suggesting manually opening the output file.11. Save the file and run it using the following command: git diff master..branch | python3 chatgpt_code_reviewer.pyA progress bar will be displayed and after a while, the browser will open an html file with the output of the command, depending on the number of files to review it may take a few seconds or a few minutes, in this video, you can see the process. Congratulations! You have now created your own ChatGPT code reviewer project from scratch. Remember to adapt and customize the prompt[1] based on your specific requirements and preferences. You can find the complete code on this ChatGPTCodeReviewer GitHub repository.Happy coding! Article Reference[1] The `prompt` is an essential component of the code review process using ChatGPT. It is typically a text that sets the context and provides instructions to the AI model about what is expected from its response like what it needs to review, specific questions, or guidelines to focus the AI's attention on particular aspects of the code.In the code, a default `PROMPT_TEMPLATE` is used if no custom prompt is provided. You can modify the `PROMPT_TEMPLATE` variable or pass your prompt using the `--prompt` argument to tailor the AI's behavior according to your specific requirements.By carefully crafting the prompt, you can help steer the AI's responses in a way that aligns with your code review expectations, ensuring the generated comments are relevant, constructive, and aligned with the desired code quality standards.Author Bio Luis Sobrecueva is a software engineer with many years of experience working with a wide range of different technologies in various operating systems, databases, and frameworks. He began his professional career developing software as a research fellow in the engineering projects area at the University of Oviedo. He continued in a private company developing low-level (C / C ++) database engines and visual development environments to later jump into the world of web development where he met Python and discovered his passion for Machine Learning, applying it to various large-scale projects, such as creating and deploying a recommender for a job board with several million users. It was also at that time when he began to contribute to open source deep learning projects and to participate in machine learning competitions and when he took several ML courses obtaining various certifications highlighting a MicroMasters Program in Statistics and Data Science at MIT and a Udacity Deep Learning nanodegree. He currently works as a Data Engineer at a ride-hailing company called Cabify, but continues to develop his career as an ML engineer by consulting and contributing to open-source projects such as OpenAI and Autokeras.Author of the book: Automated Machine Learning with AutoKeras 
Read more
  • 0
  • 0
  • 833

article-image-help-chatgpt-improve-with-knowledge-graphs
Maxime Labonne
17 Jun 2023
9 min read
Save for later

Help ChatGPT Improve with Knowledge Graphs

Maxime Labonne
17 Jun 2023
9 min read
ChatGPT has shown impressive capabilities in processing and generating human-like text. However, it is not without its imperfections. A primary concern is the model's propensity to produce either inaccurate or obsolete answers, often called "hallucinations."The New York Times recently highlighted this issue in their article, "Here's What Happens When Your Lawyer Uses ChatGPT." It presents a lawsuit where a lawyer leaned heavily on ChatGPT to assist in preparing a court filing for a client suing an airline. The model generated fictional court decisions to back its arguments, which didn't go unnoticed. This incident underscores the need for solutions to ground AI models like ChatGPT and improve their performance.To address this, we propose an approach that focuses on augmenting ChatGPT using a knowledge graph. This method aims to provide a structured context, ensuring the model outputs are accurate but also relevant and up-to-date. By bridging the gap between the unstructured textual world of ChatGPT and the structured clarity of knowledge graphs, we strive to enhance the effectiveness and reliability of AI language models.All the code used in this article is available on Google Colab and on GitHub.What is a knowledge graph?A knowledge graph is a structured format of knowledge representation, usually composed of entities and relationships. In a typical knowledge graph, entities are the nodes, and the relationships between them are the edges. The graph-based representation allows complex relationships to be modeled in a way that's intuitive and closer to human understanding. Here is a simple illustration of a knowledge graph: Source: Wikipedia. CC BY-SA 4.0 Google has been using knowledge graphs since 2012 to provide additional contextual information and sources. The structured representation of data offers a new dimension of context to the AI model, grounding it in validated knowledge.Applying Knowledge Graphs to Improve ChatGPTA crucial limitation of ChatGPT is its lack of real-time information updates. Since the model was last trained using data up until 2021, it doesn't have access to events, data, or context after that year. This leads to ChatGPT having outdated or incomplete information about events, technological advancements, or other critical happenings post-2021.Let's illustrate this limitation by asking ChatGPT about a recent event, When did Apple announce the Vision Pro?. Given the model's knowledge cutoff in 2021, we would expect it to be unaware of this announcement, which happened in 2023.!pip install -q openai langchain import os import openai os.environ['OPENAI_API_KEY'] = "your OpenAI key" openai.api_key = os.environ['OPENAI_API_KEY'] question = "When did apple announced the Vision Pro?" completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", temperature=0, messages=[{"role": "user", "content": question}]) print(completion["choices"][0]["message"]["content"]) As an AI language model, I do not have access to current events or real-time information. However, as of my last training data, Apple has not announced any product called "Vision Pro." It is possible that this product does not exist or has not been announced yet. As expected, ChatGPT is unable to provide the correct answer due to its training data limitations. This clearly highlights the need for constant updates to the model's knowledge base, which can be addressed by integrating it with a continuously updated knowledge graph.By implementing such a knowledge graph, we can ensure that ChatGPT can provide accurate, current, and reliable information, effectively addressing the "hallucination" issues as well as the knowledge cutoff limitations.Sentence-Level Knowledge GraphsTo demonstrate this, we'll use the LangChain library, a powerful tool designed for building frameworks around large language models. The library includes a component called GraphIndexCreator, which can parse a sentence and create a knowledge graph. This component is currently limited and cannot process long corpus of text, but it serves as a perfect starting point for our experiment.Let's start with a straightforward sentence: "Apple announced the Vision Pro in 2023."from langchain.llms import OpenAI from langchain.indexes import GraphIndexCreator from langchain.chains import GraphQAChain from langchain.prompts import PromptTemplate text = "Apple announced the Vision Pro in 2023." index_creator = GraphIndexCreator(llm=OpenAI(temperature=0)) graph = index_creator.from_text(text) graph.get_triples()[('Apple', 'Vision Pro', 'announced'), ('Vision Pro', '2023', 'was announced in')] By feeding this sentence into the GraphIndexCreator, it creates a knowledge graph by identifying the sentence's entities and relationships, forming triplets of information in the format of (source node, relation, and target node). However, the GraphIndexCreator might get confused with the relations and target nodes due to the inherent complexity of natural language.Even though it's a tiny graph based on a single sentence, we can represent it visually using popular Python libraries such as matplotlib and networkx.import networkx as nx import matplotlib.pyplot as plt # Create graph G = nx.DiGraph() G.add_edges_from((source, target, {'relation': relation}) for source, relation, target in graph.get_triples()) # Plot the graph plt.figure(figsize=(8,5), dpi=300) pos = nx.spring_layout(G, k=3, seed=0) nx.draw_networkx_nodes(G, pos, node_size=2000) nx.draw_networkx_edges(G, pos, edge_color='gray') nx.draw_networkx_labels(G, pos, font_size=12) edge_labels = nx.get_edge_attributes(G, 'relation') nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=10) # Display the plot plt.axis('off') plt.show() Image 2: Visual Pro Graph Now, let's enhance ChatGPT using the knowledge graph. We will use another component of the LangChain library, GraphQAChain, to this end.Initializing the GraphQAChain, we input the same question we asked earlier, "When did Apple announce the Vision Pro?". This time, ChatGPT leverages the knowledge graph we've just built.chain = GraphQAChain.from_llm(OpenAI(temperature=0), graph=graph, verbose=True) chain.run(question)> Entering new GraphQAChain chain...Entities Extracted: Apple, Vision ProFull Context:Apple announced Vision ProVision Pro was announced in 2023> Finished chain. Apple announced Vision Pro in 2023.This time, ChatGPT was able to output the correct information! The good thing is that we don't need any parser to build our knowledge graphs and can use existing ones. In the next experiment, let's try to use a bigger graph and see if it's still as performant.Bigger Knowledge GraphsIn this experiment, we manually create this more complex graph by supplying a list of triplets to the GraphIndexCreator object using the add_triple() method. Each triplet represents a distinct piece of knowledge related to Apple, such as the products it has created or where it is located.from langchain.graphs.networkx_graph import KnowledgeTriple # Knowledge graph kg = [ ('Apple', 'is', 'Company'), ('Apple', 'created', 'iMac'), ('Apple', 'created', 'iPhone'), ('Apple', 'created', 'Apple Watch'), ('Apple', 'created', 'Vision Pro'), ('Apple', 'developed', 'macOS'), ('Apple', 'developed', 'iOS'), ('Apple', 'developed', 'watchOS'), ('Apple', 'is located in', 'USA'), ('Steve Jobs', 'co-founded', 'Apple'), ('Steve Wozniak', 'co-founded', 'Apple'), ('Tim Cook', 'is the CEO of', 'Apple'), ('iOS', 'runs on', 'iPhone'), ('macOS', 'runs on', 'iMac'), ('watchOS', 'runs on', 'Apple Watch'), ('Apple', 'was founded in', '1976'), ('Apple', 'owns', 'App Store'), ('App Store', 'sells', 'iOS apps'), ('iPhone', 'announced in', '2007'), ('iMac', 'announced in', '1998'), ('Apple Watch', 'announced in', '2014'), ('Vision Pro', 'announced in', '2023'), ] graph = index_creator.from_text('') for (node1, relation, node2) in kg: graph.add_triple(KnowledgeTriple(node1, relation, node2))Although we could include many more triplets (real-world knowledge graphs often encompass millions of nodes), the size of our graph for this demonstration is sufficient. When visualized, this more extensive knowledge graph exhibits greater complexity and a richer depiction of information.# Create directed graph G = nx.DiGraph() for node1, relation, node2 in kg: G.add_edge(node1, node2, label=relation) # Plot the graph plt.figure(figsize=(25, 25), dpi=300) pos = nx.spring_layout(G, k=2, iterations=50, seed=0) nx.draw_networkx_nodes(G, pos, node_size=5000) nx.draw_networkx_edges(G, pos, edge_color='gray', edgelist=G.edges(), width=2) nx.draw_networkx_labels(G, pos, font_size=12) edge_labels = nx.get_edge_attributes(G, 'label') nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=12) # Display the plot plt.axis('off') plt.show()Image 4: Larger GraphWith this larger graph, we once again ask ChatGPT the question: "When did Apple announce the Vision Pro?" Leveraging the GraphQAChain object, ChatGPT processes the information embedded in the knowledge graph.chain = GraphQAChain.from_llm(OpenAI(temperature=0), graph=graph, verbose=True) chain.run(question)> Entering new GraphQAChain chain...Entities Extracted: Apple, Vision ProFull Context:Apple is CompanyApple created iMacApple created iPhoneApple created Apple WatchApple created Vision ProApple developed macOSApple developed iOSApple developed watchOSApple is located in USAApple was founded in 1976Apple owns App StoreVision Pro announced in 2023> Finished chain. Apple announced the Vision Pro in 2023.ChatGPT successfully extracts the correct information from the more expansive knowledge graph. This result demonstrates that our model can not only scale to larger graphs but can also efficiently navigate a more extensive knowledge base.The possibilities for implementing larger and more diverse knowledge graphs are practically endless. They can be populated with data from various sources, such as legal documents, code documentation, scientific literature, and more, enhancing the AI's understanding and response accuracy across multiple domains. The integration of ChatGPT and knowledge graphs thus holds immense promise for future AI development.ConclusionAs seen in our experiments, knowledge graphs can significantly aid in grounding and improving ChatGPT's outputs. A key challenge with large knowledge graphs is finding connections between distant nodes, a problem often referred to as graph completion. Successfully addressing this issue would allow ChatGPT to make insightful connections and propose new ideas based on the information available in the knowledge graph.However, the process of integrating knowledge graphs into language models like ChatGPT is still an evolving field. To further explore the various applications and delve into the details of implementing knowledge graphs, consider the book "Hands-On Graph Neural Networks Using Python", which provides a comprehensive guide on this subject. Through this type of research and experimentation, we can continuously improve AI's ability to understand and generate text, moving us closer to more reliable and grounded AI models.Author BioMaxime Labonne is a senior applied researcher at J.P. Morgan with a Ph.D. in machine learning and cyber security from the Polytechnic Institute of Paris.During his Ph.D., Maxime worked on developing machine learning algorithms for anomaly detection in computer networks. He then joined the AI Connectivity Lab at Airbus, where he applied his expertise in machine learning to improve the security and performance of computer networks. He then joined J.P. Morgan, where he develops techniques to solve a variety of challenging problems in finance and other domains.In addition to his research work, Maxime is passionate about sharing his knowledge and experience with others through Twitter (@maximelabonne) and his personal blog.
Read more
  • 0
  • 0
  • 603

article-image-making-the-best-out-of-hugging-face-hub-using-langchain
Ms. Valentina Alto
17 Jun 2023
6 min read
Save for later

Making the best out of Hugging Face Hub using LangChain

Ms. Valentina Alto
17 Jun 2023
6 min read
Since the launch of ChatGPT in November 2022, everyone is talking about GPT models and OpenAI. There is no doubt that the Generative Pre-trained Transformers (GPT) architecture developed by OpenAI has demonstrated incredible results, also given the investments in training (almost 500 billion tokens) and complexity of the model (175 billion parameters for the GPT-3).Nevertheless, there is an incredible number of open-source Large Language Models (LLMs) that have been widespread in the last months. Below are some examples:Dolly: 12 billion parameters LLM developed by Databricks and trained on their ML platform. Source codeàhttps://github.com/databrickslabs/dollyStableML: This is a series of LLM developed by StabilityAI, the company behind the popular image generation model Stable Diffusion. The series encompasses a variety of LLMs, some of which are fine-tuned on specific use cases. Source codeàhttps://github.com/Stability-AI/StableLMFalcon LLM: A 40 billion parameters LLM developed by the Technology Innovation Institute and trained on a particularly high-quality dataset called RefinedWeb. Plus, as for now (June 2023) ranks 1 globally in the latest Hugging Face independent verification of open-source AI models. Source codeà https://huggingface.co/tiiuaeGPT NeoX and GPT-J: An open-source reproduction of the OpenAI’s GPT series developed by Eulether AI, with respectively 40 and 6 billion parameters. Source codeà https://huggingface.co/EleutherAI/gpt-neox-20b and https://huggingface.co/EleutherAI/gpt-j-6bOpenLLaMa: As for the previous class of models, also this one is an open-source reproduction of Meta AI’s LLaMA and has 3.7 billion parameters. Source codeàhttps://github.com/openlm-research/open_llamaIf you are interested in getting deeper into those models and their performance, you can reference the Hugging Face leaderboard here.Image1: Hugging Face Leaderboard Now, LLMs are great, yet to unlock their real power we need them to be positioned within an applicative logic. In other words, we want our LLMs to infuse intelligence within our applications.For this purpose, we will be using LangChain, a powerful lightweight SDK which makes it easier to integrate and orchestrate LLMs within applications. LangChain is one of the most popular LLMs orchestrators, yet if you want to explore further packages I encourage you to read about Semantic Kernel and Jarvis.One of the nice things about LangChain is its integration with external tools: those might be OpenAI (and other LLMs vendors), data sources, search APIs, and so on. In this article, we are going to explore how LangChain makes it easier to leverage open-source LLMs by leveraging its integration with the Hugging Face Hub.Welcome to the realm of open source LLMsThe Hugging Face Hub serves as a comprehensive platform comprising more than 120k models, 20kdatasets, and 50k demo apps (Spaces), all of which are openly accessible and shared as open-source projects. It provides an online environment where developers can effortlessly collaborate and collectively develop machine learning solutions. Thanks to LangChain, it is way easier to start interacting with open-source LLMs. Plus, you can also surround those models with all the libraries provided by LangChain in terms of prompt design, memory retention, chain management, and so on.Let’s see an implementation with Python. To reproduce the code, make sure to have: Python 3.7.1 or higheràyou can check your Python version running python --version in your terminalLangChain installedàyou can install it via pip install langchainThe huggingface_hub Python package installedà you can install it via pip install huggingface_butHugging Face Hub API keyàto get the API key, you can register into the portal here and then generate your secret key.For this example, I’m going to use the lightest version of Dolly, developed by Databricks and available in three sizes: 3, 7, and 12 billion parameters.from langchain import HuggingFaceHub from getpass import getpass HUGGINGFACEHUB_API_TOKEN = "your-api-key" import os os.environ["HUGGINGFACEHUB_API_TOKEN"] = HUGGINGFACEHUB_API_TOKEN repo_id = " databricks/dolly-v2-3b" llm = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature":0, "max_length":64})As you can see from the above code, the only information we need are our Hugging Face Hub API key and the model’s repo ID; then, LangChain will take care of initializing our model thanks to the direct integration with Hugging Face Hub.Now that we have initialized our model, it is time to define the structure of the prompt:from langchain import PromptTemplate, LLMChain template = """Question: {question} Answer: Let's think step by step.""" prompt = PromptTemplate(template=template, input_variables=["question"]) llm_chain = LLMChain(prompt=prompt, llm=llm)Finally, we can feed our model with a first question:question = "In the first movie of Harry Potter, what is the name of the three-headed dog? “ print(llm_chain.run(question)) Output: The name of the three-headed dog in Harry Potter and the Philosopher Stone is Fuffy.Even though I tested the light version of Dolly with “only” 3 billion parameters, it came with pretty accurate results. Of course, for more complex tasks or real-world projects, heavier models might be taken into consideration, like the one emerging as top performers in the Hugging Face leaderboard mentioned at the beginning of this article.ConclusionThe realm of open-source LLM is growing exponentially, and this creates a vibrant environment of experimentation and tuning from which anyone can benefit. Plus, some interesting trends are rising, like the reduction of the number of models’ parameters in favour of an increase in quality of the training dataset. In fact, we saw that the current top performer among the open source model is Falcon LLM, with “only” 40 billion parameters, which gained its strength from the high-quality training dataset. Finally, with the development of orchestration frameworks like LangChain and similar, it’s getting easier and easier to leverage open source LLMs and integrate them into our applications. Referenceshttps://huggingface.co/docs/hub/indexOpen LLM Leaderboard — a Hugging Face Space by HuggingFaceH4Hugging Face Hub — 🦜🔗 LangChain 0.0.189Overview (huggingface.co)stabilityai (Stability AI) (huggingface.co)Stability-AI/StableLM: StableLM: Stability AI Language Models (github.com)Author BioValentina Alto graduated in 2021 in data science. Since 2020, she has been working at Microsoft as an Azure solution specialist, and since 2022, she has been focusing on data and AI workloads within the manufacturing and pharmaceutical industries. She has been working closely with system integrators on customer projects to deploy cloud architecture with a focus on modern data platforms, data mesh frameworks, IoT and real-time analytics, Azure Machine Learning, Azure Cognitive Services (including Azure OpenAI Service), and Power BI for dashboarding. Since commencing her academic journey, she has been writing tech articles on statistics, machine learning, deep learning, and AI in various publications and has authored a book on the fundamentals of machine learning with Python.Author of the book: Modern Generative AI with ChatGPT and OpenAI ModelsLink - Medium  LinkedIn  
Read more
  • 0
  • 0
  • 1222
Banner background image

article-image-creating-a-data-model-with-chatgpt-is-easier-than-you-think
Sagar Lad
16 Jun 2023
6 min read
Save for later

Creating a Data Model with ChatGPT is Easier than you think

Sagar Lad
16 Jun 2023
6 min read
In today's data-driven world, the ability to build accurate and efficient data models is paramount for businesses and individuals alike. However, the process of constructing a data model can often be complex and daunting, requiring specialized knowledge and technical skills. But what if there was a way to simplify this process and make it accessible to a wider audience? Enter ChatGPT, a powerful language model developed by OpenAI. In this article, we will explore how ChatGPT can be leveraged to build data models easily, using a practical example. By harnessing the capabilities of ChatGPT, you'll discover how data modeling can become a more approachable and intuitive task for everyone, regardless of their technical background.Build Data Model with ChatGPTConsider data modeling as the process of drawing diagrams for software applications that provide an overview of all the data pieces they include. The data flow is depicted in the diagram using text and symbols. It serves as a model for creating a new database that will allow a company to utilize the data efficiently for its needs. The primary objective of the data model is to establish an overall picture of the types of data that are used, how they are kept in the system, the relationships between the data entities, and the various ways in which they can be arranged and grouped. The norms and procedures for gathering feedback from the business stakeholders are taken into consideration when building data models.The Data Model functions as a better understanding of what is designed, much like a roadmap or blueprint might. It offers a comprehensive review of the standardized methodologies and schema to define and manage data in a way that is common and uniform throughout the organization. According to the level of abstraction, there are three different types of data models.Conceptual Data Model: It provides a helicopter view of the system description, its organization, and business rules to be considered. Initial project requirements are captured using the conceptual model. It mainly consists of the business entities, their constraints and characteristics, and the relationship between them for data integrity and security requirements.Logical Data Model: The logical data model provides detailed insights into the concepts and relationship which consists of data attributes and the relationship between the entities. It is very much useful for data-driven projects or initiatives.Physical Data Model: It provides an overview of how the data should be stored physically within the database. It is a final design to implement the relational database including the relationship using the primary and foreign keys.                           Image 1 : Types of Data Modelling TechniquesThe data model was created using a variety of data modeling methodologies, as seen in the graphic above. The most popular data modeling technique utilized by any corporate organization is entity relationship modeling, also known as dimensional modeling. Erwin Data Modeler, ER/Studio, Archi, and other tools are available on the market to construct data models utilizing these data modeling methodologies. The data Modelling technique mainly involves below steps :  Identify the entitiesFind the entity propertiesCreate a relationship between the entitiesCorrelated attributes to the entityDefine the degree of normalization to improve the performanceValidate and Finalise the data modelLet’s start with creating a data model using chatGPT. The goal is to ask chatGPT to start with the data modeling activities for the anti-money laundering(AML) system of a banking domain: Image 1: The data model for the banking system, Part 1  Image 2: Data Modelling  for AML Process for Bank As you can see in the image, once we provide an input to the chatGPT, it provides a step-by-step process of building the data model. The first step is to understand the AML regulations and identify the stakeholders for the system to capture the requirements. Once the stakeholders are identified, the next step is to define the data modeling goals including the list of data sources, and perform the data profiling. Once data profiling steps are done, the next activity is to create a conceptual, logical, and physical data model.Now, Let’s check with chatGPT to create a conceptual model with all the entities. Image 3: Conceptual Data Model, Part 1                 Image 4 : AML Conceptual ModelAfter the input, chatGPT responds with the list of actors, entities, and relationships between the entities to define the conceptual model. With this information, we can have a high-level overview of the system by building the conceptual data model. Let’s ask chatGPT to build the logical data model once the conceptual data model is ready:Image 5: AML data model for ERwin Tool                  Image 6 : AML Logical Data Model, Part 2 As you can see in the above image, step by step process to create a logical data model is to open the Erwin Tool and create a new data model. In the new data model, add all entities, their attributes, and the relationship between the entities. Once entities are defined, set up primary and foreign keys for all entities and validate the data model. After the validation, adjust the review comments and finalize the logical data model and generate the documentation for the same.Next, Let’s ask chatGPT if it can add new customer information to the existing conceptual model.                  Image 5 : AML Logical Data Model with Customer Information As we can see in the above image, chatGPT asks to first identify the source information and create an entity and attributes for the same. Once it is done, we have to define the cardinality to understand how entities are related to each other. Then define primary and foreign key relationships, data model validation and generate documentation.ConclusionIn this article, we understood the importance of building the data model and step by step process to create the data model. Later in this article, we also checked how to use chatGPT to create conceptual and logical data models.Author BioSagar Lad is a Cloud Data Solution Architect with a leading organisation and has deep expertise in designing and building Enterprise-grade Intelligent Azure Data and Analytics Solutions. He is a published author, content writer, Microsoft Certified Trainer, and C# Corner MVP.Link - Medium , Amazon , LinkedIn 
Read more
  • 0
  • 0
  • 966

article-image-microsoft-fabric-revolutionizing-data-analytics-and-ai-integration
Julian Melanson
15 Jun 2023
7 min read
Save for later

Microsoft Fabric: Revolutionizing Data Analytics and AI Integration

Julian Melanson
15 Jun 2023
7 min read
In today's data-driven world, organizations are constantly seeking ways to unlock the full potential of their data and seamlessly integrate artificial intelligence into their operations. Addressing this need, Microsoft has introduced Microsoft Fabric at the Build 2023 developer conference. This cutting-edge data analytics platform brings together essential data and analytics tools into a unified software-as-a-service (SaaS) product. In this article, we will explore the features of Microsoft Fabric, uncovering how it simplifies AI integration and revolutionizes data analytics, empowering organizations to harness the power of their data.A Holistic Approach to Data AnalyticsMicrosoft Fabric offers a holistic solution by integrating platforms such as Data Factory, Synapse, and Power BI into a cohesive and comprehensive platform. By replacing disparate systems with a simplified and cost-effective platform, Microsoft Fabric provides organizations with a unified environment for AI integration. It consolidates essential components like data integration, data engineering, data warehousing, data science, real-time analytics, applied observability, and business intelligence into a single ecosystem, equipping data professionals with a comprehensive suite of tools.Core Workloads in Microsoft Fabric:Microsoft Fabric supports seven core workloads that cater to various aspects of data analytics and AI integration, ensuring a seamless end-to-end experience:Data Factory: This workload facilitates seamless data integration by offering over 150 connectors to popular cloud and on-premises data sources. With its user-friendly drag-and-drop functionality, Data Factory simplifies data integration tasks.Synapse Data Engineering: With a focus on data engineering, this workload promotes collaboration among data professionals, streamlining the data engineering workflow and ensuring efficient data processing.Synapse Data Science: Designed for data scientists, this workload enables the development, training, deployment, and management of AI models. It offers an end-to-end workflow and infrastructure support for streamlined AI development.Synapse Data Warehousing: This workload provides a converged lake house and data warehousing experience. Optimizing SQL performance on open data formats, it offers efficient and scalable data warehousing capabilities.Synapse Real-Time Analytics: Tailored for handling high volumes of streaming data, this workload enables developers to analyze semi-structured data in real time with minimal latency. It caters to IoT devices, telemetry, and log data.Power BI Integration: Microsoft Fabric seamlessly integrates powerful visualization capabilities and AI-driven analytics from Power BI. This integration empowers business analysts and users to derive valuable insights through visually appealing representations.Data Activator: This workload offers a no-code experience for real-time data detection and monitoring. By triggering notifications and actions based on predefined data patterns, Data Activator ensures proactive data management.Simplifying AI DevelopmentMicrosoft Fabric addresses the challenges organizations face in AI development by providing a unified platform that encompasses all necessary capabilities to extract insights from data and make them accessible to AI models or end users. To enhance usability, Fabric integrates its own copilot tool, allowing users to interact with the platform using natural language commands and a chat-like interface. This feature streamlines code generation, query creation, AI plugin development, custom Q&A, visualization creation, and more.The Power of OneLake and Integration with Microsoft 365Microsoft Fabric is built upon the OneLake open data lake platform, which serves as a central repository for data. OneLake eliminates the need for data extraction, replication, or movement, acting as a single source of truth. This streamlined approach enhances data governance while offering a scalable pricing model that aligns with usage. Furthermore, Fabric seamlessly integrates with Microsoft 365 applications, enabling users to discover and analyze data from OneLake directly within tools such as Microsoft Excel. This integration empowers users to generate Power BI reports with a single click, transforming data analysis into a more intuitive and efficient process. Additionally, Fabric enables users of Microsoft Teams to bring data directly into their chats, channels, meetings, and presentations, expanding the reach of data-driven insights. Moreover, sales professionals using Dynamics 365 can leverage Fabric and OneLake to unlock valuable insights on customer relationships and business processes.Getting Started with Microsoft FabricFollow these steps to start your Fabric (Preview) trial.Open the Fabric homepage and select the Account Manager.In the Account Manager, select Start Trial.If prompted, agree to the terms and then select Start Trial.Once your trial capacity is ready, you receive a confirmation message. Select Got it to begin working in Fabric.Open your Account manager again. Notice that you now have a heading for Trial status. Your Account manager keeps track of the number of days remaining in your trial. You also see the countdown in your Fabric menu bar when you work on a product experience.You now have a Fabric (Preview) trial that includes a Power BI individual trial (if you didn't already have a Power BI paid license) and a Fabric (Preview) trial capacity.Below is a list of end-to-end tutorials available in Microsoft Fabric with links to Microsoft’s website.Multi-experience tutorialsThe following table lists tutorials that span multiple Fabric experiences.Tutorial nameScenarioLakehouseIn this tutorial, you ingest, transform, and load the data of a fictional retail company, Wide World Importers, into the lakehouse and analyze sales data across various dimensions.Data ScienceIn this tutorial, you explore, clean, and transform a taxicab trip dataset, and build a machine-learning model to predict trip duration at scale on a large dataset.Real-Time AnalyticsIn this tutorial, you use the streaming and query capabilities of Real-Time Analytics to analyze the New York Yellow Taxi trip dataset. You uncover essential insights into trip statistics, taxi demand across the boroughs of New York, and other related insights.Data warehouseIn this tutorial, you build an end-to-end data warehouse for the fictional Wide World Importers company. You ingest data into a data warehouse, transform it using T-SQL and pipelines, run queries, and build reports.Experience-specific tutorialsThe following tutorials walk you through scenarios within specific Fabric experiences.Tutorial nameScenarioPower BIIn this tutorial, you build a dataflow and pipeline to bring data into a lakehouse, create a dimensional model, and generate a compelling report.Data FactoryIn this tutorial, you ingest data with data pipelines and transform data with dataflows, then use the automation and notification to create a complete data integration scenario.Data Science end-to-end AI samplesIn this set of tutorials, learn about the different Data Science experience capabilities and examples of how ML models can address your common business problems.Data Science - Price prediction with RIn this tutorial, you build a machine learning model to analyze and visualize the avocado prices in the US and predict future prices.SummaryMicrosoft Fabric revolutionizes data analytics and AI integration by providing organizations with a unified platform that simplifies the complex tasks involved in AI development. By consolidating data-related functionalities and integrating with Microsoft 365 applications, Fabric empowers users to harness the power of their data and make informed decisions. With its support for diverse workloads and integration with OneLake, Microsoft Fabric paves the way for organizations to unlock the full potential of data-driven insights and AI innovation. As the landscape of AI continues to evolve, Microsoft Fabric stands as a game-changing solution for organizations seeking to thrive in the era of data-driven decision-making.Author BioJulian Melanson is a full-time teacher and best-selling instructor dedicated to helping students realize their full potential. With the honor of teaching over 150,000 students from 130 countries across the globe, he has honed his teaching skills to become an expert in this field. He focuses on unlocking the potential of creativity and productivity with AI tools and filmmaking techniques learned over the years, creating countless content for clients from many industries.
Read more
  • 0
  • 0
  • 94
Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at $19.99/month. Cancel anytime
article-image-using-langchain-for-large-language-model-powered-applications
Avratanu Biswas
15 Jun 2023
5 min read
Save for later

Using LangChain for Large Language Model — Powered Applications

Avratanu Biswas
15 Jun 2023
5 min read
This article is the second part of a series of articles, please refer to Part 2 for learning how to Get to grips with LangChain framework and how to utilize it for building LLM-powered AppsIntroductionLangChain is a powerful and open-source Python library specifically designed to enhance the usability, accessibility, and versatility of Large Language Models (LLMs) such as GPT-3 (Generative Pre-trained Transformer 3), BERT(Bidirectional Encoder Representations from Transformers), BLOOM (BigScience Large Open-science Open-access Multilingual Language Model). It provides developers with a comprehensive set of tools to seamlessly combine multiple prompts, creating a harmonious orchestra for working with LLMs effortlessly. The project was initiated by Harrison Chase, with the first commit made in late October 2022. In just a few weeks, LangChain gained immense popularity within the open-source community. Image 1: The popularity of the LangChain Python libraryLangChain for LLMsTo fully grasp the fundamentals of LangChain and utilize it effectively — understanding the fundamentals of LLMs is essential. In simple terms, LLMs are sophisticated language models or AI systems that have been extensively trained on massive amounts of text data to comprehend and generate human-like language. Albeit their powerful capabilities, LLMs are generic in nature i.e. lacking domain-specific knowledge or expertise. For instance, when addressing queries in fields like medicine or law, while an LLM can provide general insights, it, however, may struggle to offer in-depth or nuanced responses that require specialized expertise. Alongside such limitations, LLMs are susceptible to biases and inaccuracies present in training data which can yield contextually plausible, yet incorrect outputs. This is where LangChain shines — serving as an open-source library that leverages the power of LLMs and mitigates their drawbacks by providing abstractions and a diverse range of modules, akin to Lego blocks, thus facilitating intuitive integration with other tools and knowledge bases.In brief, LangChain presents a useful approach for handling text data, wherein the initial step involves preprocessing of the large corpus by segmenting it into smaller chunks or summaries. These chunks are then transformed into vector representations, enabling efficient comparisons and retrieval of similar chunks when questions are posed. This approach of preprocessing, real-time data collection, and interaction with the LLM is not only applicable to the specific context but can also be effectively utilized in other scenarios like code and semantic search.Image 2 - Typical workflow of Langchain ( Image created by Author)A typical workflow of LangChain involves several steps that enable efficient interaction between the user, the preprocessed text corpus, and the LLM. Notably, the strengths of LangChain lie in its provision of an abstraction layer, streamlining the intricate process of composing and integrating these text components, thereby enhancing overall efficiency and effectiveness.Key Attributes offered by LangChainThe core concept behind LangChain is its ability to connect a “Chain of thoughts” around LLMs, as evident from its name. However, LangChain is not limited to just a few LLMs —  it provides a wide range of components that work together as building blocks for advanced use cases involving LLMs. Now, let’s delve into the various components that the LangChain library offers, making our work with LLMs easier and more efficient.Image 3:  LangChain features at a glance. (Image created by Author)Prompts and Prompt Templates: Prompts refer to the inputs or queries we send to LLMs. As we have experienced with ChatGPT, the quality of the response depends heavily on the prompt. LangChain provides several functionalities to simplify the construction and handling of prompts. A prompt template consists of multiple parts, including instructions, content, and queries.Models: While LangChain itself does not provide LLMs, it leverages various Language Models (such as GPT3 and BLOOM, discussed earlier), Chat Models (like get-3.5-turbo), and Text Embedding Models (offered by CohereAI, HuggingFace, OpenAI).Chains: Chains are an end-to-end wrapper around multiple individual components, playing a major role in LangChain. The two most common types of chains are LLM chains and vector index chains.Memory: By default, Chains in LangChain are stateless, treating each incoming query or input independently without retaining context (i.e., lacking memory). To overcome this limitation, LangChain assists in both short-term memory (using previous conversational messages or summarised messages) and long-term memory (managing the retrieval and updating of information between conversations).Indexes: Index modules provide various document loaders to connect with different data resources and utility functions to seamlessly integrate with external vector databases like Pinecone, ChromoDB, and Weaviate, enabling smooth handling of large arrays of vector embeddings. The types of vector indexes include Document Loaders, Text Splitters, Retriever, and Vectorstore.Agents: While the sequence of chains is often deterministic, in certain applications, the sequence of calls may not be deterministic, with the next step depending on the user input and previous responses. Agents utilize LLMs to determine the appropriate actions and their orders. Agents perform these tasks using a suite of tools.Limitations on LangChain usageAbstraction challenge for debugging: The comprehensive abstraction provided by LangChain poses challenges for debugging as it becomes difficult to comprehend the underlying processes.Higher token consumption due to prompt coupling: Coupling a chain of prompts when executing multiple chains for a specific task often leads to higher token consumption, making it less cost-effective. Increased latency and slower performance: The latency period experienced when using LangChain in applications with agents or tools is higher, resulting in slower performance.Overall, LangChain provides a broad spectrum of features and modules that greatly enhance our interaction with LLMs. In the subsequent sections, we will explore the practical usage of LangChain and demonstrate how to build simple demo web applications using its capabilities.Referenceshttps://docs.langchain.com/docs/https://github.com/hwchase17/langchain https://medium.com/databutton/getting-started-with-langchain-a-powerful-tool-for-working-with-large-language-models-286419ba0842https://medium.com/@avra42/how-to-build-a-personalized-pdf-chat-bot-with-conversational-memory-965280c160f8AuthorAvratanu Biswas, Ph.D. Student ( Biophysics ), Educator, and Content Creator, ( Data Science, ML & AI ).Twitter    YouTube    Medium     GitHub
Read more
  • 0
  • 0
  • 1379

article-image-the-little-known-benefits-of-creating-architecture-design-with-chatgpt
Sagar Lad
15 Jun 2023
5 min read
Save for later

The Little-Known Benefits of Creating Architecture Design with ChatGPT

Sagar Lad
15 Jun 2023
5 min read
Software architecture acts as a blueprint for the system, using abstraction to control the system's complexity and establish inter-component communication. In the ever-evolving landscape of software architecture, a groundbreaking innovation has emerged, reshaping the way developers design and optimize their systems. Enter ChatGPT, an advanced language model that has revolutionized the field with its remarkable capabilities. With its deep understanding of natural language, ChatGPT is unlocking new horizons in software architecture. From streamlining development processes to enhancing user interactions, this article delves into the transformative potential of ChatGPT, exploring how it is reshaping the very foundations of software architecture as we know it.In this piece, we'll examine the value of software architecture and how chatGPT may help us build it.  Architecture Design with ChatGPTThe entire design of the software, its elements, and its behavior are represented by the software system architect. In a nutshell, it is a visual representation of how software applications are made by connecting their many components. The following are examples of software architecture activities: Implementation Details: It could be architectural artifacts, source code, documentation, repository, etc.Implementation Design decisions: It includes options for technology (cloud or on-premises), architectural style (monolithic or distributed), storage (AWS S3, Azure Blob, ADLS Gen2, etc.), ingestion pattern (batch or real-time streaming pattern), and more.Infrastructure Considerations: Deployment Choices, Component Configurations, etc.Let’s understand in detail about the process of software architecture.Requirement Gathering: Any project should begin with functional and non-functional requirements since they will determine how to create the software architecture and how to prepare the finished product in accordance with the needs of the stakeholders.Create a Helicopter view of the solution: Using the mind map, provide a high-level overview of the system's constituent parts. It is a useful method for capturing your requirements as a diagram.Refine functional and non-functional requirements: Examine the non-functional needs in terms of performance, security, cost-effectiveness, etc. once you have thoroughly refined the functional requirements to comprehend the overall functioning of the program.Design each component in detail: Start with creating the platform's infrastructure and creating the application components while taking into account the functional and non-functional needs.Create a phase-wise approach for the implementation: Once the infrastructure and application implementation design considerations are clear, begin preparing deliverables for a phased rollout. It should include the state of architecture as it is today, architecture in transition, and architecture in the future. Make a visual representation of the application and infrastructure, taking into account networking, security, and interconnection issues.Below are the best practices that can be followed while designing the software architecture for any application:Design your application considering the best and worst-case scenarioDesign your application which should be able to scale up and scale downCreate loosely coupled architecture design for the smooth functioning of the system Create a multi-thread processing to speed up the processing for batch and real-time streaming implementationDesign your application with 7 layers of security implementationMake a choice to store your dataNow, Let’s use ChatGPT to create a software architecture for an application. Our goal is to create a data mesh architecture for the retail industry using the azure technology. The major requirement is also to define and capture data architecture requirements.Image 1 - Part 1, Data mesh responseImage 2 - Part 2, Data mesh responseImage 3- Part 3, Data mesh responseImage 4- Part 4, Data mesh response ChatGPT first offers suggestions for a group of Azure services to be used to implement the batch and real-time streaming patterns after receiving input from the user. The principles for implementing a data mesh architecture are then provided, including domain-driven data ownership, data-driven products, self-service data infrastructure, and data governance, including data discovery and monitoring.Let’s check with chatGPT on how the networking setup should be done for these Azure services:Image 5: Part 1, Networking responseImage 6: Part 2 Networking response Image 7: Part 3 Networking response  The configuration of a VNET, subnet, NSG rules, Azure firewall, VNET peering, VPN gateway, and the private link is advised by chatGPT. These Azure networking components can be used to manage the services' interconnection. Another major requirement to implement data mesh architecture is also to check how domain-specific data will be managed and operationalized for the data mesh architecture. Image 8: Part 1,  Domain-specific Data ManagementImage 9: Part 2,  Domain-specific Data ManagementImage 10: Part 3,  Domain-specific Data ManagementThe goal of chatGPT's proposals is to produce domain-specific cleansed data that end users can utilize directly to extract value from the data. Since these data domain stores are being built by domain experts, they are also in charge of managing, supporting, and operationalizing the data as needed.ConclusionIn this post, we looked in detail at the overall process of software architecture design as well as its sequential process. The best techniques for creating the software architecture for any application were also demonstrated. Later, we used chatGPT to develop a data mesh architecture implementation, complete with networking setup and operationalization, for a retail domain.Author BioSagar Lad is a Cloud Data Solution Architect with a leading organization and has deep expertise in designing and building Enterprise-grade Intelligent Azure Data and Analytics Solutions. He is a published author, content writer, Microsoft Certified Trainer, and C# Corner MVP.Link - Medium , Amazon , LinkedIn  
Read more
  • 0
  • 0
  • 169

article-image-babyagi-empowering-task-automation-through-advanced-ai-technologies
Rohan Chikorde
15 Jun 2023
8 min read
Save for later

BabyAGI: Empowering Task Automation through Advanced AI Technologies

Rohan Chikorde
15 Jun 2023
8 min read
In today's rapidly evolving technological landscape, the demand for efficient task automation has grown exponentially. Businesses and individuals alike are seeking innovative solutions to streamline their workflows, optimize resource allocation, and enhance productivity. In response to this demand, a groundbreaking autonomous AI agent called BabyAGI has emerged as a powerful tool for task management.BabyAGI stands out from traditional AI agents by leveraging cutting-edge technologies from OpenAI, Pinecone, LangChain, and Chroma. These technologies work in synergy to provide a comprehensive and versatile solution for automating tasks and achieving specific objectives.This comprehensive blog post aims to delve into the world of BabyAGI, exploring its unique features, functionalities, and potential applications. Additionally, it will provide a step-by-step guide on how to set up and run BabyAGI effectively, allowing users to harness its full potential for task automation. By the end of this blog post, you will have a deep understanding of BabyAGI and the tools required to utilize it successfully. Whether you're a project manager looking to optimize workflows, a content creator seeking innovative ideas, or an individual aiming to streamline personal tasks, BabyAGI can revolutionize your approach to task management.Understanding BabyAGIBabyAGI is an autonomous AI agent that brings together the power of various advanced technologies to revolutionize task automation. By leveraging the capabilities of OpenAI's GPT3.5 or GPT4 models, BabyAGI possesses a remarkable ability to generate creative ideas and insights. One of the distinguishing features of BabyAGI is its focus on brainstorming and ideation. Unlike traditional AI agents that rely on browsing external resources, BabyAGI draws upon its existing knowledge base, which is built using the vast amount of information available up until 2021. By avoiding interruptions caused by web searches, BabyAGI can maintain its train of thought and provide uninterrupted suggestions and solutions.The integration of Pinecone's vector database service is another key component of BabyAGI's capabilities. Pinecone enables BabyAGI to store and manage information in a unique way by converting it into vectors. These vectors capture the essential details of the data, making it easier for BabyAGI to understand and work with. LangChain, another technology incorporated into BabyAGI, enhances its integration potential. This means that BabyAGI can be seamlessly integrated into existing systems, allowing users to leverage its functionalities alongside other tools and resources.Chroma, the final technology in BabyAGI's arsenal, brings an innovative approach to the table. Chroma focuses on efficient task management, helping users prioritize and optimize their workflows. By automating repetitive and time-consuming tasks, BabyAGI frees up valuable resources and allows users to focus on more strategic and value-added activities. The combination of these advanced technologies in BabyAGI makes it a versatile and powerful tool for various industries and individuals. Project managers can leverage BabyAGI's brainstorming capabilities to generate new ideas and innovative approaches. Content creators can tap into BabyAGI's creativity to enhance their creative process and produce engaging content. Individuals can rely on BabyAGI to automate mundane tasks, freeing up time for more fulfilling activities.BabyAGI represents a significant leap forward in task automation. By combining the capabilities of OpenAI's models, Pinecone's vector database, LangChain's integration potential, and Chroma's efficiency, BabyAGI offers a unique and powerful solution for brainstorming, ideation, and task management. Its ability to generate creative ideas, prioritize tasks, and optimize workflows sets it apart as a revolutionary tool in the realm of AI-driven automation.How It WorksThe script operates through an endless loop, executing the following sequence:Retrieves the initial task from the list of tasks.Dispatches the task to the execution agent, which leverages OpenAI's API to accomplish the task within the given context.Enhances the obtained result and archives it in Chroma/Weaviate.Chroma is an open-source embedding database. Chroma makes it easy to build LLM apps by making knowledge, facts, and skills pluggable for LLMs. Weaviate is an open-source vector database. It allows you to store data objects and vector embeddings from your favorite ML models, and scale seamlessly into billions of data objects. Generates fresh tasks and reorganizes the task list based on the objective and the outcome of the preceding task.Image 1: Working, Pic Credits: https://github.com/yoheinakajima/babyagiThe function execution_agent() utilizes the OpenAI API, employing two parameters: the objective and the task. It sends a prompt to the OpenAI API, which in turn provides the task result. The prompt consists of a description of the AI system's task, the objective, and the task itself. The returned result is a string.In the function task_creation_agent(), OpenAI's API is employed to generate new tasks based on the objective and the result of the previous task. The function takes four parameters: the objective, the previous task's result, the task description, and the current task list. It sends a prompt to the OpenAI API, which response with a list of new tasks as strings. The function returns the new tasks as a list of dictionaries, where each dictionary contains the task name.The prioritization_agent() function utilizes the OpenAI API to rearrange the task list based on priority. It accepts the ID of the current task as a parameter. It sends a prompt to the OpenAI API, receiving the reprioritized task list as a numbered list.Lastly, the script utilizes Chroma/Weaviate to store and retrieve task results for context. It creates a Chroma/Weaviate collection using the specified table name in the TABLE_NAME variable. The script employs Chroma/Weaviate to store task results in the collection, including the task name and any additional metadata.Setting Up BabyAGITo unleash the power of BabyAGI, the first step is to ensure that Python and Git are installed on your system. Python serves as the programming language for BabyAGI, while Git enables easy access to the necessary files and updates. If you don't have Python and Git installed, you can obtain them from their respective sources. For Python, head over to python.org and download the latest version compatible with your operating system. Follow the installation instructions provided by the Python installer to set it up on your machine. It is recommended to choose the option to add Python to your system's PATH during installation for easier accessibility.For Windows users, Git can be obtained by visiting the official Git website. Download the appropriate installer for your system and execute it. The installer will guide you through the installation process, allowing you to choose the desired options. Select the option to add Git to your system's PATH for convenient usage. Once you have Python and Git installed, the next crucial step is to acquire an OpenAI API Key. This key grants you access to OpenAI's powerful GPT3.5 or GPT4 models, which are essential for BabyAGI's operation. To obtain an API Key, you need a paid OpenAI account.Visit the OpenAI website and log in to your account. Navigate to the API section and follow the instructions to obtain your API Key. It is crucial to keep this key secure as it provides access to powerful AI models and should not be shared with unauthorized individuals.  Image 2: OpenAI API KeyWith Python, Git, and the OpenAI API Key in place, you are now ready to proceed with setting up BabyAGI. The next step involves downloading the BabyAGI source code from its GitHub repository. Visit the GitHub page and locate the download option.Clone the repository via git clone https://github.com/yoheinakajima/babyagi.git and cd into the cloned repository. Install the required packages: pip install -r requirements.txtCopy the .env.example file to .env: cp .env.example .env. This is where you will set the following variables.Set your OpenAI API key in the OPENAI_API_KEY and OPENAPI_API_MODEL variables. In order to use with Weaviate you will also need to set up additional variables detailed here.             Set the name of the table where the task results will be stored in the TABLE_NAME variable.(Optional) Set the name of the BabyAGI instance in the BABY_NAME variable.(Optional) Set the objective of the task management system in the OBJECTIVE variable.(Optional) Set the first task of the system in the INITIAL_TASK variable.Run the script: python babyagi.pyNote: The intention behind this script is to run it continuously as an integral component of a task management system. It is crucial to exercise responsible usage due to the potential for high API utilization when running the script continuously.ConclusionBabyAGI is a revolutionary AI agent that brings together the strengths of OpenAI, LangChain, and Chroma to deliver a powerful tool for task automation. With its ability to generate creative ideas, optimize workflows, and enhance decision-making, BabyAGI is transforming the way professionals approach task management. By automating repetitive tasks and providing valuable insights, it empowers project managers, content creators, and decision-makers to achieve better outcomes and maximize productivity. As technology continues to evolve, BabyAGI stands at the forefront of innovation, paving the way for more efficient and intelligent task management in a wide range of industries.Author BioRohan is an accomplished AI Architect professional with a post-graduate in Machine Learning and Artificial Intelligence. With almost a decade of experience, he has successfully developed deep learning and machine learning models for various business applications. Rohan's expertise spans multiple domains, and he excels in programming languages such as R and Python, as well as analytics techniques like regression analysis and data mining. In addition to his technical prowess, he is an effective communicator, mentor, and team leader. Rohan's passion lies in machine learning, deep learning, and computer vision.LinkedIn
Read more
  • 0
  • 0
  • 287

article-image-implementing-azure-ad-protection-with-chatgpt
Steve Miles
15 Jun 2023
8 min read
Save for later

Implementing Azure AD Protection with ChatGPT

Steve Miles
15 Jun 2023
8 min read
IntroductionCybersecurity professionals face numerous challenges daily, from threat detection to incident response. The advent of AI-powered language models, also called Generative AI such as ChatGPT or Google's Bard, has revolutionized how experts approach their tasks. In this tutorial, we will explore how ChatGPT can assist cybersecurity professionals in performing various tasks efficiently and effectively. From analyzing logs and conducting risk assessments to developing incident response strategies, ChatGPT's capabilities can be harnessed to streamline workflows and enhance productivity. In this blog, let's dive into the practical applications and benefits of integrating Generative AI into (cyber)security operations.In this article, we will cover a tutorial on implementing Azure AD Protection with ChatGPT and also cover certain other areas of cybersecurity where GPT can be beneficial.Implementing Azure AD Identity Protection with ChatGPTAzure AD Identity Protection helps organizations safeguard their Azure Active Directory (Azure AD) identities by detecting and mitigating identity-related risks. In this section, we will explore how ChatGPT can assist in implementing Azure AD Identity Protection through code examples using Python and the Microsoft Graph API.1. Set up the EnvironmentBefore we begin, ensure that you have the following prerequisites in place:Python is installed on your machine.The requests library is installed. You can install it using the following command: pip install requests Azure AD application registered with the appropriate permissions to access Azure AD Identity Protection.2. Acquire Access TokenTo interact with the Microsoft Graph API, we must acquire an access token. Use the following Python code to obtain the access token:```python import requests # Azure AD application details tenant_id = 'YOUR_TENANT_ID' client_id = 'YOUR_CLIENT_ID' client_secret = 'YOUR_CLIENT_SECRET' # Microsoft Graph token endpoint token_url = f'https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token' # Request access token payload = {    'grant_type': 'client_credentials',    'client_id': client_id,    'client_secret': client_secret,    'scope': 'https://graph.microsoft.com/.default' } response = requests.post(token_url, data=payload) if response.status_code == 200:    access_token = response.json()['access_token'] else:    print('Error: Failed to obtain access token') ```Make sure to replace the placeholders with your Azure AD application details.3. Query Azure AD Identity Protection Data with ChatGPTNow that we have the access token, we can leverage ChatGPT to query Azure AD Identity Protection data. Use the following code example to interact with the model and retrieve identity protection insights:```python import openai openai.api_key = 'YOUR_OPENAI_API_KEY' def query_model(question):    response = openai.Completion.create(        engine='text-davinci-003',        prompt=question,        max_tokens=100,        temperature=0.5,        n=1,        stop=None,        temperature=0.5,    )    if response.choices:        return response.choices[0].text.strip()    else:        return None # Example question for querying Azure AD Identity Protection data question = "What are the recent risky sign-ins detected by Azure AD Identity Protection?" # Microsoft Graph API endpoint for risky sign-ins graph_api_url = 'https://graph.microsoft.com/v1.0/identityProtection/riskyUsers' # Send API request with the access token headers = {    'Authorization': f'Bearer {access_token}',    'Content-Type': 'application/json' } response = requests.get(graph_api_url, headers=headers) if response.status_code == 200:    risky_sign_ins = response.json()    # Process the response as needed    # ...    # Query the AI model for insights or recommendations    insights = query_model(question)    if insights:        print("Identity Protection Insights:")        print(insights)    else:        print("Error: Failed to obtain insights from the AI model") else:    print("Error: Failed to retrieve risky sign-ins data from Azure AD Identity Protection") ```Ensure you have appropriate permissions and update the `graph_api_url` with the relevant endpoint for the Azure AD Identity Protection data you want to retrieve.4. Interpret and Utilize InsightsOnce you obtain insights from the AI model, interpret, and utilize them to improve your identity protection practices. This could involve taking proactive measures to mitigate risks, investigating suspicious activities, or implementing additional security measures based on the recommendations provided.Remember to adapt the code examples based on your specific requirements and refer to the Microsoft Graph API documentation for available endpoints and data structures. https://learn.microsoft.com/en-us/graph/Other application areas1. Analyzing Log FilesOne of the most important aspects of cybersecurity is analyzing log files for suspicious activity and potential security breaches. Chat can help businesses automate this process. By importing log files into the model, ChatGPT can quickly identify patterns, anomalies, and potentially malicious activities. This analysis allows cybersecurity professionals to focus on the most important issues, saving valuable time and effort. In addition, ChatGPT's ability to create human-readable summaries of log data simplifies the interpretation and communication of findings for stakeholders.2. Conducting Risk AssessmentsConducting a comprehensive risk assessment is essential to understanding an organization's security posture. ChatGPT can help in this process by using its powerful capabilities to provide context and insights. By interacting with the model, organizations can ask specific questions about potential vulnerabilities, attacks, or best practices related to their risk assessments. ChatGPT's feedback provides knowledge of the organization's security environment and offers real value actionable insights that help businesses identify and prioritize risks and remediation tasks.3. Developing Incident Response StrategiesTime is of the essence in a cybersecurity incident. Generative AI can be an invaluable tool for developing effective incident response mechanisms. By leveraging its natural language processing capabilities, businesses can use ChatGPT to brainstorm and optimize response processes. The model can provide recommendations based on historical data, industry standards, and best practices, helping to create robust and efficient incident response systems. Generative AI can understand and generate human-like responses, making it an ideal virtual security analyst for cybersecurity professionals in high-pressure and time-sensitive situations.4. Automating Routine TasksCybersecurity professionals are often faced with increasing volume and velocity of repetitive and time-consuming tasks, such as vulnerability assessments, log analysis, and updating firewall rules. Generative AI can help automate these routine tasks, freeing experts to focus on complex real-value organizational security challenges. By integrating ChatGPT with existing automation frameworks, organizations can create chatbot-like interfaces that interact with the model to perform pre-defined actions. This approach increases productivity and reduces the risk of human error associated with manual processing.5. Enhancing Threat Intelligence AnalysisEffective threat reporting is essential for proactive cybersecurity defenses. Generative AI can enhance threat intelligence data analysis by extracting insights from a vast repository of security information. By asking about emerging threats, known vulnerabilities, or attack techniques, administrators can gain a deeper understanding of the ongoing threat landscape. ChatGPT's ability to understand complex security issues enhances the accuracy and relevance of threat intelligence reports, contributing to timely decision-making.ConclusionIn conclusion, it is easier and more efficient to implement Azure AD in conjunction with ChatGPT. As the cybersecurity landscape continues to evolve, businesses must embrace AI-powered solutions to stay ahead of malicious actors. Generative AI provides valuable support for various cybersecurity tasks, including log analysis, risk assessment, incident response planning, workflow automation, and threat intelligence analysis capabilities, enabling cybersecurity professionals to streamline their workflow, increase productivity, and make more informed decisions. While it is important to exercise proper judgment and credentials when implementing AI models, integrating Generative AI  such as ChatGPT into the cybersecurity industry offers significant opportunities for businesses to manage their tasks faster, more accurately, and more efficiently.Author BioSteve Miles (SMiles) is the CTO responsible for the tools and technologies selection for the cloud practice of a multi-billion turnover IT distributor based in the UK and Ireland. He is also a multi-cloud and hybrid technology strategist with 20+ years of telco, co-location, hosted data center, hybrid, and multi-cloud infrastructure experience. Steve is an Alibaba Cloud MVP (Most Valuable Professional), as well as being a Microsoft Azure MVP (Most Valuable Professional), and MCT (Microsoft Certified Trainer). Published freelance author for Microsoft technologies and certification guides, as well as an editorial and technical reviewer. Amongst many hybrid/cloud-based certifications, he is Alibaba Cloud Certified, with 20+ Cloud/Hybrid based Microsoft certifications with 14 of those being in Azure.His roles have included network security architect, global solutions architect, public cloud security solutions architect, and Azure practice technical lead. He currently works for a leading multi-cloud distributor based in the UK and Dublin in a cloud and hybrid technology leadership role.His first Microsoft certification was on Windows NT. He is an MCP, MCITP, MCSA, and MCSE for Windows Server and many other Microsoft products. He also holds multiple Microsoft Fundamentals, Associate, Expert, and Specialty certifications in Azure Security, Identity, Network, M365, and D365. He also holds multiple security and networking vendor certifications, as well as PRINCE2 and ITIL, and is associated with industry bodies such as the CIF, ISCA, and IISP.Author of the book: Azure Security Cookbook 
Read more
  • 0
  • 0
  • 181
article-image-build-an-irreverent-news-feed-in-python-and-bard-api
Darren Broemmer
14 Jun 2023
8 min read
Save for later

Build an Irreverent News Feed in Python and Bard API

Darren Broemmer
14 Jun 2023
8 min read
Now that we can invoke Bard from our code using this article, let’s build a news feed application that incorporates Generate AI capability. Not only will it grab the top headlines and stories, but it will also use the Bard API to transform them in a comical way. Note that the Bard API is an unofficial, cutting-edge technology in a rapidly changing area and is not production ready at the time of writing. The first step is to get the list of news stories. First, let’s use the Bard API to do this.As seen above, requests to Google Bard yield a natural language response, just like the web interface does. Thus, depending on your use case, you may need to specify a more formal output format so that your program can consume the data.Specify the output format in your prompt.Our news application could use the prompt, What are the top five news stories today?This will give us a text response with a numbered or bulleted list of stories. Unless we have a text-only user interface, our application will need to parse this out into individual stories for display.Thus, to get a computer-readable set of news stories, use a prompt in the form below. prompt = '''What are the top five news stories today?Structure the output as a list of xml objects each called story.Each story element should have child elements called title, content, and url.''' Here is an example of what this prompt returned. Sure, here are the top five news stories today, structured as a list of XML objects with the attributes title, content, and URL:```xml <stories> <story>    <title>US House Votes to Suspend Debt Ceiling and Avoid Default</title>    <content>The US House of Representatives voted on Thursday to suspend the debt ceiling and avoid a default on the country's debt. The vote was 221-212, with all Democrats and 11 Republicans voting in favor. The Senate is expected to vote on the measure later this week.</content> <url>https://www.cnn.com/2023/06/01/politics/us-debt-ceiling-vote/index.html</url> </story> … </stories> ```Note the pre-canned introduction at the beginning of the response. Multiple attempts to instruct Bard to omit this and only return the XML data were unsuccessful. However, Bard used a markdown format so extracting the substring from the response is fairly easy. Here is the code we used that leverages the prompt shown earlier.def get_bard_headlines():   answer = call_bard(prompt)   # We need to filter out the precanned response and get just the xml   # Bard's response beings with something like:   #   # Sure, here are the top five news stories today, structured as a   # list of XML objects with the attributes title, content, and url:   # ```xml   # <news>   # ...   # </news>   # ```   # Get just the json text from the response   delimeter = "```xml"   idx1 = answer.index(delimeter)   idx2 = answer.index("```", idx1 + 6)   # length of substring 1 is added to   # get string from next character   xml_data = answer[idx1 + len(delimeter) + 1: idx2]   article_list = []   # Parse the XML data   root = ET.fromstring(xml_data)   # Iterate over each 'item' element   for item in root.iter('story'):       title = item.find('title').text       content = item.find('content').text       url = item.find('url').text       article_dict = {'title': title, 'content': content, 'url': url}       article_list.append(article_dict)   return article_list  Why use an XML format and not JSON? In our testing with Bard, it did not always create correctly formatted JSON for this use case. It had trouble when the content included single or double quotation marks. See the example below where it incorrectly wrapped text outside of the quotes, resulting in an invalid JSON that caused an exception during parsing. For this news use case, XML provided reliable results that our application code could easily parse. For other use cases, JSON may work just fine. Be sure to perform testing on different data sets to see what is best for your requirements. Even if you are not familiar with parsing XML using Python, you can ask Bard to write the code for you:At this point, we have the basic news stories, but we want to transform them in a comic way. We can either combine the two steps into a single prompt, or we can use a second step to convert the headlines.One thing to keep in mind is that calls to the Bard API are often slower than typical services. If you use the output from Bard in a high-volume scenario, it may be advantageous to use a background process to get content from Bard and cache that for your web application.Another option to get fast, reliable headlines is to use the GNews API. It allows up to 100 free queries per day. Create an account to get your API token. The documentation on the site is very good, or you can ask Bard to write the code to call the API. It has a top headlines endpoint with several categories to choose from (world, business, technology, etc.), or you can perform a query to retrieve headlines using arbitrary keyword(s). Here is the code to get the top headlines.def get_gnews_headlines(category):   url = f"https://gnews.io/api/v4/top-headlines?category={category}&lang=en&country=us&max=10&apikey={gnews_api_key}"   with urllib.request.urlopen(url) as response:       data = json.loads(response.read().decode("utf-8"))       articles = data["articles"]       return articlesUse Bard to create a web interfaceBottle is a lightweight web server framework for Python. It is quick and easy to create web applications. We use the following prompt to have Bard write code for a news feed web page built using the Bottle framework.  Here is a snapshot of the resulting page. It can use some CSS styling, but not bad for a start. The links take you to the underlying news source and the full article. Use Bard to transform headlinesWith the basic news structure in place, Bard can be used for the creative part of transforming the headlines. The prompt and Python functions to do this are shown below. Bard sometimes returns multiple lines of output, so this function only returns the first line of actual output. reword_prompt = '''Rewrite the following news headline to have a comic twist to it. Use the comic style of Jerry Seinfeld. If the story is about really bad news, then do not attempt to rewrite it and simply echo back the headline. ''' def bard_reword_headline(headline):   answer = call_bard(reword_prompt + headline)   # Split response into lines   lines = answer.split('\n')   # Ignore the first line which is Bard’s canned response   lines = lines[1:]   for line in lines:       if len(line) > 0:           return line.strip("\"")   return "No headlines available" We then incorporate this into our web server code:import bottle import requests from gnews import get_gnews_headlines from bard import bard_reword_headline # Define the Bottle application. app = bottle.Bottle() # Define the route to display the news stories. @app.route("/") def index():   # Get the news articles from the gnews.io API.   # Category choices are: general, world, nation, business, technology, entertainment,   # sports, science, and health   articles = get_gnews_headlines("technology")   # Reword each headline   for article in articles:       reworded_headline = bard_reword_headline(article['title'])       article['comic_title'] = reworded_headline   # Render the template with the news stories.   return bottle.template("news_template.html", articles=articles) # Run the Bottle application. if __name__ == "__main__":   app.run(host="0.0.0.0", port=8080) Here is the result. I think Bard did a pretty good job. SummaryIn conclusion, building an irreverent news feed using Python and the Bard API is a practical and engaging project. By harnessing the power of Python, developers can extract relevant news data and employ creative techniques to inject humor and satire into the feed. The Bard API provides a vast collection of literary quotes that can be seamlessly integrated into the news content, adding a unique and entertaining touch. This project not only demonstrates the versatility of Python but also showcases the potential for innovative and humorous news delivery in the digital age.Author BioDarren Broemmer is an author and software engineer with extensive experience in Big Tech and Fortune 500. He writes on topics at the intersection of technology, science, and innovation.LinkedIn  
Read more
  • 0
  • 0
  • 139

article-image-how-to-integrate-the-bard-api-into-your-python-applications
Darren Broemmer
14 Jun 2023
5 min read
Save for later

How to integrate the Bard API into your Python applications

Darren Broemmer
14 Jun 2023
5 min read
You can leverage the power of Google Bard from within applications using the Bard-API Python package. This package provides a user-friendly programmatic interface to interact with Google Bard. You can use this package to seamlessly add generative AI capability to your Python applications. Text summarization, question-answering, and language translation are simplified.  Because Bard is Internet-aware, the API can answer queries that other AI solutions cannot answer out of the box.It is important to note that this package describes itself as an “unofficial Python package that returns (the) response of Google Bard through (a) cookie value.” Specifically, it requires you to obtain a cookie from your browser assigned to your account. You then provide this to the library, and it acts as an “api key.” You should treat it with the same level of security and confidentiality as you would with any other API key tied to one of your accounts. Note that the Bard API is a cutting-edge technology in a rapidly changing area and is not production ready at the time of writing. Using this cookie value, the Bard-API package emulates calling Bard as if you were working with the web interface in a browser. By comparison, the Bard API does not have as much flexibility as the ChatGPT API. For example, there is no equivalent temperature parameter that controls the creativity level of the output. The Bard API signature is prompt-centric, so any instructions you want to give to the API need to be included as part of your prompt.On the plus side, the interface is simple and easy to use. The main function is simply defined as shown below. The dictionary returned includes a content element, as well as other helpful information about the output.def get_answer(self, input_text: str) -> dict:Setup your environment for the Bard APIFirst, install the Bard-API package using the following command. pip install bardapiYou then need to obtain your account’s __Secure-1PSID cookie value. From the GitHub project that reverse-engineered the Bard API, you can get the cookie value as follows.Go to https://bard.google.com/F12 for consoleCopy the valuesSession: Go to Application → Cookies → __Secure-1PSID. Copy the value of that cookie.As with any API key, avoid putting it directly into your code. Create a .env file and add a line for the value. Note that the key name _BARD_API_KEY is the exact name required by the Python library. _BARD_API_KEY=your_cookie_value.To use this within your code, install the python-dotenv library. pip install python-dotenvThe following code in our bard.py file uses the Bard-API Python library to invoke the API. It reads the cookie value from the environment file in order to successfully authenticate.from bardapi import Bard from dotenv import load_dotenv load_dotenv() def call_bard(query):   bard = Bard()   answer = bard.get_answer(query)   return (answer['content']) Invoke the Bard API from your Python codeThe function above can be used from within your Python code. Create a new file in Python to perform a simple test and verify that your API client is working correctly. The details of the API output can also be inspected. Note, however, that the call_bard code only returns the content element. In most use cases, this is likely all you need to be concerned with. from bard import call_bard response = call_bard("What movie would you recommend?") print(response) Running this code returned the following output. Note that only the initial portion of the response is shown below for brevity. Our BARD API client code is working.I need more information like what kind of movies do you like, what are your interests, etc. Here are a few recommendations to get you started: * **The Godfather (1972)** is a classic gangster film that tells the story of the Corleone family. It is considered one of the greatest films of all time.[Image of The Godfather (1972) movie poster]* **The Shawshank Redemption (1994)** is a drama about a man who is wrongly convicted of murder and sent to prison. It is a heartwarming story about hope and redemption.[Image of The Shawshank Redemption (1994) movie poster]* **The Dark Knight (2008)** is a superhero film that tells the story of Batman's battle against the Joker. It is a dark and gritty film that is considered one of the best superhero films ever made.[Image of The Dark Knight (2008) movie poster]…For some use cases, you may be interested to see what other response options Bard generated. In the dictionary returned from the Bard API, there is also a choices element, which is a list of other candidate responses Bard generated. On the Bard web page, you can choose to view these alternative responses. In your application, you may or may not want to leverage these other options based on your use case and requirements.Interestingly, Bard also returns an equivalent query it uses to generate a response. In our movie example above, the output dictionary contains the following element. textQuery': ['what is the most critically acclaimed movie?', 1]If you look through the other choices it generated, others take a different approach. Another response choice starts by recommending comedies instead of critically acclaimed movies. {'id': 'rc_e531de0d5173e11b', 'content': ["I need more information on what kind of movie you are looking for. Here are a few options to get you started:\n\n* If you are in the mood for a comedy, I recommend *21 Jump Street* (2012). It's a hilarious and action-packed film about two young cops who go undercover as high school students to bust a drug ring.\n[Image of 21 Jump Street (2012) movie poster]... SummaryIn summary, integrating the Bard API into Python applications is a practical and straightforward process. By leveraging the API's rich collection of literary quotes, developers can enhance their applications with a touch of elegance and creativity. Through simple API calls and data manipulation, Python programmers can seamlessly integrate Bard's vast repository of quotes into their projects, enriching the user experience and adding a sophisticated literary flair. By following the practical steps outlined in this article, developers can easily unlock the power of the Bard API and bring the magic of literature into their Python applications.Author BioDarren Broemmer is an author and software engineer with extensive experience in Big Tech and Fortune 500. He writes on topics at the intersection of technology, science, and innovation. LinkedIn 
Read more
  • 0
  • 0
  • 758

article-image-animating-adobe-firefly-content-with-adobe-animate
Joseph Labrecque
14 Jun 2023
10 min read
Save for later

Animating Adobe Firefly Content with Adobe Animate

Joseph Labrecque
14 Jun 2023
10 min read
You can download the image source files for this article from hereAn Introduction to Adobe FireflyEarlier this year, Adobe unveiled its set of generative AI tools via https://firefly.adobe.com/. These services are similar to other generative image AIs such as Midjourney or Dalle-2 and are exposed through a web-based interface with a well-thought-out UI. Eventually, Adobe plans to integrate these procedures into existing software such as Photoshop, Premiere Pro, Express, and more.Originally as a waitlist that one would need to sign up for… Firefly is now open to anyone for use with an Adobe ID.Image 1: Adobe Firely  Firefly is the new family of creative generative AI models coming to Adobe products, focusing initially on image and text effect generation. Firefly will offer new ways to ideate, create, and communicate while significantly improving creative workflows. Firefly is the natural extension of the technology Adobe has produced over the past 40 years, driven by the belief that people should be empowered to bring their ideas into the world precisely as they imagine them. -- AdobeA few of the things that make Adobe Firefly different from similar generative AI services are the immediate approach to moving beyond prompt-based image generation to procedures such as prompt-driven text effects and vector recolorization… the fact that the Firefly model is based upon Adobe Stock content instead of general web content… and Adobe’s commitment to the Content Authenticity Initiative.As of early June 2023, the following procedures are available through Adobe Firefly: Text to Image: Generate images from a detailed text description.Generative Fill: Use a brush to remove objects, or paint in new ones from text descriptions.Text Effects: Apply styles or textures to text with a text prompt.Generative Recolor: Generate color variations of your vector artwork from a detailed text description.In addition to this, the public Adobe Photoshop beta also has deep integration with Firefly through the generative fill and other procedures exposed through time-tested Photoshop workflows.Generating Images with Text PromptsLet’s have a look at how the prompt-based image generation in Adobe Firefly works. From the Firefly start page, choose the option to generate content using Text to Image and type in the following prompt:cute black kitten mask with glowing green eyes on a neutral pastel backgroundOn the image generation screen, select None as the content type. You should see similar results as the screenshot pictures below.Image 2: Cute black kitten with green eyesFirefly generates a set of four variations based on the given text prompt. You can direct the AI to adjust certain aspects of the images that are generated by tweaking the prompt, specifying certain styles via the user interface, and making choices around aspect ratio and other aspects.Using Generative FillWe can enter the generative fill interface directly following the creation of our image assets by hovering over the chosen variant and clicking the Generative Fill option.Image 3: Generative fill outputThe generative fill UI contains tools for inserting and removing content from an existing image with the direction of text prompts as well. In the example below, we are brushing over the kitten’s forehead and specifying that we would like the AI to generate a crown in that place via a text prompt:Image 4: Generating a crown using a text promptClicking the Generate button will create a set of variants - similar to when we first created the image. At this point, we can choose the variant we like best and click the Download button to download the image to our local machine for further manipulation.Image 5: Image generated with a crown addedSee the file Firefly Inpaint 20230531190125.png to view the resultant image generated by Firefly with the crown added. You can download the files from here.Preparing for Animation with PhotoshopBefore bringing the generated kitten image into Animate, we’ll want to optionally remove the background using Photoshop. With the new contextual toolbar – Adobe makes this very simple. Simply open the generated image file in Photoshop and with the single available layer selected, choose Remove Background from the contextual toolbar that appears beneath the image.Image 6: Removing background in PhotoshopThe background is removed via a layer mask that you can then use to refine the portions of your image that have been hidden through the normal procedure of brushing black or white across the mask to hide or reveal content.See the file Kitten.png to view the image with the background removed by Photoshop.To export your image without the background, choose File… Export… Export As… from the application menu - and select to export a transparent .png file to a location of your local machine that you’ll remember.Animate Document SetupWe’ve prepared a new Animate document using the resulting .png file as a base. The stage measures 1024x1024 and has been given an appropriate background color. The FPS (frames per second) value is set to 30 – making every 30 frames in the timeline defines 1 second of motion. The kitten image has been added to the single layer in this document and is present on the stage:See the file KittenStarter.fla from here to if you’d like to follow along in the next section.Producing Motion from Generative Images with Adobe AnimateWhile Adobe Animate does not have any direct interaction with Firefly procedures yet – it has exhibited Adobe Sensei capabilities for a number of years now through automated lip-sync workflows that make use of the Sensei AI to match visemes with language sounds (phonemes) across the timeline for automated frame assignments. Since we are dealing with a kitten image and not a speaking character – we will not be using this technology for this article. 1. Instead, we’ll be using another new animation workflow available in Animate through the Asset Warp tool and the creation of Warped Objects. Select the Asset Warp tool from the toolbar. This tool allows us to transform images into Warped Objects and to place and manipulate pins to create a warp mesh.2. In the Properties panel, ensure in the Tool Properties tab that Creates Bones is toggled off within the Warp Options section. This will ensure we create pins and not bones as would be needed for a full rig.Image 7: Properties Panel 3. Using the Asset Warp tool, click the tip of the kitten’s right ear to establish a pin and transform the image to a Warped Object. An overlay mesh is displayed across the object – indicating the form and complexity of the newly created warped object.Image 8: Warped Object4. Add additional pins across the image to establish a set of control pins. I recommend moving clockwise around the kitten’s face and have placed a total of 8 pins in locations where I may want to control the mesh.Image 8: Kitten face clock-wise 5. Now, look at the timeline and note that we currently have a single keyframe at frame 1. It is good practice to establish your Warped Object and its associated pins first, before creating additional keyframes… but changes can be propagated across frames if necessary. Select frame 30 and insert a new keyframe from the menu above the timeline to duplicate the keyframe at frame 1. You’ll then have 2 identical keyframes in the timeline with a span of frames between them.6. Add a third keyframe at frame 15. This is the frame in which we will manipulate the Warped Object. The keyframes at frames 1 and 30 will remain as they are.7. Using the Asset Warp toll once again, click and drag the various pins at frame 15 to distort the mesh and change the underlying image in subtle ways. I pull the ears closer together and move the chin down and adjust the crown and cheeks very slightly. 8. We’ll now establish animation between these three keyframes with a Classic Tween. In the timeline, select a series of frames across both frames spans so they are highlighted in blue. From the men above the timeline, choose to Create classic tween.9. The frame spans take on a violet color which indicates a set of Classic Tweens have been established. The arrows across each tween indicate there are no technical errors. Scrub the blue playhead across the timeline to view the animation you’ve created from our Firefly content. Your Adobe Firefly content is now fully animated!Refining Warped Object MotionIf desired, you can refine the motion by inserting easing effects such as a Cubic Ease In Out across your tweens by selecting the frames of a tween and looking at the Frame tab in the Properties panel. In the Tweening section, simply click the Effect button to view your easing presets and double-click the one you wish to apply.See the file KittenComplete.fla to view the finished animation.Sharing Your WorkIt’s easy to share your animated Firefly creation through the menu at the upper right of the screen in Animate. Simply click the Quick Share and publish icon to begin.Choose the Publish option… and then Animated GIF (.gif) – and click the Publish button to generate the file.You will be able to locate the published .gif file in the same folder as your .fla document.See the file Kitten.gif to view the generated animated GIF.Author BioJoseph is a Teaching Assistant Professor, Instructor of Technology, University of Colorado Boulder / Adobe Education Leader / Partner by DesignJoseph Labrecque is a creative developer, designer, and educator with nearly two decades of experience creating expressive web, desktop, and mobile solutions. He joined the University of Colorado Boulder College of Media, Communication, and Information as faculty with the Department of Advertising, Public Relations, and Media Design in Autumn 2019. His teaching focuses on creative software, digital workflows, user interaction, and design principles and concepts. Before joining the faculty at CU Boulder, he was associated with the University of Denver as adjunct faculty and as a senior interactive software engineer, user interface developer, and digital media designer.Labrecque has authored a number of books and video course publications on design and development technologies, tools, and concepts through publishers which include LinkedIn Learning (Lynda.com), Peachpit Press, and Adobe. He has spoken at large design and technology conferences such as Adobe MAX and for a variety of smaller creative communities. He is also the founder of Fractured Vision Media, LLC; a digital media production studio and distribution vehicle for a variety of creative works.Joseph is an Adobe Education Leader and member of Adobe Partners by Design. He holds a bachelor’s degree in communication from Worcester State University and a master’s degree in digital media studies from the University of Denver.Author of the book: Mastering Adobe Animate 2023
Read more
  • 0
  • 0
  • 877
article-image-adding-a-chatbot-to-your-portfolio-website-with-chatgpt
Maaike van Putten
13 Jun 2023
10 min read
Save for later

Adding a Chatbot to your Portfolio Website with ChatGPT

Maaike van Putten
13 Jun 2023
10 min read
This article is the second part of a series of articles, please refer to Part 1 for learning how to create a simple portfolio website using ChatGPT in a few stepsIn my last blog, we created a basic personal portfolio app for Olivia with ChatGPT. We’ll use this as the starting point for our next adventure. We’re going to be adding a simple chatbot to our website and configuring it to deal with certain questions. Of course, we could do this ourselves, but let’s see how we can utilize ChatGPT to accomplish this task faster. We’re going to do so with just four prompts! Let’s start with the end result, so you know what we’re working towards:Image 1: End result of the project In the right bottom corner, you see a pop-up that says Ask me anything. Well, you can’t ask it anything, but it can answer the following common questions:Where can I contact you?Can I contact you through Twitter?Can I contact you through LinkedIn?Where can I see your projects? Of course, we can elaborate and do even more with it. We actually wanted to use a free API for this, and we were stuck with CDN options due to the nature of our project. Luckily, we have a digital friend who has some options for us. Let’s see how this started.Deciding which service to use (with ChatGPT)It’s best to be quite descriptive when prompting. This is the first prompt that was used to start implementing the chatbot:I have an existing portfolio site, using HTML/CSS/JS. I'm not using any package managers, so any requirements will have to use a CDN. I want to add a chatbot to my site using a Natural Language AI. If it is possible I'd want the API I'll use to be free. Can you give me some options as to how I can achieve this? ChatGPT had some ideas: Certainly! There are several options available for adding a chatbot with Natural Language AI to your existing portfolio site using HTML/CSS/JS and integrating it through a CDN. Here are a few options that offer free plans: 1. IBM Watson Assistant: IBM Watson Assistant is a powerful NLP service that allows you to build chat bots. You can integrate it into your website using the Watson Assistant API. IBM offers a free tier that provides a limited number of API requests per month. You can find more information and documentation on the IBM Watson Assistant website. 2. Dialogflow (formerly API.AI): Dialogflow, now part of Google Cloud, offers a free tier that allows you to create conversational agents and integrate them into your website. Dialogflow provides a JavaScript library that you can use to communicate with the API. You can find documentation and examples on the Dialogflow website. 3. Wit.ai: Wit.ai, which is also owned by Facebook, provides a free NLP service for building chatbots. You can integrate it into your website using the Wit.ai API. Wit.ai offers a JavaScript SDK that you can use to interact with the API. You can find more information on the Wit.ai website. 4. Microsoft Azure Bot Service: Microsoft Azure Bot Service offers a free tier that allows you to create and deploy chatbots. You can use the Bot Service REST API to communicate with your bot from your website. Microsoft provides documentation and examples on its Azure Bot Service website. Remember to review the terms and limitations of the free plans for each service to ensure they meet your requirements. Additionally, be aware that some services may have usage limitations or require you to upgrade to a paid plan for higher usage levels or advanced features. Choose the option that best suits your needs, and refer to the respective documentation for implementation details specific to each service. After this, it was research time. This actually took a little while. IBM wasn’t properly explored, because the sign-up failed due to the Dutch valid phone number not passing validation. Azure seemed great, but a bit too advanced for what we needed right now. The chatbot service chosen was Wit.ai. On there we can sign up, get an access token and specify how to deal with certain inputs. After figuring that out and making a little code start ourselves. It was time to start adjusting the code with ChatGPT. Prompting for codeEnter the following prompt, to begin with: Alright, I set up a wit.ai project, and it seems to work. Now I have the following snippet:   <section id="chat-bot">    <h2>Ask me anything!</h2>    <input id="chat-prompt" type="text">  </section> I'd like to create a chatbot with this. I can write the responses myself, but can you for now create some JavaScript code that sends an HTTP request to the wit.ai server and parses the result? For now, just print it to the console. It gave us a great place to start and some additional implementation guidelines. We’ve only included the code snippet here:// Function to send the user's message to Wit.ai and parse the response async function sendMessage(message) { // Replace 'YOUR_WITAI_ACCESS_TOKEN' with your actual Wit.ai access token const accessToken = 'YOUR_WITAI_ACCESS_TOKEN'; const apiUrl = `https://api.wit.ai/message?v=20210525&q=${encodeURIComponent(message)}`; try {    const response = await fetch(apiUrl, {      headers: {        Authorization: `Bearer ${accessToken}`      }    });    if (response.ok) {      const data = await response.json();      console.log('Wit.ai Response:', data);      // Process the data and handle the response as needed      // For example, extract intents, entities, or generate appropriate responses    } else {      console.log('Request to Wit.ai failed with status:', response.status);    } } catch (error) {    console.log('An error occurred while communicating with Wit.ai:', error); } } // Event listener for handling user input const inputElement = document.getElementById('chat-prompt'); inputElement.addEventListener('keydown', async (event) => { if (event.key === 'Enter') {    const message = event.target.value.trim();    if (message) {      console.log('User Input:', message);      await sendMessage(message);      event.target.value = ''; // Clear the input field    } } }); It also instructed us to take the following steps:Replace YOUR_WITAI_ACCESS_TOKEN with our actual access tokenPress enter after typing your question and it then logs the response to the console Make sure to put the JavaScript code in the <script> tag This is what it looked like:Image 2: practical output after the first few prompts This was already quite good, but of course, we don’t want the response in the console, but displayed in the chat window. And the same goes for our previous questions, it should become a chat. Let’s see if we can move toward that.Making it into an actual conversationIt’s always a good idea to be specific in your prompt. You can see the following prompt does quite a bit of the heavy lifting and explains clearly what type of work is needed from ChatGPT. This helps to achieve the result: I've modified the HTML a little bit:   <section id="chat-bot">    <ol id="chat-history"></ol>    <h2>Ask me anything!</h2>    <input id="chat-prompt" type="text">  </section> Can you write some logic which can populate the `chat-history` element? I need 3 things: - A history as a JavaScript object- A function which can generate the content from the history- A function which can add the question, and the response, to the history in JavaScript For now just print the top intent and all the entities. This did quite a bit of the work already. You can see the result below, the history and the answers of the two questions asked appear on top of the input box.Image 3: Answers and history appearing on top of the Input box                        It’s no secret that I’m not a UX or design expert, but even I can see that this is not ideal. So let’s see if we can improve the design.Asking ChatGPT to Style the ChatbotLet’s see if we can improve the design. Normally chatbots are not on the top left, but the bottom right. Also, it would be nice if the history could go inside the box. Of course, we want to use the same orange as for the rest of our portfolio. Here’s the prompt: Can you generate some CSS to style the element? I'd like the following: - The chat should be at the bottom right of the page.- The chat should not impact the rest of the page.- Each question and response should have a chat bubble.- The theme color is #f37041.This gave us the CSS and some context as output. Here’s the CSS:#chat-bot { position: fixed; bottom: 20px; right: 20px; z-index: 9999; background-color: #f37041; color: #fff; font-family: Arial, sans-serif; border-radius: 5px; padding: 10px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3); } #chat-history { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow-y: auto; } .question, .response { display: inline-block; max-width: 80%; padding: 8px; border-radius: 10px; margin-bottom: 5px; } .question { background-color: #fff; color: #333; text-align: right; } .response { background-color: #f37041; color: #fff; text-align: left; } #chat-prompt { width: 100%; padding: 8px; margin-top: 10px; border: none; border-radius: 5px; } #chat-prompt:focus { outline: none; } #chat-prompt::placeholder { color: #ccc; } And this did quite the trick. Here’s what it looks like now: Image4: The final output If you’d like to see all the responses and the versions of the personal portfolio after each step, you can check out this GitHub repo: https://github.com/BrightBoost/portfolio-with-ai-prompt-chatgptSummaryIn conclusion, integrating a basic chatbot into your personal portfolio website can significantly enhance user engagement and provide a unique interactive experience. By leveraging GPT prompts, you can effortlessly develop a conversational AI agent that understands and responds to user queries. Adding this functionality not only showcases your technical skills but also demonstrates your ability to create dynamic and user-centric web experiences. So go ahead, implement a chatbot and elevate your portfolio website to the next level. Happy prompting!Author Bio Maaike van Putten is an experienced software developer and Pluralsight, LinkedIn Learning, Udemy, and Bright Boost instructor. She has a passion for software development and helping others get to the next level in their career.LinkedInTraining courses   
Read more
  • 0
  • 0
  • 1500

article-image-demystifying-and-getting-started-with-github-copilot
Rod Anami
13 Jun 2023
6 min read
Save for later

Demystifying and Getting Started with GitHub Copilot

Rod Anami
13 Jun 2023
6 min read
Suddenly, in a blink of an eye, we all started to talk about AI, with particular attention to Generative AI, which produces assets, including code. Not long ago, OpenAI released ChatGPT, which received the spotlight from the media and even interest from people outside IT because of its capacity to sustain a dialog with a human and bring very specialized knowledge to answer questions. Before we continue, as a disclaimer, AI did not generate this very article. In my previous post, I discussed that site reliability engineers (SREs) and other professionals used AI capabilities long before ChatGPT. Today I want to talk about an exciting application of AI to aid software engineers, developers, and SREs in coding with AI-powered pair programming. GitHub Copilot is one notorious example and is sold as an "AI pair programmer." It generates code based on the comments around the code's intention, and it's been gaining traction among the developer's ranks. By the end of this post, you will understand what's Copilot and how to start using it.Does it mean I don't need any development skills anymore?The short answer is not really. Unless the problem you're trying to resolve with code is simple enough to require a few functionalities, you must have solid software development abilities to complete the work, even with Copilot in the game. Copilot is an emerging coding productivity tool, not a no-code or low-code solution. Also, would you sell software that you wouldn't be able to explain how it works? Worse, would you buy software that no one knows how it works?How does it work?GitHub Copilot utilizes OpenAI Codex under the hood. Like ChatGPT, Codex is a descendant of the GPT-3 (third-generation Generative Pre-trained Transformer), a neural network machine learning model trained with data from the Internet and capable of generating any natural language text. On top of that, they used billions of code lines from public repositories to teach Codex. In essence, it can read natural language and forge lines of code in many languages, including "JavaScript, Go, Perl, PHP, Ruby, Swift and TypeScript, and even Shell," but it has more proficiency in Python.Codex possesses four proven coding capacities:Generation: it generates lines of code based on a description in natural languageTranspiration: transforms code written in one language to another one that has a similar level of abstractionExplanation: explains what a block of code does in detailRefactoring: improves the efficiency of a code block without modifying its original intentWith Copilot, it's possible to generate a new block of code by inserting a programming language comment with the description of the code logic. For example, if I type this comment in a JavaScript file:// A function that takes in a string and returns a string with the first letter capitalizedIt may suggest the following code snippet:function capitalizeFirstLetter(string) {        return string.charAt(0).toUpperCase() + string.slice(1);}Another usage is through code recommendations. For instance, it may suggest lines of code to complete an unfinished function or procedure.Will it spy on me?Not at all. According to the GitHub's privacy statement, "neither your Prompts nor Suggestions will be shared or used as suggested code for other users of GitHub Copilot." Of course, publishing your code and the comments used to generate code through Copilot on a public repository may defeat this data privacy.Will it generate the perfect code?No, it will construct a reasonable with minimum accuracy solution, but it does not necessarily mean the generated code perfectly fits your project requirements. You will need to validate if the Copilot recommendations make sense in the context of your project. Also, there's no guarantee the code suggestions are flawless or follow strict security and quality policies.Now that you have a basic understanding of Copilot let's enable it on your laptop. You will need a GitHub account and an integrated development environment (IDE) tool installed on your machine.Enable Copilot for your GitHub personal accountYou can sign up for free at this link if you don't have a GitHub personal account. I'm assuming you have one ready for the rest of the below instructions.Image 1: Copilot pageThe first task is enabling the Copilot feature for your GitHub account; you can do that by selecting one of the pricing plans here. When I wrote this article, there was a free trial option. Next, you need to indicate whether or not you want the code suggestions coming from public code and if Copilot can use your snippets to improve the model (re-train it).Install the Copilot module on your preferred IDEAfter you enable it for your GitHub account, the second task is to install Copilot into your preferred IDE. I'm using Microsoft Visual Studio Code (VS Code), but they provide a package for many other IDEs; you can see the list and specific installation procedure here. Also, if you want, you can download and install VS Code from this official website.Image 2: Copilot extensionFor the VS Code tool, the installation process is straightforward: Open VS Code and click on Extensions in the left navigation panel.Look for the "copilot" term and select the GitHub Copilot extensionUse your GitHub credentials if you don't have any VS Code extension for GitHub yetInstall it and make sure it's enabled globally.Start to experiment with Copilot for realAfter you have the Copilot extension, it's time to test it. Just open a project folder or create a new one.Then create a new file; you can name it after copilot-test.js. If you don't have the JavaScript extension, it will prompt you to install it. Let's craft a comment that will trigger Copilot to generate code. Enter the following statement:// A function that reads a JSON file and returns the number of fields in the JSON objectThen, hit the CTRL+Enter to see possible solutions in a separate window. By the way, you can see all the keyboard shortcuts in this document for VS Code. It can bring up to 10 possible recommendations. Check the one that matches your style and click on the "Accept Solution" link at the end of the section.ConclusionAlthough it may not be the full-fledged AI-fueled programmer we see in the movies, GitHub Copilot helps developers with the initial algorithms and basic coding patterns. It might benefit individual developers and entire companies if seen as a software development productivity tool instead of a mythic autonomous programmer bot.I hope you enjoyed this blog post, and if you liked it, please connect to me on LinkedIn or follow me on Twitter @ranami. Also, my book Becoming a Rockstar SRE is out.
Read more
  • 0
  • 0
  • 161