Skip to content

Instantly share code, notes, and snippets.

@csiebler
Last active November 20, 2023 13:59
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save csiebler/e287b791333011183792c08bad1dc140 to your computer and use it in GitHub Desktop.
Save csiebler/e287b791333011183792c08bad1dc140 to your computer and use it in GitHub Desktop.
Using LlamaIndex (GPT Index) with Azure OpenAI Service
import os
import openai
from dotenv import load_dotenv
from llama_index import GPTSimpleVectorIndex, SimpleDirectoryReader, LLMPredictor, PromptHelper
from langchain.llms import AzureOpenAI
from langchain.embeddings import OpenAIEmbeddings
from llama_index import LangchainEmbedding
# Load env variables (create .env with OPENAI_API_KEY and OPENAI_API_BASE)
load_dotenv()
# Configure OpenAI API
openai.api_type = "azure"
openai.api_version = "2022-12-01"
openai.api_base = os.getenv('OPENAI_API_BASE')
openai.api_key = os.getenv("OPENAI_API_KEY")
deployment_name = "text-davinci-003"
# Create LLM via Azure OpenAI Service
llm = AzureOpenAI(deployment_name=deployment_name)
llm_predictor = LLMPredictor(llm=llm)
embedding_llm = LangchainEmbedding(OpenAIEmbeddings())
# Define prompt helper
max_input_size = 3000
num_output = 256
chunk_size_limit = 1000 # token window size per document
max_chunk_overlap = 20 # overlap for each token fragment
prompt_helper = PromptHelper(max_input_size=max_input_size, num_output=num_output, max_chunk_overlap=max_chunk_overlap, chunk_size_limit=chunk_size_limit)
# Read txt files from data directory
documents = SimpleDirectoryReader('data').load_data()
index = GPTSimpleVectorIndex(documents, llm_predictor=llm_predictor, embed_model=embedding_llm, prompt_helper=prompt_helper)
index.save_to_disk("index.json")
# Query index with a question
response = index.query("What is azure openai service?")
print(response)
@Sai-Yannakula
Copy link

can we create index using gptfaissindex using the azure openai

@Sai-Yannakula
Copy link

also is it possible to create index.json for pdf files

@csiebler
Copy link
Author

can we create index using gptfaissindex using the azure openai

Yes, I've tested it with LangChain and Azure OpenAI Service, works. See https://clemenssiebler.com/posts/using-langchain-with-azure-openai-service/.

@Sai-Yannakula
Copy link

do u know how to query a pdf using azure openai. if so can brief me about that

@arindamhazramsft
Copy link

Hello, following your code provided above. I am getting TypeError: BaseGPTIndex.init() got an unexpected keyword argument 'llm_predictor' error. Am I missing anything here? Thanks in advance!

@csiebler
Copy link
Author

csiebler commented Apr 3, 2023

can we create index using gptfaissindex using the azure openai

Please look here: https://clemenssiebler.com/posts/chatting-private-data-langchain-azure-openai-service/

@Sanjaykumarojha
Copy link

how to know from which file in data folder I'm getting the output and print that file name also

@carchi8py
Copy link

@arindamhazramsft i did as well

from llama_index import ServiceContext
service_context = ServiceContext.from_defaults(
llm_predictor=llm_predictor, prompt_helper=prompt_helper, embed_model=embedding_llm
)

index = GPTSimpleVectorIndex.from_documents(documents, service_context=service_context)

Got past that error but I ended up with

openai.error.InvalidRequestError: Must provide an 'engine' or 'deployment_id' parameter to create a <class 'openai.api_resources.completion.Completion'>

@csiebler
Copy link
Author

openai.error.InvalidRequestError: Must provide an 'engine' or 'deployment_id' parameter to create a <class 'openai.api_resources.completion.Completion'>

Looks like your LLM is not properly initialized. For this, maybe just copy the code from this post: https://clemenssiebler.com/posts/chatting-private-data-langchain-azure-openai-service/, mainly:

# Configure OpenAI API
openai.api_type = "azure"
openai.api_version = "2023-03-15-preview"
openai.api_base = os.getenv('OPENAI_API_BASE')
openai.api_key = os.getenv("OPENAI_API_KEY")

# Initialize gpt-35-turbo and our embedding model
llm = AzureChatOpenAI(deployment_name="gpt-35-turbo", openai_api_version="2023-03-15-preview")

@carchi8py
Copy link

carchi8py commented Apr 17, 2023

