-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
enable end users to pass model instances for llm and embeddings model #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
""" | ||
Basic example of scraping pipeline using SmartScraper using Azure OpenAI Key | ||
""" | ||
|
||
import os | ||
from dotenv import load_dotenv | ||
from langchain_openai import AzureChatOpenAI | ||
from langchain_openai import AzureOpenAIEmbeddings | ||
from scrapegraphai.graphs import SmartScraperGraph | ||
from scrapegraphai.utils import prettify_exec_info | ||
|
||
|
||
## required environment variable in .env | ||
# AZURE_OPENAI_ENDPOINT | ||
# AZURE_OPENAI_CHAT_DEPLOYMENT_NAME | ||
# MODEL_NAME | ||
# AZURE_OPENAI_API_KEY | ||
# OPENAI_API_TYPE | ||
# AZURE_OPENAI_API_VERSION | ||
# AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME | ||
load_dotenv() | ||
|
||
|
||
# ************************************************ | ||
# Initialize the model instances | ||
# ************************************************ | ||
|
||
llm_model_instance = AzureChatOpenAI( | ||
openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"], | ||
azure_deployment=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT_NAME"] | ||
) | ||
|
||
embedder_model_instance = AzureOpenAIEmbeddings( | ||
azure_deployment=os.environ["AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME"], | ||
openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"], | ||
) | ||
|
||
# ************************************************ | ||
# Create the SmartScraperGraph instance and run it | ||
# ************************************************ | ||
|
||
graph_config = { | ||
"llm": {"model_instance": llm_model_instance}, | ||
"embeddings": {"model_instance": embedder_model_instance} | ||
} | ||
|
||
smart_scraper_graph = SmartScraperGraph( | ||
prompt="List me all the events, with the following fields: company_name, event_name, event_start_date, event_start_time, event_end_date, event_end_time, location, event_mode, event_category, third_party_redirect, no_of_days, | ||
time_in_hours, hosted_or_attending, refreshments_type, registration_available, registration_link", | ||
# also accepts a string with the already downloaded HTML code | ||
source="https://www.hmhco.com/event", | ||
config=graph_config | ||
) | ||
|
||
result = smart_scraper_graph.run() | ||
print(result) | ||
|
||
# ************************************************ | ||
# Get graph execution info | ||
# ************************************************ | ||
|
||
graph_exec_info = smart_scraper_graph.get_execution_info() | ||
print(prettify_exec_info(graph_exec_info)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,8 @@ def execute(self, state): | |
if isinstance(embedding_model, OpenAI): | ||
embeddings = OpenAIEmbeddings( | ||
api_key=embedding_model.openai_api_key) | ||
elif isinstance(embedding_model, AzureOpenAIEmbeddings): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DId you have the chanche to test with azure embedding model? Did you use text-ada? does it work properliy? :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I used text-ada, have attached example as well. |
||
embeddings = embedding_model | ||
elif isinstance(embedding_model, AzureOpenAI): | ||
embeddings = AzureOpenAIEmbeddings() | ||
elif isinstance(embedding_model, Ollama): | ||
|
@@ -133,3 +135,4 @@ def execute(self, state): | |
|
||
state.update({self.output[0]: compressed_docs}) | ||
return state | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be cool to have all the avaible model on AzureAI, here the link Azure AI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure.