From cee390db6e405f9e99306f974f4f423af354ddc7 Mon Sep 17 00:00:00 2001 From: dphuang2 Date: Fri, 12 Apr 2024 11:46:26 -0700 Subject: [PATCH] fix ci --- misc/building-ai-applications/.gitignore | 18 + .../Chatbots-checkpoint.ipynb | 431 ------------------ .../.ipynb_checkpoints/RAG-checkpoint.ipynb | 117 ----- .../.ipynb_checkpoints/test.md | 7 - ...ng Guides from OpenAPI Specification.ipynb | 230 ---------- ...b => generating-guides-from-openapi.ipynb} | 12 - 6 files changed, 18 insertions(+), 797 deletions(-) create mode 100644 misc/building-ai-applications/.gitignore delete mode 100644 misc/building-ai-applications/.ipynb_checkpoints/Chatbots-checkpoint.ipynb delete mode 100644 misc/building-ai-applications/.ipynb_checkpoints/RAG-checkpoint.ipynb delete mode 100644 misc/building-ai-applications/.ipynb_checkpoints/test.md delete mode 100644 misc/building-ai-applications/Generating Guides from OpenAPI Specification.ipynb rename misc/building-ai-applications/{.ipynb_checkpoints/Generating Guides from OpenAPI Specification-checkpoint.ipynb => generating-guides-from-openapi.ipynb} (98%) diff --git a/misc/building-ai-applications/.gitignore b/misc/building-ai-applications/.gitignore new file mode 100644 index 000000000..0f443161f --- /dev/null +++ b/misc/building-ai-applications/.gitignore @@ -0,0 +1,18 @@ +# Created by https://www.toptal.com/developers/gitignore/api/jupyternotebooks +# Edit at https://www.toptal.com/developers/gitignore?templates=jupyternotebooks + +### JupyterNotebooks ### +# gitignore template for Jupyter Notebooks +# website: http://jupyter.org/ + +.ipynb_checkpoints +*/.ipynb_checkpoints/* + +# IPython +profile_default/ +ipython_config.py + +# Remove previous ipynb_checkpoints +# git rm -r .ipynb_checkpoints/ + +# End of https://www.toptal.com/developers/gitignore/api/jupyternotebooks \ No newline at end of file diff --git a/misc/building-ai-applications/.ipynb_checkpoints/Chatbots-checkpoint.ipynb b/misc/building-ai-applications/.ipynb_checkpoints/Chatbots-checkpoint.ipynb deleted file mode 100644 index 7e11a59e1..000000000 --- a/misc/building-ai-applications/.ipynb_checkpoints/Chatbots-checkpoint.ipynb +++ /dev/null @@ -1,431 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 4, - "id": "222c4363-1867-4b38-8980-56aa609d2d0d", - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_openai import ChatOpenAI\n", - "\n", - "chat = ChatOpenAI(model=\"gpt-3.5-turbo-1106\", temperature=0.2)" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "eca0b05d-56f0-4170-b40e-2d36843c1dd3", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "AIMessage(content=\"J'adore la programmation.\", response_metadata={'token_usage': {'completion_tokens': 8, 'prompt_tokens': 19, 'total_tokens': 27}, 'model_name': 'gpt-3.5-turbo-1106', 'system_fingerprint': 'fp_592ef5907d', 'finish_reason': 'stop', 'logprobs': None}, id='run-5f63377a-4878-4173-9277-201111eb9c55-0')" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from langchain_core.messages import HumanMessage\n", - "\n", - "chat.invoke(\n", - " [\n", - " HumanMessage(\n", - " content=\"Translate this sentence from English to French: I love programming.\"\n", - " )\n", - " ]\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "4c7a766c-d23a-48c6-a3de-bfcce879d736", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "AIMessage(content='I apologize if there was any confusion. Can you please let me know what specific part of my previous response you would like me to clarify or repeat?', response_metadata={'token_usage': {'completion_tokens': 30, 'prompt_tokens': 13, 'total_tokens': 43}, 'model_name': 'gpt-3.5-turbo-1106', 'system_fingerprint': 'fp_592ef5907d', 'finish_reason': 'stop', 'logprobs': None}, id='run-96a8be1d-43e1-4d13-96a0-6e0901e20539-0')" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "chat.invoke([HumanMessage(content=\"What did you just say?\")])" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "541b4cd9-01bb-45cd-8d21-f32fb90f5a4c", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "AIMessage(content='I said \"J\\'adore la programmation\" which means \"I love programming\" in French.', response_metadata={'token_usage': {'completion_tokens': 21, 'prompt_tokens': 41, 'total_tokens': 62}, 'model_name': 'gpt-3.5-turbo-1106', 'system_fingerprint': 'fp_592ef5907d', 'finish_reason': 'stop', 'logprobs': None}, id='run-5d2eb355-00cb-4137-ad84-992b3bff3a7b-0')" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from langchain_core.messages import AIMessage\n", - "\n", - "chat.invoke(\n", - " [\n", - " HumanMessage(\n", - " content=\"Translate this sentence from English to French: I love programming.\"\n", - " ),\n", - " AIMessage(content=\"J'adore la programmation.\"),\n", - " HumanMessage(content=\"What did you just say?\"),\n", - " ]\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "750c36b5-856d-474a-8026-e158c00fda90", - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n", - "\n", - "prompt = ChatPromptTemplate.from_messages(\n", - " [\n", - " (\n", - " \"system\",\n", - " \"You are a helpful assistant. Answer all questions to the best of your ability. But at the end of every sentence, add a little joke.\",\n", - " ),\n", - " MessagesPlaceholder(variable_name=\"messages\"),\n", - " ]\n", - ")\n", - "\n", - "chain = prompt | chat" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "78ff74cd-3c22-4c49-9575-e6378c2fdcd1", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "AIMessage(content='I said, \"J\\'adore la programmation.\" That\\'s French for \"I love programming.\" And I must say, that\\'s un peu magnifique!', response_metadata={'token_usage': {'completion_tokens': 33, 'prompt_tokens': 84, 'total_tokens': 117}, 'model_name': 'gpt-3.5-turbo-1106', 'system_fingerprint': 'fp_77a673219d', 'finish_reason': 'stop', 'logprobs': None}, id='run-01e974d6-3d67-47d9-bda8-b7196656d9e7-0')" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "chain.invoke(\n", - " {\n", - " \"messages\": [\n", - " HumanMessage(\n", - " content=\"Translate this sentence from English to French: I love programming.\"\n", - " ),\n", - " AIMessage(content=\"J'adore la programmation.\"),\n", - " HumanMessage(content=\"What did you just say?\"),\n", - " HumanMessage(content=\"What did you just say?\"),\n", - " ],\n", - " }\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "8f7e3dc4-4132-4583-9e6c-9c56e530ab10", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[HumanMessage(content='hi!'), AIMessage(content='whats up?')]" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from langchain.memory import ChatMessageHistory\n", - "\n", - "demo_ephemeral_chat_history = ChatMessageHistory()\n", - "\n", - "demo_ephemeral_chat_history.add_user_message(\"hi!\")\n", - "\n", - "demo_ephemeral_chat_history.add_ai_message(\"whats up?\")\n", - "\n", - "demo_ephemeral_chat_history.messages" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "c4988b74-98e7-40ee-98d7-d60fb1980677", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "AIMessage(content='Je adore la programmation. And I also love \"Ctrl\" and \"C\" because I always like to be in control and copy everything!', response_metadata={'token_usage': {'completion_tokens': 29, 'prompt_tokens': 66, 'total_tokens': 95}, 'model_name': 'gpt-3.5-turbo-1106', 'system_fingerprint': 'fp_592ef5907d', 'finish_reason': 'stop', 'logprobs': None}, id='run-fddc67bb-4754-4fd7-9866-3faf82313362-0')" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "demo_ephemeral_chat_history.add_user_message(\n", - " \"Translate this sentence from English to French: I love programming.\"\n", - ")\n", - "\n", - "response = chain.invoke({\"messages\": demo_ephemeral_chat_history.messages})\n", - "\n", - "response" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "id": "13a6c8b4-9373-4a4d-bc40-baf3c32ca7b5", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "AIMessage(content='I said \"Je adore la programmation,\" which means \"I love programming\" in French. And then I added a little joke about \"Ctrl\" and \"C\" because I always like to be in control and copy everything!', response_metadata={'token_usage': {'completion_tokens': 46, 'prompt_tokens': 109, 'total_tokens': 155}, 'model_name': 'gpt-3.5-turbo-1106', 'system_fingerprint': 'fp_592ef5907d', 'finish_reason': 'stop', 'logprobs': None}, id='run-f9758e0e-bd47-4f16-b022-20920cd218e4-0')" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "demo_ephemeral_chat_history.add_ai_message(response)\n", - "\n", - "demo_ephemeral_chat_history.add_user_message(\"What did you just say?\")\n", - "\n", - "chain.invoke({\"messages\": demo_ephemeral_chat_history.messages})" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "id": "0d1418be-467c-4c9b-9464-0bd2e2423804", - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_community.document_loaders import WebBaseLoader\n", - "\n", - "loader = WebBaseLoader(\"https://docs.smith.langchain.com/overview\")\n", - "data = loader.load()" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "id": "b0233b5f-a6e4-481b-ae94-8adca9e1d340", - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_text_splitters import RecursiveCharacterTextSplitter\n", - "\n", - "text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=0)\n", - "all_splits = text_splitter.split_documents(data)" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "id": "006c09b8-52df-49db-a5d5-9076bfbb5e72", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "1" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(data)" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "id": "3720860a-7713-49c6-802b-e9d0bf34616b", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "16" - ] - }, - "execution_count": 34, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(all_splits)" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "id": "57db6a3b-a581-40d8-850b-25b2e0b42191", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 36, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from langchain_community.vectorstores import Chroma\n", - "from langchain_openai import OpenAIEmbeddings\n", - "\n", - "vectorstore = Chroma.from_documents(documents=all_splits, embedding=OpenAIEmbeddings())\n", - "vectorstore" - ] - }, - { - "cell_type": "code", - "execution_count": 37, - "id": "dec395c6-ef81-4e5d-a456-f49cdd1f435b", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[Document(page_content='Getting started with LangSmith | 🦜️🛠️ LangSmith', metadata={'description': 'Introduction', 'language': 'en', 'source': 'https://docs.smith.langchain.com/overview', 'title': 'Getting started with LangSmith | 🦜️🛠️ LangSmith'}),\n", - " Document(page_content='Getting started with LangSmith | 🦜️🛠️ LangSmith', metadata={'description': 'Introduction', 'language': 'en', 'source': 'https://docs.smith.langchain.com/overview', 'title': 'Getting started with LangSmith | 🦜️🛠️ LangSmith'}),\n", - " Document(page_content='Skip to main contentLangSmith API DocsSearchGo to AppQuick StartUser GuideTracingEvaluationProduction Monitoring & AutomationsPrompt HubProxyPricingSelf-HostingCookbookQuick StartOn this pageGetting started with LangSmithIntroduction\\u200bLangSmith is a platform for building production-grade LLM applications. It allows you to closely monitor and evaluate your application, so you can ship quickly and with confidence. Use of LangChain is not necessary - LangSmith works on its own!Install LangSmith\\u200bWe', metadata={'description': 'Introduction', 'language': 'en', 'source': 'https://docs.smith.langchain.com/overview', 'title': 'Getting started with LangSmith | 🦜️🛠️ LangSmith'}),\n", - " Document(page_content='Skip to main contentLangSmith API DocsSearchGo to AppQuick StartUser GuideTracingEvaluationProduction Monitoring & AutomationsPrompt HubProxyPricingSelf-HostingCookbookQuick StartOn this pageGetting started with LangSmithIntroduction\\u200bLangSmith is a platform for building production-grade LLM applications. It allows you to closely monitor and evaluate your application, so you can ship quickly and with confidence. Use of LangChain is not necessary - LangSmith works on its own!Install LangSmith\\u200bWe', metadata={'description': 'Introduction', 'language': 'en', 'source': 'https://docs.smith.langchain.com/overview', 'title': 'Getting started with LangSmith | 🦜️🛠️ LangSmith'})]" - ] - }, - "execution_count": 37, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# k is the number of chunks to retrieve\n", - "retriever = vectorstore.as_retriever(k=4)\n", - "\n", - "docs = retriever.invoke(\"how can langsmith help with testing?\")\n", - "\n", - "docs" - ] - }, - { - "cell_type": "code", - "execution_count": 38, - "id": "dd3b89ae-8496-4ac3-8c92-dfbd99740320", - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.chains.combine_documents import create_stuff_documents_chain\n", - "\n", - "chat = ChatOpenAI(model=\"gpt-3.5-turbo-1106\")\n", - "\n", - "question_answering_prompt = ChatPromptTemplate.from_messages(\n", - " [\n", - " (\n", - " \"system\",\n", - " \"Answer the user's questions based on the below context:\\n\\n{context}\",\n", - " ),\n", - " MessagesPlaceholder(variable_name=\"messages\"),\n", - " ]\n", - ")\n", - "\n", - "document_chain = create_stuff_documents_chain(chat, question_answering_prompt)" - ] - }, - { - "cell_type": "code", - "execution_count": 39, - "id": "0cd3cef8-7ea5-4c45-b6bc-2f00835f9bcf", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'LangSmith can help with testing by providing tools for closely monitoring and evaluating your application during the testing phase. It allows you to track and analyze the performance of your application, identify any potential issues or bottlenecks, and ensure that your application is ready for production. With LangSmith, you can gain confidence in the quality and reliability of your application before shipping it.'" - ] - }, - "execution_count": 39, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from langchain.memory import ChatMessageHistory\n", - "\n", - "demo_ephemeral_chat_history = ChatMessageHistory()\n", - "\n", - "demo_ephemeral_chat_history.add_user_message(\"how can langsmith help with testing?\")\n", - "\n", - "document_chain.invoke(\n", - " {\n", - " \"messages\": demo_ephemeral_chat_history.messages,\n", - " \"context\": docs,\n", - " }\n", - ")" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/misc/building-ai-applications/.ipynb_checkpoints/RAG-checkpoint.ipynb b/misc/building-ai-applications/.ipynb_checkpoints/RAG-checkpoint.ipynb deleted file mode 100644 index 049b5be0d..000000000 --- a/misc/building-ai-applications/.ipynb_checkpoints/RAG-checkpoint.ipynb +++ /dev/null @@ -1,117 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 3, - "id": "edc14b04-7e1c-41c2-92a5-4a4c0017924a", - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "import bs4\n", - "from langchain import hub\n", - "from langchain_community.document_loaders import WebBaseLoader\n", - "from langchain_community.vectorstores import Chroma\n", - "from langchain_core.output_parsers import StrOutputParser\n", - "from langchain_core.runnables import RunnablePassthrough\n", - "from langchain_openai import OpenAIEmbeddings\n", - "from langchain_text_splitters import RecursiveCharacterTextSplitter" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "1473caab-04ca-4fa1-b4eb-24ffbafe4c44", - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_openai import ChatOpenAI\n", - "\n", - "llm = ChatOpenAI(model=\"gpt-3.5-turbo-0125\")" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "ccbac0f7-d2de-4c0a-b45b-1d93bf5f3f68", - "metadata": {}, - "outputs": [], - "source": [ - "# Load, chunk and index the contents of the blog.\n", - "loader = WebBaseLoader(\n", - " web_paths=(\"https://docs.snaptrade.com/demo/getting-started\",),\n", - ")\n", - "docs = loader.load()\n", - "\n", - "text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)\n", - "splits = text_splitter.split_documents(docs)\n", - "vectorstore = Chroma.from_documents(documents=splits, embedding=OpenAIEmbeddings())\n", - "\n", - "# Retrieve and generate using the relevant snippets of the blog.\n", - "retriever = vectorstore.as_retriever()\n", - "prompt = hub.pull(\"rlm/rag-prompt\")\n", - "\n", - "def format_docs(docs):\n", - " return \"\\n\\n\".join(doc.page_content for doc in docs)\n", - "\n", - "\n", - "rag_chain = (\n", - " {\"context\": retriever | format_docs, \"question\": RunnablePassthrough()}\n", - " | prompt\n", - " | llm\n", - " | StrOutputParser()\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "ad94e048-289f-444e-9552-a3e41bcb9be4", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'To get started with SnapTrade, you need to initialize a client with your clientId and consumerKey, which can be obtained by contacting api@snaptrade.com. Check that the client is able to make a request to the API server by calling the API Status endpoint. Create a new user on SnapTrade by calling the Register User endpoint with a userId to receive a user id and user secret for accessing user data.'" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "rag_chain.invoke(\"How do I get started with SnapTrade?\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b7515f7d-496c-423d-812b-08a9c17e7253", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/misc/building-ai-applications/.ipynb_checkpoints/test.md b/misc/building-ai-applications/.ipynb_checkpoints/test.md deleted file mode 100644 index baaee31a7..000000000 --- a/misc/building-ai-applications/.ipynb_checkpoints/test.md +++ /dev/null @@ -1,7 +0,0 @@ -```mermaid -graph TD; - A[Start] --> B{Is it?}; - B -->|Yes| C[End]; - C -->|No| D[End]; - B -->|No| D[End]; -``` diff --git a/misc/building-ai-applications/Generating Guides from OpenAPI Specification.ipynb b/misc/building-ai-applications/Generating Guides from OpenAPI Specification.ipynb deleted file mode 100644 index 07c818e88..000000000 --- a/misc/building-ai-applications/Generating Guides from OpenAPI Specification.ipynb +++ /dev/null @@ -1,230 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "98cbe3b5-c41b-437a-a888-ef79da152dc0", - "metadata": {}, - "source": [ - "### Generating Guides from OpenAPI Specification" - ] - }, - { - "cell_type": "markdown", - "id": "e2a11448", - "metadata": {}, - "source": [ - "### (1) Rudimentary Example\n", - "\n", - "\n", - "\n", - "```mermaid\n", - "graph LR\n", - " allow.com.yaml --> DocumentLoader\n", - " DocumentLoader --> Chat\n", - " Query[How do I create a journey in Python?] --> Chat\n", - " Chat --> Guide\n", - "```" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "6cbdeb3a", - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_openai import ChatOpenAI\n", - "from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n", - "from langchain.chains.combine_documents import create_stuff_documents_chain\n", - "\n", - "\n", - "chat = ChatOpenAI(model=\"gpt-4-turbo-preview\", temperature=0.2)\n", - "question_answering_prompt = ChatPromptTemplate.from_messages(\n", - " [\n", - " (\n", - " \"system\",\n", - " \"Answer the user's questions based on the below context:\\n\\n{context}\",\n", - " ),\n", - " MessagesPlaceholder(variable_name=\"messages\"),\n", - " ]\n", - ")\n", - "document_chain = create_stuff_documents_chain(chat, question_answering_prompt)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "id": "0a81101f-7a0e-4222-a088-0a3fd09a564f", - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.document_loaders.text import TextLoader\n", - "\n", - "file_path = 'alloy.com.yaml'\n", - "loader = TextLoader(file_path)\n", - "docs = loader.load()" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "id": "8a4efa9c-c3d2-4dbe-85b6-63f38db462cf", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'To create a journey in Python using the Alloy API, you would typically perform a POST request to the `/journeys/{journey_token}/applications` endpoint. This request would create a journey application for one or more entities based on the journey specified by the `journey_token`. Below is an example of how you might do this using Python\\'s `requests` library.\\n\\nFirst, ensure you have the `requests` library installed. If not, you can install it using pip:\\n\\n```bash\\npip install requests\\n```\\n\\nHere\\'s a sample Python script to create a journey application:\\n\\n```python\\nimport requests\\nimport json\\n\\n# Replace these variables with your actual data\\njourney_token = \"your_journey_token_here\"\\nauthorization_header = \"Basic your_base64_encoded_credentials\"\\nalloy_api_url = f\"https://demo-qasandbox.alloy.co/v1/journeys/{journey_token}/applications\"\\n\\n# Sample payload. Replace or modify the entities as per your journey\\'s requirements\\npayload = {\\n \"entities\": [\\n {\\n \"external_entity_id\": \"person-entity\",\\n \"gender\": \"male\",\\n \"birth_date\": \"1998-02-03\",\\n \"name_first\": \"John\",\\n \"name_last\": \"Doe\",\\n \"document_ssn\": \"123456789\",\\n \"addresses\": [\\n {\\n \"address_line_1\": \"41 E. 11th\",\\n \"address_city\": \"New York\",\\n \"address_state\": \"NY\",\\n \"address_postal_code\": \"10003\",\\n \"address_country_code\": \"US\",\\n \"type\": \"primary\"\\n }\\n ],\\n \"emails\": [\\n {\\n \"email_address\": \"john@alloy.com\"\\n }\\n ],\\n \"phones\": [\\n {\\n \"phone_number\": \"555-000-1234\"\\n }\\n ],\\n \"pii_status\": \"successful\"\\n }\\n ]\\n}\\n\\nheaders = {\\n \"Authorization\": authorization_header,\\n \"Content-Type\": \"application/json\"\\n}\\n\\nresponse = requests.post(alloy_api_url, headers=headers, data=json.dumps(payload))\\n\\nif response.status_code == 201:\\n print(\"Journey application created successfully.\")\\n print(response.json())\\nelse:\\n print(f\"Failed to create journey application. Status code: {response.status_code}\")\\n print(response.json())\\n```\\n\\nThis script constructs a POST request to the Alloy API to create a journey application. It includes a sample payload with one entity. You\\'ll need to replace `your_journey_token_here` with your actual journey token and `your_base64_encoded_credentials` with your Base64-encoded `application_token:application_secret`. \\n\\nThe `external_entity_id`, `gender`, `birth_date`, `name_first`, `name_last`, `document_ssn`, `addresses`, `emails`, `phones`, and `pii_status` in the payload should be adjusted according to the specific requirements of your journey and the data you have.\\n\\nAfter sending the request, the script checks the response status code. If the journey application is created successfully, it prints the success message and the response JSON. Otherwise, it prints an error message along with the status code and response JSON for debugging.'" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from langchain.memory import ChatMessageHistory\n", - "\n", - "demo_ephemeral_chat_history = ChatMessageHistory()\n", - "\n", - "demo_ephemeral_chat_history.add_user_message(\"How do I create a journey in Python?\")\n", - "\n", - "document_chain.invoke(\n", - " {\n", - " \"messages\": demo_ephemeral_chat_history.messages,\n", - " \"context\": docs,\n", - " }\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "id": "7791d6df-c1f1-43ea-aa57-6aff4dc3bb73", - "metadata": {}, - "outputs": [], - "source": [ - "output = 'To create a journey in Python using the Alloy API, you would typically perform a POST request to the `/journeys/{journey_token}/applications` endpoint. This request would create a journey application for one or more entities based on the journey specified by the `journey_token`. Below is an example of how you might do this using Python\\'s `requests` library.\\n\\nFirst, ensure you have the `requests` library installed. If not, you can install it using pip:\\n\\n```bash\\npip install requests\\n```\\n\\nHere\\'s a sample Python script to create a journey application:\\n\\n```python\\nimport requests\\nimport json\\n\\n# Replace these variables with your actual data\\njourney_token = \"your_journey_token_here\"\\nauthorization_header = \"Basic your_base64_encoded_credentials\"\\nalloy_api_url = f\"https://demo-qasandbox.alloy.co/v1/journeys/{journey_token}/applications\"\\n\\n# Sample payload. Replace or modify the entities as per your journey\\'s requirements\\npayload = {\\n \"entities\": [\\n {\\n \"external_entity_id\": \"person-entity\",\\n \"gender\": \"male\",\\n \"birth_date\": \"1998-02-03\",\\n \"name_first\": \"John\",\\n \"name_last\": \"Doe\",\\n \"document_ssn\": \"123456789\",\\n \"addresses\": [\\n {\\n \"address_line_1\": \"41 E. 11th\",\\n \"address_city\": \"New York\",\\n \"address_state\": \"NY\",\\n \"address_postal_code\": \"10003\",\\n \"address_country_code\": \"US\",\\n \"type\": \"primary\"\\n }\\n ],\\n \"emails\": [\\n {\\n \"email_address\": \"john@alloy.com\"\\n }\\n ],\\n \"phones\": [\\n {\\n \"phone_number\": \"555-000-1234\"\\n }\\n ],\\n \"pii_status\": \"successful\"\\n }\\n ]\\n}\\n\\nheaders = {\\n \"Authorization\": authorization_header,\\n \"Content-Type\": \"application/json\"\\n}\\n\\nresponse = requests.post(alloy_api_url, headers=headers, data=json.dumps(payload))\\n\\nif response.status_code == 201:\\n print(\"Journey application created successfully.\")\\n print(response.json())\\nelse:\\n print(f\"Failed to create journey application. Status code: {response.status_code}\")\\n print(response.json())\\n```\\n\\nThis script constructs a POST request to the Alloy API to create a journey application. It includes a sample payload with one entity. You\\'ll need to replace `your_journey_token_here` with your actual journey token and `your_base64_encoded_credentials` with your Base64-encoded `application_token:application_secret`. \\n\\nThe `external_entity_id`, `gender`, `birth_date`, `name_first`, `name_last`, `document_ssn`, `addresses`, `emails`, `phones`, and `pii_status` in the payload should be adjusted according to the specific requirements of your journey and the data you have.\\n\\nAfter sending the request, the script checks the response status code. If the journey application is created successfully, it prints the success message and the response JSON. Otherwise, it prints an error message along with the status code and response JSON for debugging.'" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "id": "0187cf3f-bc8e-49c7-9acc-f412b0e57ed2", - "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "To create a journey in Python using the Alloy API, you would typically perform a POST request to the `/journeys/{journey_token}/applications` endpoint. This request would create a journey application for one or more entities based on the journey specified by the `journey_token`. Below is an example of how you might do this using Python's `requests` library.\n", - "\n", - "First, ensure you have the `requests` library installed. If not, you can install it using pip:\n", - "\n", - "```bash\n", - "pip install requests\n", - "```\n", - "\n", - "Here's a sample Python script to create a journey application:\n", - "\n", - "```python\n", - "import requests\n", - "import json\n", - "\n", - "# Replace these variables with your actual data\n", - "journey_token = \"your_journey_token_here\"\n", - "authorization_header = \"Basic your_base64_encoded_credentials\"\n", - "alloy_api_url = f\"https://demo-qasandbox.alloy.co/v1/journeys/{journey_token}/applications\"\n", - "\n", - "# Sample payload. Replace or modify the entities as per your journey's requirements\n", - "payload = {\n", - " \"entities\": [\n", - " {\n", - " \"external_entity_id\": \"person-entity\",\n", - " \"gender\": \"male\",\n", - " \"birth_date\": \"1998-02-03\",\n", - " \"name_first\": \"John\",\n", - " \"name_last\": \"Doe\",\n", - " \"document_ssn\": \"123456789\",\n", - " \"addresses\": [\n", - " {\n", - " \"address_line_1\": \"41 E. 11th\",\n", - " \"address_city\": \"New York\",\n", - " \"address_state\": \"NY\",\n", - " \"address_postal_code\": \"10003\",\n", - " \"address_country_code\": \"US\",\n", - " \"type\": \"primary\"\n", - " }\n", - " ],\n", - " \"emails\": [\n", - " {\n", - " \"email_address\": \"john@alloy.com\"\n", - " }\n", - " ],\n", - " \"phones\": [\n", - " {\n", - " \"phone_number\": \"555-000-1234\"\n", - " }\n", - " ],\n", - " \"pii_status\": \"successful\"\n", - " }\n", - " ]\n", - "}\n", - "\n", - "headers = {\n", - " \"Authorization\": authorization_header,\n", - " \"Content-Type\": \"application/json\"\n", - "}\n", - "\n", - "response = requests.post(alloy_api_url, headers=headers, data=json.dumps(payload))\n", - "\n", - "if response.status_code == 201:\n", - " print(\"Journey application created successfully.\")\n", - " print(response.json())\n", - "else:\n", - " print(f\"Failed to create journey application. Status code: {response.status_code}\")\n", - " print(response.json())\n", - "```\n", - "\n", - "This script constructs a POST request to the Alloy API to create a journey application. It includes a sample payload with one entity. You'll need to replace `your_journey_token_here` with your actual journey token and `your_base64_encoded_credentials` with your Base64-encoded `application_token:application_secret`. \n", - "\n", - "The `external_entity_id`, `gender`, `birth_date`, `name_first`, `name_last`, `document_ssn`, `addresses`, `emails`, `phones`, and `pii_status` in the payload should be adjusted according to the specific requirements of your journey and the data you have.\n", - "\n", - "After sending the request, the script checks the response status code. If the journey application is created successfully, it prints the success message and the response JSON. Otherwise, it prints an error message along with the status code and response JSON for debugging." - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "from IPython.display import display, Markdown\n", - "\n", - "display(Markdown(output))" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/misc/building-ai-applications/.ipynb_checkpoints/Generating Guides from OpenAPI Specification-checkpoint.ipynb b/misc/building-ai-applications/generating-guides-from-openapi.ipynb similarity index 98% rename from misc/building-ai-applications/.ipynb_checkpoints/Generating Guides from OpenAPI Specification-checkpoint.ipynb rename to misc/building-ai-applications/generating-guides-from-openapi.ipynb index 07c818e88..e7da7e70c 100644 --- a/misc/building-ai-applications/.ipynb_checkpoints/Generating Guides from OpenAPI Specification-checkpoint.ipynb +++ b/misc/building-ai-applications/generating-guides-from-openapi.ipynb @@ -211,18 +211,6 @@ "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.6" } }, "nbformat": 4,