Spaces:
Sleeping
Sleeping
File size: 2,708 Bytes
0fc716a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
{
"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
}
|