I did end up getting this working, just looking at what different from above and mine is the following

service_context = ServiceContext.from_defaults(
   llm_predictor=llm_predictor, prompt_helper=prompt_helper, embed_model=embedding_llm
   )
# Create index
index = GPTSimpleVectorIndex.from_documents(documents, service_context=service_context)

@guangsenw
Copy link

I am also using openai.api_type = "azure" and openai.api_version = "2023-03-15-preview". However, when running the script, I got the following errors when using deployment_name="gpt-35-turbo":
"INFO:openai:error_code=DeploymentNotFound error_message='The API deployment for this resource does not exist.'"
could you please help? thanks

@zhangao0086
Copy link

I am also using openai.api_type = "azure" and openai.api_version = "2023-03-15-preview". However, when running the script, I got the following errors when using deployment_name="gpt-35-turbo": "INFO:openai:error_code=DeploymentNotFound error_message='The API deployment for this resource does not exist.'" could you please help? thanks

+1 here

@csiebler
Copy link
Author

csiebler commented Apr 24, 2023

@guangsenw @zhangao0086 - can you check that you have a model deployment named exactly gpt-35-turbo in Azure OpenAI Service? Are you running llama-index or are you purely using LangChain?

Please check if this piece of code works:

import os
import openai
from dotenv import load_dotenv
from langchain.chat_models import AzureChatOpenAI
from langchain import LLMChain
from langchain.prompts.chat import (
    ChatPromptTemplate,
    SystemMessagePromptTemplate,
    HumanMessagePromptTemplate,
)

# Load environment variables (set OPENAI_API_KEY and OPENAI_API_BASE in .env)
load_dotenv()

# Configure Azure OpenAI Service API
openai.api_type = "azure"
openai.api_version = "2023-03-15-preview"
openai.api_base = os.getenv('OPENAI_API_BASE')
openai.api_key = os.getenv("OPENAI_API_KEY")

# Init LLM and embeddings model
llm = AzureChatOpenAI(deployment_name="gpt-35-turbo", temperature=0.7, openai_api_version="2023-03-15-preview")

template=f"You are an AI assistant that tells jokes."

system_message_prompt = SystemMessagePromptTemplate.from_template(template)
human_template="{text}"
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])

chain = LLMChain(llm=llm, prompt=chat_prompt)
result = chain.run(f"Tell me a dad joke")
print(result)

This will confirm that LangChain works with Azure OpenAI Service with gpt-35-turbo...

@potturiravi
Copy link

I did end up getting this working, just looking at what different from above and mine is the following

service_context = ServiceContext.from_defaults(
   llm_predictor=llm_predictor, prompt_helper=prompt_helper, embed_model=embedding_llm
   )
# Create index
index = GPTSimpleVectorIndex.from_documents(documents, service_context=service_context)

Hi, I did the same thing but still getting error "The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.' error_param=None error_type=None message='OpenAI API error received' stream_error=False"

can you share code where you got this working?

@potturiravi
Copy link

potturiravi commented Apr 26, 2023

@guangsenw @zhangao0086 - can you check that you have a model deployment named exactly gpt-35-turbo in Azure OpenAI Service? Are you running llama-index or are you purely using LangChain?

Please check if this piece of code works:

import os
import openai
from dotenv import load_dotenv
from langchain.chat_models import AzureChatOpenAI
from langchain import LLMChain
from langchain.prompts.chat import (
    ChatPromptTemplate,
    SystemMessagePromptTemplate,
    HumanMessagePromptTemplate,
)

# Load environment variables (set OPENAI_API_KEY and OPENAI_API_BASE in .env)
load_dotenv()

# Configure Azure OpenAI Service API
openai.api_type = "azure"
openai.api_version = "2023-03-15-preview"
openai.api_base = os.getenv('OPENAI_API_BASE')
openai.api_key = os.getenv("OPENAI_API_KEY")

# Init LLM and embeddings model
llm = AzureChatOpenAI(deployment_name="gpt-35-turbo", temperature=0.7, openai_api_version="2023-03-15-preview")

template=f"You are an AI assistant that tells jokes."

system_message_prompt = SystemMessagePromptTemplate.from_template(template)
human_template="{text}"
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])

chain = LLMChain(llm=llm, prompt=chat_prompt)
result = chain.run(f"Tell me a dad joke")
print(result)

This will confirm that LangChain works with Azure OpenAI Service with gpt-35-turbo...

Hi @csiebler This is working fine for me , but when i tried to do
service_context = ServiceContext.from_defaults(
llm_predictor=llm_predictor, prompt_helper=prompt_helper, embed_model=embedding_llm
)

index = GPTSimpleVectorIndex.from_documents(documents, service_context=service_context)

I am getting this error The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.' error_param=None error_type=None message='OpenAI API error received' stream_error=False

can you help to run this code again and see if there needs any other change?

@That1Panda
Copy link

@guangsenw @zhangao0086 - can you check that you have a model deployment named exactly gpt-35-turbo in Azure OpenAI Service? Are you running llama-index or are you purely using LangChain?
Please check if this piece of code works:

import os
import openai
from dotenv import load_dotenv
from langchain.chat_models import AzureChatOpenAI
from langchain import LLMChain
from langchain.prompts.chat import (
    ChatPromptTemplate,
    SystemMessagePromptTemplate,
    HumanMessagePromptTemplate,
)

# Load environment variables (set OPENAI_API_KEY and OPENAI_API_BASE in .env)
load_dotenv()

# Configure Azure OpenAI Service API
openai.api_type = "azure"
openai.api_version = "2023-03-15-preview"
openai.api_base = os.getenv('OPENAI_API_BASE')
openai.api_key = os.getenv("OPENAI_API_KEY")

# Init LLM and embeddings model
llm = AzureChatOpenAI(deployment_name="gpt-35-turbo", temperature=0.7, openai_api_version="2023-03-15-preview")

template=f"You are an AI assistant that tells jokes."

system_message_prompt = SystemMessagePromptTemplate.from_template(template)
human_template="{text}"
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])

chain = LLMChain(llm=llm, prompt=chat_prompt)
result = chain.run(f"Tell me a dad joke")
print(result)

This will confirm that LangChain works with Azure OpenAI Service with gpt-35-turbo...

Hi @csiebler This is working fine for me , but when i tried to do service_context = ServiceContext.from_defaults( llm_predictor=llm_predictor, prompt_helper=prompt_helper, embed_model=embedding_llm )

index = GPTSimpleVectorIndex.from_documents(documents, service_context=service_context)

I am getting this error The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.' error_param=None error_type=None message='OpenAI API error received' stream_error=False

can you help to run this code again and see if there needs any other change?

+1 Here

@ll13j1209
Copy link

Same issue here, does anyone have an exmple of how to create index using gpt_35_turbo

@sai-kiran-adusumilli
Copy link

sai-kiran-adusumilli commented May 4, 2023

I am using gpt_index with azure openai service , while querying the index i am facing errors for only few questions , and for few questions its working fine . can anyone help me in this . Here is my code

#Initialize gpt-35-turbo and our embedding model
llm = AzureChatOpenAI(deployment_name="chat",
openai_api_version="2023-03-15-preview")
embeddings = LangchainEmbedding(OpenAIEmbeddings(deployment ='embeddingModel',
model="text-embedding-ada-002",
chunk_size=1))
llm_predictor = LLMPredictor(llm=llm)
service_context = ServiceContext.from_defaults(chunk_size_limit=2000,embed_model=embeddings,llm_predictor=llm_predictor)

#Read txt files from data directory
documents = SimpleDirectoryReader(r'C:\Users\skiranadusum\Desktop\AzureOpenAI\data').load_data()
index = GPTSimpleVectorIndex.from_documents(documents,service_context=service_context)
query1 = "what are probes"
query2 = "what is biopsy"
response = index.query(query2,verbose=True,service_context=service_context)

for query1 i am getting nice answer from the pdf file , while for the second query (query2) i am facing this error

warning

WARNING:langchain.chat_models.openai:Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.._completion_with_retry in 1.0 seconds as it raised APIError: Invalid response object from API: '{"error":{"message":"The response was filtered due to the prompt triggering Azure OpenAI’s content management policy. Please modify your prompt and retry. To learn more about our content filtering policies please read our documentation: https://go.microsoft.com/fwlink/?linkid=2198766","type":null,"param":"prompt","code":"content_filter","status":400}}' (HTTP response code was 400).

error

APIError: Invalid response object from API: '{"error":{"message":"The response was filtered due to the prompt triggering Azure OpenAI’s content management policy. Please modify your prompt and retry. To learn more about our content filtering policies please read our documentation: https://go.microsoft.com/fwlink/?linkid=2198766","type":null,"param":"prompt","code":"content_filter","status":400}}' (HTTP response code was 400)

