-
-
Save csiebler/e287b791333011183792c08bad1dc140 to your computer and use it in GitHub Desktop.
| 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) |
@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

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

Any Ideas?
@csiebler Did not work for me. With the following Packages:
openai==0.27.6 llama-index==0.6.0 langchain==0.0.157 python-dotenvI 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
I run this part of Code, was working: https://gist.github.com/csiebler/e287b791333011183792c08bad1dc140?permalink_comment_id=4546610#gistcomment-4546610
Any Ideas?
.....
I had deploy as well the training Model....
👀 prompt wizards, come share the best prompts with God Tier Prompts ✨
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())