{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "from llama_index.llms.azure_openai import AzureOpenAI\n", "from llama_index.embeddings.azure_openai import AzureOpenAIEmbedding\n", "from llama_index.core import SimpleDirectoryReader, Settings, VectorStoreIndex" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "api_key = os.getenv(\"AZURE_OPENAI_API_KEY\")\n", "api_version = \"2024-05-01-preview\"\n", "azure_endpoint = os.getenv(\"AZURE_OPENAI_ENDPOINT\")" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "llm = AzureOpenAI(\n", " model=\"gpt-4o\",\n", " deployment_name=\"gpt-4o\",\n", " api_key=api_key,\n", " azure_endpoint=azure_endpoint,\n", " api_version=api_version,\n", ")" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "# You need to deploy your own embedding model as well as your own chat completion model\n", "embed_model = AzureOpenAIEmbedding(\n", " model=\"text-embedding-3-small\",\n", " deployment_name=\"text-embedding-3-small\",\n", " api_key=api_key,\n", " azure_endpoint=azure_endpoint,\n", " api_version=api_version,\n", ")" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "Settings.llm = llm\n", "Settings.embed_model = embed_model" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "# Data Source -> Documents化を行うStep\n", "documents = SimpleDirectoryReader(\n", " input_dir=\"./data/text\"\n", ").load_data()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "index = VectorStoreIndex.from_documents(documents)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "index.storage_context.persist(persist_dir=\"../index\")" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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.9.11" } }, "nbformat": 4, "nbformat_minor": 2 }