@csiebler
Copy link
Author

csiebler commented May 4, 2023

I'm running:

openai==0.27.6
llama-index==0.6.0
langchain==0.0.157

Something is wrong with presumably how llama-index generates the call to langchain. When I use llm that you pass into llm_predictor = LLMPredictor(llm=llm) directly, it get the proper response, but once llama-index uses it, it seems to fail.

@csiebler
Copy link
Author

csiebler commented May 4, 2023

Ok, this works with the mentioned versions:

import os
import openai
from dotenv import load_dotenv
from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader, PromptHelper, LangchainEmbedding, ServiceContext
from langchain.chat_models import AzureChatOpenAI
from langchain.embeddings import OpenAIEmbeddings
from llama_index.llm_predictor.chatgpt import ChatGPTLLMPredictor

# Load environment variables (set OPENAI_API_KEY and OPENAI_API_BASE in .env)
load_dotenv()

openai_api_version = "2023-03-15-preview"

# Configure Azure OpenAI Service API
openai.api_type = "azure"
openai.api_version = openai_api_version
openai.api_base = os.getenv('OPENAI_API_BASE')
openai.api_key = os.getenv("OPENAI_API_KEY")
# openai.log = "debug"

# Initialize LLM and Embeddings model
llm = AzureChatOpenAI(deployment_name="gpt-35-turbo", temperature=0,
                      openai_api_version=openai_api_version)
llm_predictor = ChatGPTLLMPredictor(llm=llm, retry_on_throttling=False)

embeddings = LangchainEmbedding(OpenAIEmbeddings(model="text-embedding-ada-002", chunk_size=1, openai_api_version=openai_api_version))

# Define prompt helper
max_input_size = 3000
num_output = 256
chunk_size_limit = 1000
max_chunk_overlap = 20
prompt_helper = PromptHelper(max_input_size=max_input_size, 
                             num_output=num_output, 
                             max_chunk_overlap=max_chunk_overlap, 
                             chunk_size_limit=chunk_size_limit)

service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, embed_model=embeddings, prompt_helper=prompt_helper)

# Load documents
documents = SimpleDirectoryReader('../data/qna/').load_data()

# Create index
index = GPTVectorStoreIndex.from_documents(documents, service_context=service_context, prompt_helper=prompt_helper)
query_engine = index.as_query_engine(service_context=service_context, verbose=True)

query = "What is azure openai service? give me back a bullet point list"
answer = query_engine.query(query)

print(f"Query: {query}")
print(f"Answer: {answer}")
print(f"Sources: {answer.get_formatted_sources()}")

I've used openai.log = "debug" to figure out to which endpoint llama-index/lc are talking. There seems to be an issue where the api-version param is dropped when not specifying it for the embedding, hence resulting in the 404. Please let me know if it works now.

@That1Panda
Copy link

Ok, this works with the mentioned versions:

import os
import openai
from dotenv import load_dotenv
from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader, PromptHelper, LangchainEmbedding, ServiceContext
from langchain.chat_models import AzureChatOpenAI
from langchain.embeddings import OpenAIEmbeddings
from llama_index.llm_predictor.chatgpt import ChatGPTLLMPredictor

# Load environment variables (set OPENAI_API_KEY and OPENAI_API_BASE in .env)
load_dotenv()

openai_api_version = "2023-03-15-preview"

# Configure Azure OpenAI Service API
openai.api_type = "azure"
openai.api_version = openai_api_version
openai.api_base = os.getenv('OPENAI_API_BASE')
openai.api_key = os.getenv("OPENAI_API_KEY")
# openai.log = "debug"

# Initialize LLM and Embeddings model
llm = AzureChatOpenAI(deployment_name="gpt-35-turbo", temperature=0,
                      openai_api_version=openai_api_version)
llm_predictor = ChatGPTLLMPredictor(llm=llm, retry_on_throttling=False)

embeddings = LangchainEmbedding(OpenAIEmbeddings(model="text-embedding-ada-002", chunk_size=1, openai_api_version=openai_api_version))

# Define prompt helper
max_input_size = 3000
num_output = 256
chunk_size_limit = 1000
max_chunk_overlap = 20
prompt_helper = PromptHelper(max_input_size=max_input_size, 
                             num_output=num_output, 
                             max_chunk_overlap=max_chunk_overlap, 
                             chunk_size_limit=chunk_size_limit)

service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, embed_model=embeddings, prompt_helper=prompt_helper)

