File size: 1,098 Bytes
6e50eae
85878a9
 
 
 
 
6e50eae
 
85878a9
 
6e50eae
 
 
 
85878a9
6e50eae
 
 
 
 
85878a9
6e50eae
 
 
 
 
85878a9
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import nest_asyncio
import json
from scrapegraphai.graphs import SearchGraph
import streamlit as st  # This import is necessary to access secrets in Streamlit

# Apply necessary settings for asyncio compatibility in Jupyter/Streamlit environments
nest_asyncio.apply()

# Access your API keys securely
OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]

# Define the configuration for the graph
graph_config = {
    "llm": {
        "api_key": OPENAI_API_KEY,  # Use the secure variable to pass the actual API key
        "model": "gpt-3.5-turbo",
        "temperature": 0,
    },
}

# Create the SearchGraph instance with a prompt
search_graph = SearchGraph(
    prompt="List me all the attributes of 'cannabis strain'.",
    config=graph_config
)

try:
    # Run the graph to fetch results
    result = search_graph.run()
    # Convert the result to a JSON string with indentation for better readability
    output = json.dumps(result, indent=2)
    # Print each line of the JSON output
    for line in output.split("\n"):
        print(line)
except Exception as e:
    print(f"An error occurred: {e}")