赞
踩
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,
)
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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。