# Load documents
documents = SimpleDirectoryReader('../data/qna/').load_data()

# Create index
index = GPTVectorStoreIndex.from_documents(documents, service_context=service_context, prompt_helper=prompt_helper)
query_engine = index.as_query_engine(service_context=service_context, verbose=True)

query = "What is azure openai service? give me back a bullet point list"
answer = query_engine.query(query)

print(f"Query: {query}")
print(f"Answer: {answer}")
print(f"Sources: {answer.get_formatted_sources()}")

I've used openai.log = "debug" to figure out to which endpoint llama-index/lc are talking. There seems to be an issue where the api-version param is dropped when not specifying it for the embedding, hence resulting in the 404. Please let me know if it works now.

after using the same version it worked for me too
Been trying to solve it the whole week thanks

@sai-kiran-adusumilli
Copy link

sai-kiran-adusumilli commented May 5, 2023

Ok, this works with the mentioned versions:

import os
import openai
from dotenv import load_dotenv
from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader, PromptHelper, LangchainEmbedding, ServiceContext
from langchain.chat_models import AzureChatOpenAI
from langchain.embeddings import OpenAIEmbeddings
from llama_index.llm_predictor.chatgpt import ChatGPTLLMPredictor

# Load environment variables (set OPENAI_API_KEY and OPENAI_API_BASE in .env)
load_dotenv()

openai_api_version = "2023-03-15-preview"

# Configure Azure OpenAI Service API
openai.api_type = "azure"
openai.api_version = openai_api_version
openai.api_base = os.getenv('OPENAI_API_BASE')
openai.api_key = os.getenv("OPENAI_API_KEY")
# openai.log = "debug"

# Initialize LLM and Embeddings model
llm = AzureChatOpenAI(deployment_name="gpt-35-turbo", temperature=0,
                      openai_api_version=openai_api_version)
llm_predictor = ChatGPTLLMPredictor(llm=llm, retry_on_throttling=False)

embeddings = LangchainEmbedding(OpenAIEmbeddings(model="text-embedding-ada-002", chunk_size=1, openai_api_version=openai_api_version))

# Define prompt helper
max_input_size = 3000
num_output = 256
chunk_size_limit = 1000
max_chunk_overlap = 20
prompt_helper = PromptHelper(max_input_size=max_input_size, 
                             num_output=num_output, 
                             max_chunk_overlap=max_chunk_overlap, 
                             chunk_size_limit=chunk_size_limit)

service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, embed_model=embeddings, prompt_helper=prompt_helper)

# Load documents
documents = SimpleDirectoryReader('../data/qna/').load_data()

# Create index
index = GPTVectorStoreIndex.from_documents(documents, service_context=service_context, prompt_helper=prompt_helper)
query_engine = index.as_query_engine(service_context=service_context, verbose=True)

query = "What is azure openai service? give me back a bullet point list"
answer = query_engine.query(query)

print(f"Query: {query}")
print(f"Answer: {answer}")
print(f"Sources: {answer.get_formatted_sources()}")

I've used openai.log = "debug" to figure out to which endpoint llama-index/lc are talking. There seems to be an issue where the api-version param is dropped when not specifying it for the embedding, hence resulting in the 404. Please let me know if it works now.

It didn't work for all queries

query_engine = index.as_query_engine(service_context=service_context, verbose=True)

query1 = "what is biopsy"
query2 = "what are biopsy kit components"
query3 = "what are the things used in biopsy kit"
query4 = "what are probes"
answer = query_engine.query(query2)

in my previous comment it failed for query1
using the solution that you have provided it works for query1 but fails for query2
to be suprised it works for query3 , is there anything related to the word "components" (from query2) that's causing this error?
i don't understand why it doesn't work for query2
and it's not working for query4 also..
can you help me in this , facing the same even with above versions

here is the error that i am getting

APIError

APIError: Invalid response object from API: '{"error":{"message":"The response was filtered due to the prompt triggering Azure OpenAI’s content management policy. Please modify your prompt and retry. To learn more about our content filtering policies please read our documentation: https://go.microsoft.com/fwlink/?linkid=2198766","type":null,"param":"prompt","code":"content_filter","status":400}}' (HTTP response code was 400)
Capture5

@mrcmoresi
Copy link

@arindamhazramsft i did as well

from llama_index import ServiceContext service_context = ServiceContext.from_defaults( llm_predictor=llm_predictor, prompt_helper=prompt_helper, embed_model=embedding_llm )

