# 1. Azure OpenAI Services
Azure OpenAI Service (hereinafter referred to as AOAI) is OpenAI's artificial intelligence (AI) service provided on the Microsoft Azure cloud platform.
Natural language processing models such as GPT-4 and ChatGPT developed by OpenAI can be used.
[What is Azure OpenAI Service? ja](https://www.jbcc.co.jp/blog/column/azure_open_ai.html)
[Pricing](https://azure.microsoft.com/ja-jp/pricing/details/cognitive-services/openai-service/)
**Note: Set Region to Japan East on all of the functions that you are going to use**
## Creating resources
Open Azure [Home page ](https://portal.azure.com/#home)
1. Choose Azure OpenAI/ Create a resource

2. Click create a resource and search "openai" in marketplace after that click Create on Azure OpenAI or any other services that you want to use

3. Create Azure OpenAI (Create new resource group if it doesnt exist)
**Note: Set Region to Japan East on all of the functions that you are going to use**

4. After Next (2) Network

5. Tag Name and Value (default) click Next

6. Review + submit (adjust if you have done any mistake) & click Create

7. Redirected to the Overview Page as below

## Deploying the model
got back to Home> Subscriptions > Click Subscription name > Subscriptions Click View resources or Just click Go to Resources from steop 7 page
1. You can find out the Resources that you have created earlier

2. Double click to Open (preview of bottom half)

3. Click Go to Azure OpenAI studio

4. Welcome to Azure OpenAI service > Click Create new deployment

Got prompt

I had to revert back my region to different region as I was not able to create new deployment with gpt35 with region Japan east there was no issues
5. Deploy model (here we deploy gpt-35-turbo)

You can see the lis of created/ deployed models in deployments
**Deploying text-embedding-ada-002 was not possible because of quota limitation**
6. Model deployment status success

## Network Settings
(Before this create a [Virtual Network Resources](https://hackmd.io/0A5k45WBSNKqSCYL75h1_g))
Even if confidential information such as endpoints and API keys are leaked to external users, it is recommended to set up a firewall on resources to prevent unauthorized use.
As we have used By default "All networks" in network settings lets adjust it
1. Open resources and open Networking in right hand side

### use by API case I (Not recommended)
```
#with openai version 1.7.2
# openai[datalib]==1.7.2
# pip install openai==1.7.2
# doesnt supports AzureOpenAI
# requires atleas 1.XX api_version
# pip install --upgrade openai
from openai import AzureOpenAI
# visit Keys and Endpoints for the information in inyou resources management > Keys and Endpoint
resorce_name = "oai-jp-gpt35"
embedding_deploy_name = "gpt-35-turbo" # AOAIのembeddingモデルのデプロイ名
chat_deploy_name = "gpt35" # AOAIのChatモデルのデプロイ名
client = AzureOpenAI(azure_endpoint=f"https://{resorce_name}.openai.azure.com/", #endポイント
api_version="2023-07-01-preview", #Azure AI Studioのチャットプレイグランドで送信例のコード表示から
api_key="455b5a2dec89489b88d6c8c21880025d" #APIキー
)
use_messages = [{
"role": "user",
"content": "Say about Ram"
}]
response = client.chat.completions.create(model=chat_deploy_name,
messages=use_messages,
temperature=0,
max_tokens=2000,
top_p=0.95,
frequency_penalty=0,
presence_penalty=0,
stop=None
)
r = response.choices[0].message.content
print(r)
```
### use by API case II (recommended)
```
# openai[datalib]==0.27.8
# pip install openai==0.27.8
import openai
# visit Keys and Endpoints for the information in inyou resources management > Keys and Endpoint
resorce_name = "resources name"
openai.api_type = "azure" # AOAIを使用するためazure
openai.api_base = f"https://{resorce_name}.openai.azure.com/" #endポイント
openai.api_version = "2023-07-01-preview" #Azure AI Studioのチャットプレイグランドで送信例のコード表示から
openai.api_key = "Key" #APIキー
embedding_deploy_name = "gpt-35-turbo" # AOAIのembeddingモデルのデプロイ名
chat_deploy_name = "gpt35" # AOAIのChatモデルのデプロイ名
use_messages = [{
"role": "user",
"content": "Say about ram"
}]
response = openai.ChatCompletion.create(
engine=chat_deploy_name,
messages=use_messages,
temperature=0,
max_tokens=2000,
top_p=0.95,
frequency_penalty=0,
presence_penalty=0,
stop=None
)
r = response.choices[0].message.content
print(r)
```
# 2. Preparation for Cognitive Search

[Cognitive Search](https://hackmd.io/fh7REExbTUmw9pBOmV4gXw)
# 3. Preparing Azure Function

[Azure Function](https://hackmd.io/WDy2agi1Qo-Kj0_QSNUsRg?view)
# 4. Preparing the web application

[Web Application](https://hackmd.io/aBBgN6qhQKubXjd-PJHVww?both)
# 5. Deploy to Azure Functions

[Deploy To Azure Functions](https://hackmd.io/YNud9cC2Rae4ZQ_k4d-rMA)
# 6. Deploy Azure App Service

[Deploy Azure App Service](https://hackmd.io/TchyTcyJTjuVQ8JS8A1a5Q)
# 7. Appendix: Using conversation history

[Using conversation history](https://hackmd.io/B0BFN99bQuy9YIDIzHEx8g)
# 8. Appendix: Registering data to Azure CosmosDB

[Registering data to Azure CosmosDB](https://hackmd.io/eXA3CTOHQHCJuMphnjlj9w)
# 9. Appendix: How to send a Queue to Azure Queue Storage

[Queue to Azure Queue Storage](https://)