当前位置:   article > 正文

llama index with azure openai API

llama index with azure openai API

from llama_index.llms.azure_openai import AzureOpenAI
from llama_index.embeddings.azure_openai import AzureOpenAIEmbedding
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
import logging
import sys

logging.basicConfig(
stream=sys.stdout, level=logging.INFO
) # logging.DEBUG for more verbose output
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))

api_key = “xxxxxxxx”
azure_endpoint = “https://xxxxxxxx.openai.azure.com”
api_version = “2023-07-01-preview”

llm = AzureOpenAI(
model=“gpt-35-turbo”,
deployment_name=“gpt-35-turbo”,
api_key=api_key,
azure_endpoint=azure_endpoint,
api_version=api_version,
)

You need to deploy your own embedding model as well as your own chat completion model

embed_model = AzureOpenAIEmbedding(
model=“text-embedding-ada-002”,
deployment_name=“text-embedding-ada-002”,
api_key=api_key,
azure_endpoint=azure_endpoint,
api_version=api_version,
)

from llama_index.core import Settings

Settings.llm = llm
Settings.embed_model = embed_model
documents = SimpleDirectoryReader(
input_files=[“./data/paul_graham_essay.txt”]
).load_data()
index = VectorStoreIndex.from_documents(documents)

query = “What is most interesting about this essay?”
query_engine = index.as_query_engine()
answer = query_engine.query(query)

print(answer.get_formatted_sources())
print(“query was:”, query)
print(“answer was:”, answer)

参考链接

https://docs.llamaindex.ai/en/stable/examples/customization/llms/AzureOpenAI.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/269160
推荐阅读
相关标签
  

闽ICP备14008679号