index = GPTSimpleVectorIndex.from_documents(documents, service_context=service_context)

Got past that error but I ended up with

openai.error.InvalidRequestError: Must provide an 'engine' or 'deployment_id' parameter to create a <class 'openai.api_resources.completion.Completion'>

@carchi8py could you share how you define the service_context and embedding_llm. I'm trying to replicate it but I'm getting the same error you had there about defining the engine or deployment_id

@That1Panda
Copy link

@arindamhazramsft i did as well
from llama_index import ServiceContext service_context = ServiceContext.from_defaults( llm_predictor=llm_predictor, prompt_helper=prompt_helper, embed_model=embedding_llm )
index = GPTSimpleVectorIndex.from_documents(documents, service_context=service_context)
Got past that error but I ended up with
openai.error.InvalidRequestError: Must provide an 'engine' or 'deployment_id' parameter to create a <class 'openai.api_resources.completion.Completion'>

@carchi8py could you share how you define the service_context and embedding_llm. I'm trying to replicate it but I'm getting the same error you had there about defining the engine or deployment_id

# set maximum input size
max_input_size = 4096
# set number of output tokens
num_outputs = 256
# set maximum chunk overlap
max_chunk_overlap = 20
# set chunk size limit
chunk_size_limit = 600
llm = AzureChatOpenAI(deployment_name="gpt-35-turbo", temperature=0,openai_api_version=openai_api_version)
llm_predictor = ChatGPTLLMPredictor(llm=llm, retry_on_throttling=False)
embeddings = LangchainEmbedding(OpenAIEmbeddings(model="text-embedding-ada-002", chunk_size=1, openai_api_version=openai_api_version))
prompt_helper = PromptHelper(max_input_size=max_input_size, num_output=num_outputs, max_chunk_overlap=max_chunk_overlap, chunk_size_limit=chunk_size_limit)
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, embed_model=embeddings, prompt_helper=prompt_helper)

@carchi8py
Copy link

I did the following.

The generate function called a few different llama hub loader I was using and created static files.

` llm = ChatOpenAI(deployment_id="gpt-4-32k-0314")
llm_predictor = LLMPredictor(llm=llm)
embedding_llm = LangchainEmbedding(OpenAIEmbeddings())

options = parse_args()
if options.generate:
    generate()

#load PDF from Confelunce
documents = SimpleDirectoryReader(DATA_DIR).load_data()

# Define prompt helper
max_input_size = 3000
num_output = 256
chunk_size_limit = 1000
max_chunk_overlap = 20
prompt_helper = PromptHelper(max_input_size=max_input_size, num_output=num_output, max_chunk_overlap=max_chunk_overlap, chunk_size_limit=chunk_size_limit)

service_context = ServiceContext.from_defaults(
   llm_predictor=llm_predictor, prompt_helper=prompt_helper, embed_model=embedding_llm
   )
# Create index
index = GPTSimpleVectorIndex.from_documents(documents, service_context=service_context)
index.save_to_disk("index.json")`

@dell1503
Copy link

dell1503 commented May 29, 2023

https://gist.github.com/csiebler/e287b791333011183792c08bad1dc140?permalink_comment_id=4558026#gistcomment-4558026

@csiebler
Did not work for me.
With the following Packages:

openai==0.27.6
llama-index==0.6.0
langchain==0.0.157
python-dotenv

I still got the API Error:
openai.error.InvalidRequestError: The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.

I have in Azure a Deplyoment called: gpt-35-turbo
Bildschirmfoto 2023-05-29 um 21 18 53

I run this part of Code, was working:
https://gist.github.com/csiebler/e287b791333011183792c08bad1dc140?permalink_comment_id=4546610#gistcomment-4546610
image

Any Ideas?

@dell1503
Copy link

https://gist.github.com/csiebler/e287b791333011183792c08bad1dc140?permalink_comment_id=4558026#gistcomment-4558026

@csiebler Did not work for me. With the following Packages:

openai==0.27.6
llama-index==0.6.0
langchain==0.0.157
python-dotenv

I still got the API Error: openai.error.InvalidRequestError: The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.

I have in Azure a Deplyoment called: gpt-35-turbo Bildschirmfoto 2023-05-29 um 21 18 53

I run this part of Code, was working: https://gist.github.com/csiebler/e287b791333011183792c08bad1dc140?permalink_comment_id=4546610#gistcomment-4546610 image

Any Ideas?

.....
I had deploy as well the training Model....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment